从aspnet mvc中的Redirect清除哈希和参数?

时间:2011-09-26 10:45:51

标签: c# asp.net asp.net-mvc redirect

在控制器中考虑以下代码:

    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

为什么哈希不会从网址中删除?
如何摆脱服务器端?

1 个答案:

答案 0 :(得分:2)

这是不可能的。命名锚(#/?tab=Foo)不是请求的一部分,浏览器不会将命名锚发送到服务器。看看named anchors are not sent to the web server