我的应用程序需要获取所有重定向的先前视图。我目前有一个父控制器,它将检查并抓取当前视图。这很好用。我怎么得到以前的?
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一样带回上一页,因为我只需要/帮助/索引
答案 0 :(得分:1)
String previousUrl = Request.UrlReferrer.AbsolutePath;