标签:
URL的获取很简单,ASP.NET通用:
string url=Request.Url.ToString();
string url=Request.RawUrl; //(或) string url=Request.Url.PathAndQuery;
string url=HttpContext.Current.Request.Url.AbsolutePath; //(或 ) string url= HttpContext.Current.Request.Path;
string url=HttpContext.Current.Request.Url.Host;
string url= HttpContext.Current.Request.Url.Query;
Request.Url.Port
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
标签:
原文地址:http://www.cnblogs.com/Jerrycjc/p/5151414.html