【发布时间】:2012-03-15 06:06:22
【问题描述】:
在 asp.net mvc 应用程序中,我有一个将 JsonResult 返回到视图的方法。它在我的本地计算机上完美运行,但是当应用程序部署在 Web 托管服务器上时,当我尝试通过点击视图的链接获取此数据时,我在 Firebug 中得到 404 Not Found。有没有人知道可能发生这种情况的原因?我如何生成路径的代码 sn-ps 如下:
private void get_info()
{
var serviceUri = new Uri("/getcountrydata/" + country_name + "/" + arms[0].Name + "/" + arms[1].Name + "/" + arms[2].Name + "/" + arms[3].Name, UriKind.Relative);
var webClient = new WebClient();
webClient.OpenReadCompleted += openReadCompleted;
webClient.OpenReadAsync(serviceUri);
}
Global.asax 路由如下:
routes.MapRoute(
"getcountrydata",
"getcountrydata/{country}/{indicator1}/{indicator2}/{indicator3}/{indicator4}",
new { controller = "Home", action = "getcountrydata" }
);
getcountrydata方法如下:
public JsonResult getcountrydata(string country, string indicator1, string indicator2, string indicator3, string indicator4)
{
LegoData legoData = captainClimateRepostory.GetLegoData(country, indicator1, indicator2, indicator3, indicator4);
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(LegoData));
MemoryStream ms = new MemoryStream();
ser.WriteObject(ms, legoData);
return Json(ms.ToArray(), JsonRequestBehavior.AllowGet);
}
【问题讨论】:
-
您知道您的托管服务提供商使用的是哪个版本的 IIS?您应该能够在 firebug 响应标头中看到它。
-
他们使用的是 Microsoft-IIS/7.5
-
使用 REST 客户端在 firefox 上测试您的服务,一旦您在那里工作,您可以尝试修复此代码!
标签: c# asp.net asp.net-mvc json silverlight