Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an ASPX page be given an alias so that it can be accessed from two different URLs?

I need to access the same page via two different names for the page.

Example:

CustomersDetail.aspx needs to be accessable using the aliased name PartnersDetail.aspx

CustomersDetail.aspx is the real file.

Both of the following urls should map to the same page:

http://www.example.com/CustomersDetail.aspx    
http://www.example.com/PartnersDetail.aspx

Is this possible using the Web.Config? If this is possible can the page know which url it was accessed from by looking that the request uri?

like image 664
Tim Santeford Avatar asked Jul 11 '11 17:07

Tim Santeford


2 Answers

4GuysFromRolla does an excellent job of explaining ASP.NET 2.0's method of url mapping within the web.config which allows for very readable and easily maintainable url mapping.

Essentially you will want to put the following in your web.config inside of the system.web section:

<urlMappings enabled="true">
  <add url="~/PartnersDetail.aspx" mappedUrl="~/CustomersDetail.aspx" />
</urlMappings>
like image 79
Stephen Mesa Avatar answered Nov 01 '22 12:11

Stephen Mesa


Depeding on the version of the .Net Framework (introduced in 3.5) you are using you could add an entry to the RouteTable.Routes collection in the Global.asax on application start:

    protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }

    void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("DetailReRoute",
            "PartnersDetail.aspx", //Virtual Page
            "~/CustomersDetail.aspx", //Physical Page
            false, null, null);
    }
like image 3
Bradley Ullery Avatar answered Nov 01 '22 12:11

Bradley Ullery