Labels

Tuesday, May 8, 2007

Remapping URLs

Context: This is about how to serve a different page than the page a user requests.

 

Need: Below are the situation when it is really required.

·         You have an site containing lot of pages, and you have a page which is heavily used in the redirection statement in all the other pages. Due to some reason you came up with a new page instead of the earlier. Then in this situation all is required is to go and make changes to all the code statements containing code to redirect to this often used page.

In such situation if you can do it declaratively in just few minutes, then nothing can be great than this quick trick.

 

 

How:

                The simplest way to remap a URL is to specify the remapping in your application's web configuration file.

 

                <?xml version="1.0"?>

<configuration>

<system.web>

  <urlMappings>

    <add  url="~/Home.aspx"  mappedUrl="~/Default.aspx"/>

  </urlMappings>

</system.web>

</configuration>

 

Note:

·         It doesn't matter whether the Home.aspx page actually exists.

·         Though the request is remapped, the URL doesn’t get change. i.e User will not get any feel of remapping.

 

When working with remapped URLs, if there is any need to determine the original URL that a user requested, then use below.

 

·         Request.RawUrl : Returns the original URL (before being remapped).

 

 

Gotcha:

·         The mappedUrl attribute can contain query strings. However, it cannot contain wildcards.

·         For this need is to implement a custom urlMapper in the form of HTTPModule. [Will be covered in next post]

 

 

Thanks & Regards,

Arun Manglick

SMTS || Microsoft Technology Practice || Bridgestone - Tyre Link || Persistent Systems || 3023-6258

 

DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.

No comments:

Post a Comment