2012-03-14 126 views
0

在一個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); 


    } 
+0

你知道你的託管服務提供商使用的是什麼版本的IIS嗎?你應該能夠在firebug響應頭文件中看到它。 – russau 2012-03-14 04:56:15

+0

他們正在使用Microsoft-IIS/7.5 – 2012-03-14 05:05:28

+1

使用Firefox上的REST客戶端來測試你的服務,一旦你得到它的工作,你可以嘗試修復這段代碼! – 2012-03-14 06:44:37

回答

2

我認爲這是您爲該操作提供的網址存在問題。它與主機服務器不是相對的。勾選此SO後..

jquery ajax call to JsonResult controller method results in 404 on IIS6

+0

問題是我無法使用Url.Action()幫助器方法在哪裏生成查詢,因爲這是在Silverlight項目中,並且您無法在其中引用System.Web.Mvc? – 2012-03-14 05:15:15

+0

爲什麼你不能在那裏引用System.Web.MVC? – 2012-03-14 05:28:05

+0

你不能將System.Web.MVC dll添加到silverlight項目中。它只允許你添加Silverlight特定的dll。 – 2012-03-14 06:29:31