Linq to Sql- AutoID not working
July 31, 2009
Using Linq to Sql Auto IDs do not work by default.
Lets say you have a table “Property” with a primary key of “PropertyId”. In the table definition it is set as a unqueidentifier and by default it is assigned a NewID().
Now go to your Linq to Sql and create your dbml, drag your Property table into it.
In order to have the PropertyId generated using the Default Value go to the properties of the PropertyId field and set Auto Generate Value to True and Auto-Sync to OnInsert.

I am sure many already know this, but I hope it can help save some time for others.
asp.net dynamic meta and title tags
July 1, 2009
Using a Master page.
Problem for SEO is it really scews up the formatting and positioning of the tags.
First get the data there.
If you’re not overly concerned about formatting of the title tag, in the content page:
Page.Title = “The title of your page”;
// Add the keywords meta tag
HtmlMeta metaKeywords = new HtmlMeta();
metaKeywords.Name = "keywords";
metaKeywords.Content = nseCase.MetaKeywords;
Page.Header.Controls.AddAt(1, metaKeywords);
Page.Header.Controls.AddAt(1, new LiteralControl("\n"));
// Add the description meta tag
HtmlMeta metaDescription = new HtmlMeta();
metaDescription.Name = "description";
metaDescription.Content = nseCase.Description;
Page.Header.Controls.AddAt(1,metaDescription);
Page.Header.Controls.AddAt(1, new LiteralControl("\n"));
What is happening is the meta tags are being added to the first line in the head tag (below the title tag). Think of it like a stack, that is why it is being done in reverse order in which you would think.
If you want to do a little more work to remove the spacing and line breaks from the title tag you need to take this approach.
In the Master page remove the runat=”server” from the head tag. Now you can create literal tags for each desired tag in the <head> tag.
<head>
<asp:Literal ID=”litTitle” runat=”server” />
<asp:Literal ID=”litMetaDescription” runat=”server” />
<asp:Literal ID=”litMetaKeywords” runat=”server” />
</head>
Now in your content page you can access these literal controls by:
Literal title = (Literal)Master.FindControl("litTitle");
title.Text = String.Format("<title>{0}</title>", “Your dynamic title”);
Literal metaDescription = (Literal)Master.FindControl(“litMetaDescription”);
metaDescription.Text = String.format(“<meta name=\”{0}\” content=\”{1}\” />”, “description”, “here is your page description”);
Literal metaKeywords = (Literal)Master.FindControl(“litMetaKeywords”);
metaKeywords.Text = String.format(“<meta name=\”{0}\” content=\”{1}\” />”, “keywords”, “here, are, your, pages, keywords”);
The first approach is quicker to do and still allows you to put a default title in it. You may not want to set the title and meta tags for each page.
The second approach requires that you set the title and meta tags on every page if you want them. I suppose you could use a contentplaceholder for many of the pages which is quicker than doing it in the code-behind for pages that you don’t need the tags to be dynamic.
My SEO guy is finally happy that I came up with a solution for this. I hope this helps you get an SEO guy off your back.
-
Categories
- asp.net (11)
- Blog (1)
- Business (5)
- Conferences (1)
- Errors (3)
- Portfolio (2)
- Reviews (2)
- SQL Server (3)
- Tips (1)
- Uncategorized (1)
- Web Development (13)
-
Archives