Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何在MVC中获取上一条路线_Asp.net Mvc_Routes - Fatal编程技术网

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;