在一個asp.net mvc應用程序中,我有一個方法將JsonResult返回給視圖。它在我的本地機器上完美工作,但是當應用程序部署在虛擬主機服務器上時,當我嘗試通過點擊視圖鏈接來獲取這些數據時,我在Firebug中找到了404 Not Found。有沒有人知道這可能發生的可能原因?我的代碼的隻言片語我如何生成路徑低於:Json 404未找到
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響應頭文件中看到它。 – russau 2012-03-14 04:56:15
他們正在使用Microsoft-IIS/7.5 – 2012-03-14 05:05:28
使用Firefox上的REST客戶端來測試你的服務,一旦你得到它的工作,你可以嘗試修復這段代碼! – 2012-03-14 06:44:37