views:

36

answers:

1

I'm probably going to use the URL rewrite module for IIS 7 eventually and I have a fairly straight forward question that I really can't find the answer to.

If you have a base case of:

http://yoururl.com/page.aspx?ID=7

You can obviously have it rewritten to:

http://yoururl.com/page/7 or whatever you want.

My question is this: When using this module can you still use Request.Querystring["page"] on the rewritten querystring. How does the Request.URL stuff work. Does asp.net still provide the un-rewritten url or does it provide the rewritten one.

I would assume that your C#/asp.net code is completely unaffected by the url rewriting, as that's more or less the point, but I want to be crystal clear.

Secondary question: What is the best practice for how you should code a website when using the rewritten. Should you code links in the written style, or continue using querystrings?

A: 
  • When using this module can you still use Request.Querystring["page"] on the rewritten querystring.

Yes, you will be able to access the re-written QueryString in that way.

  • How does the Request.URL stuff work. Does asp.net still provide the un-rewritten url or does it provide the rewritten one.

Request.Url will be the re-written URL, but Request.RawUrl will be the original URL.

  • Should you code links in the written style, or continue using querystrings?

Yes, code your links in the way you want them to be seen by end users, and then in your code ensure you're aware of and document the changed format.

There is loads of information and tutorials on the IIS website here:

http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

TimS
Thanks for the info. I didn't know about Request.RawUrl. Just some things to think about and be aware of before I embark on a project.
Molly