【问题标题】:Clear hash and parameters from Redirect in aspnet mvc?从aspnet mvc中的重定向清除哈希和参数?
【发布时间】:2011-09-26 10:45:51
【问题描述】:

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

    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 中删除哈希?
我怎样才能在服务器端摆脱它?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-20
      • 2021-11-24
      • 1970-01-01
      • 2020-06-29
      • 1970-01-01
      • 1970-01-01
      • 2014-09-16
      • 2018-12-13
      相关资源
      最近更新 更多