Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hi Friends,

I am working on a Project build on ASP.NET 4.0, so currently if we access our web page "Customer.aspx" it shows like this in the address bar:
http://xxxx.com/Customer.aspx

But we need the requirement not to show the extension of the page to user, and we implemented the URL Routing and page started to look into the address bar:

http://xxxx.com/Customer

But, still if I hit the page like 'http://xxxx.com/Customer.aspx' it is working.
Please guide me where and what I am missing to redirect a user on 'http://xxxx.com/Customer' even if he hit on 'http://xxxx.com/Customer.aspx'

I have used the below code in Global.asax file
C#
 public void Application_Start()
 {
    RegisterRoutes(RouteTable.Routes)
 }

private void RegisterRoutes(RouteCollection routes)
{
    routes.Ignore("{*allaspx}", new { allaspx=@"*\.aspx" });
    routes.MapPageRoute("CustomerRoute", "Customer", "~/Customer.aspx");
    routes.EnableFriendlyUrls();
}


Thanks :)

What I have tried:

I used the System.Web.Routing to make the url routing.
Posted
Comments
F-ES Sitecore 31-May-16 10:14am    
See if you can use Application_BeginRequest, and if the path has an aspx on it do a redirect.

http://www.dotnetperls.com/global-asax
Manish Kumar Namdev 1-Jun-16 1:51am    
Thanks for reply, but will this solve the problem "not to show .aspx" in address bar, even if the User hit the "pagename.aspx" it should act like MVC controller name.

However Now I am thinking to let it be only one url and will do the "Server.Transfer", but facing the challenge is my web site has menu and they are dynamically bind so how can I make Server.Transfer from an Anchor because ultimately it will be an html inside the browser.
Shahin Khorshidnia 1-Jun-16 7:33am    
Why do you want to redirect the user who hits "xxx\Customer.aspx" to "xxx\Customer"? The user has to redirect to Error page as long as you are intent to hide "aspx" extension. At any rate, this could be a naive opinion but maybe you can expire the user's session if they hit the wrong address.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900