带片段标识符的Mvc5重定向

问题描述

我在家庭控制器中有一个控制器动作:

    public ActionResult OAuthCallback(
        [required] string code,[required] string state)
    {
        this.Response.Cookies.Add(new HttpCookie(oAuthCodeCookieName,code));
        this.Response.Cookies.Add(new HttpCookie(oAuthStateCookieName,state));

        var base64decodedState = Encoding.UTF8.GetString(Convert.FromBase64String(state));
        var stateObj = JsonConvert.DeserializeObject<Dictionary<string,string>>(base64decodedState);

        return new RedirectResult(this.Url.Action(nameof(this.Index) + stateObj["RedirectHash"]));
   }

保存在状态中的RedirectHash为#OAuthCallback,因为我想使用#OAuthCallback片段标识符转发到Index操作。 (http://localhost:1842/#OAuthCallback

我已经从旧的StackOverflow答案改编了该代码,该答案似乎在较早的Mvc版本中起作用: Redirect to a hash from the controller using "RedirectToAction"

但是,在Mvc 5.2.7中,此代码转发到localhost:1842/Home/Index%23OAuthCallback,哈希字符被转义。

如何在Mvc 5中使用片段标识符重定向

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)