在ASP.NET MVC控制器,我怎么能得到重定向(字符串URL)方法不追加'#'? [英] In an ASP.NET MVC Controller, how can I get the Redirect(string URL) method to not append a '#'?

查看:172
本文介绍了在ASP.NET MVC控制器,我怎么能得到重定向(字符串URL)方法不追加'#'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC项目5返回重定向(网址),其中URL是一个字符串的结果的控制器。

I have a controller in an ASP.NET MVC 5 project that return the result of Redirect(url) where url is a string.

基本上我有这样的:

string url = "calendar/addevent";
return Redirect(url);

在浏览器中的结果加载这样的网址: http://example.com/calendar/addevent #

The result in the browser is loading a URL like this: http://example.com/calendar/addevent#

这是在IE罚款,但Chrome的滚动到页面的底部,因为看的'#'为锚。

This is fine in IE, but Chrome scrolls to the bottom of the page looking for an anchor because of the '#'.

如何不包括'#'在URL的末尾?

Any idea on how to not include the '#' on the end of the URL?

更新15年10月21日

Update 10/21/15

这是此方法在帐户控制模板MVC 5项目中使用单用户身份验证返回:

This is being returned from this method in the Account controller found in the template MVC 5 project using single-user authentication:

private ActionResult RedirectToLocal(string returnUrl)
    {
        if (Url.IsLocalUrl(returnUrl))
        {
            return Redirect(returnUrl);
        }
        return RedirectToAction("Index", "Home");
    }

该Url.IsLocalUrl是真实的,如果我调试和读取对象从重定向(RETURNURL)回来了,URL没有'#'。该浏览器仍然以某种方式得到它虽然...

The Url.IsLocalUrl is true and, if I debug and read the object returned from Redirect(returnUrl), the URL does not have the '#'. The browser is still somehow getting it though...

推荐答案

我发现,这是因为谷歌的OAuth的反应发生。在响应他们的查询字符串以#结束。因此,在账户控制器Redirect方法返回一个302响应它,理所当然地,持续的哈希值。很好的比喻 - > <一个href=\"http://stackoverflow.com/a/5283528/2354959\">http://stackoverflow.com/a/5283528/2354959.

I've found this is happening because of Google's OAuth response. Their query string on the response ends with '#'. Hence, the Redirect method in the Account controller returns a 302 response which, rightfully, persists the hash. Good analogy -> http://stackoverflow.com/a/5283528/2354959.

因此​​,ASP.NET MVC控制器正常工作...

So the ASP.NET MVC controller is working correctly...

这篇关于在ASP.NET MVC控制器,我怎么能得到重定向(字符串URL)方法不追加'#'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆