2012-03-14 141 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