I have a ASP.NET MVC 3 application in which I have to map a request with .aspx extension to another route. what i am trying to do is to get the current request url in application start. but the problem is it runs fine with all urls without .aspx extension but in a url for ex (http://example.com/Products/5/16/Eettafels.aspx) it shows only http://example.com/
however with http://example.com/Products/5/16/Eettafels it shows the correct path ..
All the code is a simple line:
string currentUrl = HttpContext.Current.Request.Url.ToString().ToLower();
Can any one have any idea what i am doing wrong
If you add a plain ASPX page to an ASP.NET MVC project, well, it just works like a charm without any changes to the configuration. If you invoke the ASPX page, the ASPX page is processed with viewstate and postbacks.
MVC works with Extensionless URLs only (by default)<system.
Inject NavigationManager in razor. Use Uri from NavigationManager to get the current URL.
To get the current URL I am using the following C# instruction: Uri address = new Uri(Request. Host.
though it is a very old post.
I am just pasting the code Ha Doan linked to so that it will be easier to anyone landing on this question.
string url = HttpContext.Current.Request.Url.AbsoluteUri;
// http://localhost:1302/TESTERS/Default6.aspx
string path = HttpContext.Current.Request.Url.AbsolutePath;
// /TESTERS/Default6.aspx
string host = HttpContext.Current.Request.Url.Host;
// localhost
Check this SO for discussion on this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With