ASP.NET MVC routing issue with Google Chrome client

怎甘沉沦 提交于 2019-12-30 11:34:33

问题


My Silverlight 4 app is hosted in ASP.NET MVC 2 web application. It works fine when I browse with Internet Explorer 8. However Google Chrome (version 5) cannot find ASP.NET controllers. Specifically, the following ASP.NET controller works both with Chrome and IE.

//[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;
}

If I uncomment [OutputCache] attribute then it works with IE but not with Chrome. Also, I use custom model binding with controllers, so if I write the following:

public ContentResult TestMe(UserContext userContext)
{
  ...
}

it also works with IE, but again not with Chrome which gives me error message saying that resource was not found. Of course, I configured IIS 6 for handling all requests via aspnet_isapi.dll and I have registered custom model binder in my web app's Global.asax inside Application_Start() method. Can someone explain me what might be the cause? Thank you.


回答1:


This doesn't directly answer your question, but I would suggest you try Fiddler, and look at the actual request that is being sent by the browser. Compare the differences and try to figure out what's going wrong (you can use the "Request Builder" tab in Fiddler to eh-hm, fiddle with the parameters).




回答2:


What I discovered is that two methods of WebRequest: Create and CreateHttp behave differently when using HTTPS. Always use Create method to instantiate the right request according to a protocol. I had similar situation and that what I've got. For the following code we have Not Found exception when trying to get some content using WebRequest:

HttpWebRequest request = WebRequest.CreateHttp(uri); 

But the following piece works well:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);



回答3:


Ok, I found a way to solve this problem. In my silverlight app I opted for using client stack instead of using default http stack.

WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);

See also: http://blogs.msdn.com/b/silverlight_sdk/archive/2009/08/12/new-networking-stack-in-silverlight-3.aspx



来源:https://stackoverflow.com/questions/3043099/asp-net-mvc-routing-issue-with-google-chrome-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!