Asp.net mvc Google Chrome客户端的ASP.NET MVC路由问题
我的Silverlight 4应用程序托管在ASP.NET MVC 2 web应用程序中。当我使用InternetExplorer8浏览时,它工作正常。但是Google Chrome(版本5)找不到ASP.NET控制器。具体来说,以下ASP.NET控制器可与Chrome和IE一起使用Asp.net mvc Google Chrome客户端的ASP.NET MVC路由问题,asp.net-mvc,google-chrome,custom-model-binder,Asp.net Mvc,Google Chrome,Custom Model Binder,我的Silverlight 4应用程序托管在ASP.NET MVC 2 web应用程序中。当我使用InternetExplorer8浏览时,它工作正常。但是Google Chrome(版本5)找不到ASP.NET控制器。具体来说,以下ASP.NET控制器可与Chrome和IE一起使用 //[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")] public ContentResult TestMe() { Conte
//[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
public ContentResult TestMe()
{
ContentResult result = new ContentResult();
XElement response = new XElement("SvrResponse",
new XElement("Data", "my data"));
result.Content = response.ToString();
return result;
}
如果我取消[OutputCache]属性的注释,那么它可以与IE一起使用,但不能与Chrome一起使用。此外,我使用自定义模型绑定控制器,因此如果我编写以下内容:
public ContentResult TestMe(UserContext userContext)
{
...
}
它也适用于IE,但同样不适用于Chrome,Chrome会给我错误消息,说找不到资源。当然,我将IIS 6配置为通过aspnet_isapi.dll处理所有请求,并在web应用程序的Global.asax inside Application_Start()方法中注册了自定义模型绑定器。
有人能解释一下原因吗?谢谢。这并不能直接回答您的问题,但我建议您尝试一下,看看浏览器发送的实际请求。比较差异,找出问题所在(您可以使用Fiddler中的“Request Builder”选项卡来调整参数)。好的,我找到了解决此问题的方法。在我的silverlight应用程序中,我选择使用客户端堆栈,而不是使用默认http堆栈
WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);
另请参见:我发现有两种WebRequest方法:Create和CreateHttp在使用HTTPS时表现不同。始终使用Create方法根据协议实例化正确的请求。 我也有过类似的情况,这就是我所得到的。对于以下代码,我们在尝试使用WebRequest获取某些内容时未发现异常:
HttpWebRequest request = WebRequest.CreateHttp(uri);
但下面这段话很管用:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
谢谢你,科德卡。小提琴手的石头。我发现了问题;Google Chrome将“Content Type:application/x-www-form-urlencoded”放在请求头中(对url进行编码),但IE没有这样做。所以,下一个问题是如何在Chrome中禁用url编码。