Asp.net mvc 如何在MVC中获取上一条路线
我的应用程序需要获得所有重定向的上一个视图。我目前有一个父控制器,它将检查并获取当前视图。这个很好用。我怎样才能得到上一个Asp.net mvc 如何在MVC中获取上一条路线,asp.net-mvc,routes,Asp.net Mvc,Routes,我的应用程序需要获得所有重定向的上一个视图。我目前有一个父控制器,它将检查并获取当前视图。这个很好用。我怎样才能得到上一个 protected override void OnActionExecuting(ActionExecutingContext filterContext) { String currentView = Request.RawUrl //Do stuff with currentView string //String previousView
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
String currentView = Request.RawUrl
//Do stuff with currentView string
//String previousView = ......?
//Do stuff with previousView string
var query = db.PageRoutes.Where(a => a.RouteKey == currentView).FirstOrDefault();
if (query != null)
{
ViewBag.htmlRawData = query.Results;
}
base.OnActionExecuting(filterContext);
}
最后,通过使用:
String previousUrl = Request.UrlReferrer.AbsoluteUri;
将返回上一页,如//localhost:53188/Help/Index,其中我只需要/Help/Index请记住,
请求.UrlReferrer
在第一次访问时将为null,并且在重定向后也将为null。只有第一次UrlReferrer值为null,之后,每个重定向都会返回quetion(/Help/Index)中提到的绝对路径
String previousUrl = Request.UrlReferrer.AbsolutePath;