Search code examples
c#routesglobalasp.net-routing

Routing Issue want to display domain name even index.aspx is called


routes.MapPageRoute("Main", "", "~/index.aspx");

thats the route I mapped on index page.. when I call the url with index.aspx it displays like

www.abc.com/index.aspx

but I want it to show

www.abc.com 

even when index.aspx is called


Solution

  • Regarding my comment, URL Rewrite is also available in IIS and Asp.net. So you can potentially use it.

    Another solution would be to redirect to your route. The route alone doesn't change the URL, it just allows you to access the resource via the defined route.

    You can redirect to the route though, which will rewrite the URL on the client For example like this:

            if (Request.Path != "/")
            {
                Context.Response.RedirectToRoute("Main");
            }
    

    This is very simplified and might not work in all scenarios, so please be very careful.