How to do URL-rewrite with ASP.NET?

To have the .aspx-prefix at the end and a lot of querystring parameters at the end of the URLs feels rather ungraceful. And it's not any good from a SEO-point of view. IIS 6 and ASP.NET has not got any good built in solution to do URL rewrite. But there are some solutions and I will collect a few links here that I read on the subject.

In Ruby on Rails URL-rewrite seems simple and is a natural part of the language. On Apache servers there are the mod_rewrite module which is great for all the PHP-developers.

With ASP.NET it's possible to use HttpContext.RewritePatt, but it's not as simple as it first appears. I found a lot of articles about soultiuons but many of them described problems with cacheing, themes and problems with Postback.

On Urlrewriting.net there's an open source component that claimes to have solved a lot of these problems. I have not tried this myself though.

I have also read about the coming IIS 7.0 and that there will be a better support for URL rewrite. Lets hope so!

Some mixed references
http://weblogs.asp.net/fmarguerie/archive/2004/11/18/265719.aspx
http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309pj_l/asp200309pj_l.asp. http://www.developersdex.com/gurus/articles/793.asp?Page=3 http://www.webforum.nu/showthread.php?t=145530. http://www.raftweb.info/SEO/1032.aspx

 

By Jesper Lind

Adding appSettings items programmatically

This shows how to add appSettings items from your codebehind.


Configuration config = ConfigurationSettings.OpenWebConfiguration("~");

AppSettingsSection appSettingsSection = config.AppSettings;

appSettingsSection.Settings["MyKey"] = "The value to save!";

config.Save();

By Jesper Lind

Transactions with Asp.Net

Read about how to create a database transaction with Asp.Net.

SqlTransaction trans = null;
try
{
conn = new SqlConnection ( . . . );
conn.Open();
trans = conn.BeginTransaction();
cmd = new Command();
cmd.Connenction = conn;
cmd.Transaction = trans;
cmd.ExecuteNonQuery();

}
catch(Exception objException)
{
if(trans!=null)
trans.Rollback();
}
finally
{
if(conn!=null)
conn.Close();
}

By Jesper Lind