在ASP.NET MVC 中获取当前URL、controller、action
2013-11-13 16:37
579 查看
URL的获取很简单,ASP.NET通用:
【1】获取 完整url (协议名+域名+虚拟目录名+文件名+参数)
string url=Request.Url.ToString();【2】获取 虚拟目录名+页面名+参数:
string url=Request.RawUrl;(或 string url=Request.Url.PathAndQuery;)
【3】获取 虚拟目录名+页面名:
string url=HttpContext.Current.Request.Url.AbsolutePath;(或 string url= HttpContext.Current.Request.Path;)
【4】获取 域名:
string url=HttpContext.Current.Request.Url.Host;【5】获取 参数:
string url= HttpContext.Current.Request.Url.Query;【6】获取 端口:
Request.Url.Port二、当前controller、action的获取
RouteData.Route.GetRouteData(this.HttpContext).Values["controller"]RouteData.Route.GetRouteData(this.HttpContext).Values["action"]
或
RouteData.Values["controller"]
RouteData.Values["action"]
如果在视图中可以用
ViewContext.RouteData.Route.GetRouteData(this.Context).Values["controller"]
ViewContext.RouteData.Route.GetRouteData(this.Context).Values["action"]
或
ViewContext.RouteData.Values["controller"]
ViewContext.RouteData.Values["action"]
相关文章推荐
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action(转载)
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- ASP.NET实现MVC中获取当前URL、controller及action的方法
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- Asp.Net_Mvc_获取当前Url、Controller、Action
- 在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- 如何在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action(转)
- 如何在ASP.NET MVC 中获取当前URL、controller、action
- 在ASP.NET MVC 中获取当前URL、controller、action
- asp.net MVC中获取当前URL/Controller/Action
- 在ASP.NET MVC 中获取当前URL、controller、action 、参数