我有一个 ASP.NET MVC 3 应用程序,我必须在其中将扩展名为 .aspx 的请求映射到另一个路由。我想做的是在应用程序启动时获取当前请求 url。但问题是它在所有没有 .aspx 扩展名但在 ex 的 url 中运行良好 ( http://example.com/Products/5/16/Eettafels.aspx ) 它只显示 http://example.com/
然而 http://example.com/Products/5/16/Eettafels它显示了正确的路径..
所有的代码都是简单的一行:
string currentUrl = HttpContext.Current.Request.Url.ToString().ToLower();
谁能知道我做错了什么
最佳答案
虽然这是一个非常古老的帖子。
我只是粘贴了 Ha Doan 链接到的代码,这样任何人都可以更轻松地解决这个问题。
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
检查此 SO 以讨论此问题
关于c# - 在具有 .aspx 扩展名的 mvc 应用程序中获取 Current.Request.Url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17101891/