开发者

Clear hash and parameters from Redirect in aspnet mvc?

开发者 https://www.devze.com 2023-04-08 06:47 出处:网络
Consider the following code with开发者_JS百科in a controller: protected override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)

Consider the following code with开发者_JS百科in a 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);
    }

If I enter the follwing url when not authorized:

somecontroller/someaction#/?tab=Foo

I get redirected to:

/Home/Index#/?tab=Foo

How come the hash isn't stripped from the url?

How can I get rid of it serverside?


This is not possible. The named anchor (#/?tab=Foo) is not part of the request, the browser does not send the named anchor to the server. Take a look at named anchors are not sent to the web server

0

精彩评论

暂无评论...
验证码 换一张
取 消