ASP. NET Implementation of URL Mapping

  • 2021-07-16 02:10:32
  • OfStack

URL mapping is a new feature provided in ASP. NET 2.0. The URL mapping technique helps us map one particular URL to another URL. To help understand, let's assume that you have a page on your site called Homepage. aspx to access your home page, and all users also use this page to access your home page. But for some reason, you want to change the homepage to OriginalHome. aspx. Using URL mapping at this time allows you to map to new pages without notifying users.

If we set the URL mapping, any user who enters Homepage. aspx in the URL field calls OriginalHome. aspx.

In-depth concept:

Let's see how to achieve it.

This can be achieved in the configuration section.

Syntax:


 < urlMappings enabled="[true|false]" >   
 < add url="String"   
mappedUrl="String"/ >   
 < /urlMappings > 

If you want to use URL mapping, you must set the enabled property to true. Each add element contains an original URL and a mapping URL. Yes, this site, www. ofstack. com, has a simple concept! If we configured the URL mapping for the above scenario, the elements in the config file appear as follows:


 < urlMappings enabled="true" >   
 < add url="~/ Homepage.aspx" mappedUrl="~/ OriginalHome.aspx"/ >   
 < /urlMappings > 

1 Once we have modified or added the above elements to the project's web. config file, any user attempting to access Homepage. aspx will call the OriginalHome. aspx page due to the URL mapping. Interestingly, only Homepage. aspx is still displayed in the URL column. So despite thinking of calling/executing OriginalHome. aspx internally, the user still sees Hopepage. aspx in the URL column.

1 Some advantages:

1. If your customer marks a link to a page, but you have to delete the page and replace it with another page, you can solve this business problem by using URL mapping without letting the customer know about the page change.

2. If you have a large and complex URL but don't want to give it to the user, you can tell the simple URL and map the simple URL to the original URL yourself.

3. This method makes it easy to handle menu controls. The best example is the asp. net site.

4. Security is also involved here (users can't see the real page name in URL column, which is also a kind of encryption! ).

I hope you like this new feature.


Related articles: