考虑 Controller 中的以下代码:
protected override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
{
if (!this.IsAuthorized)
{
filterContext.Result = RedirectToAction("Index", "Home", new { area = "" });
//filterContext.Result = Redirect(Url.Content("~/Home/Index")); // Gives same result as the previous row
return;
}
base.OnActionExecuting(filterContext);
}
如果我在未授权的情况下输入以下网址:
somecontroller/someaction#/?tab=Foo
我被重定向到:
/Home/Index#/?tab=Foo
为什么哈希没有从 url 中剥离?
我怎样才能在服务器端摆脱它?
最佳答案
这是不可能的。命名 anchor (#/?tab=Foo
) 不是请求的一部分,浏览器不会将命名 anchor 发送到服务器。看看named anchors are not sent to the web server
关于c# - 在 asp net mvc 中清除重定向的哈希和参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7553919/