2010-12-03 115 views
0

Asp.net 3.5 IIS 7 NHibernet www.sample.com 網站中的虛擬目錄託管ASP.NET MVC 2.0 IIS 7.0和404錯誤

其生成的URL,如「/樣品/首頁/指數「而不是‘/首頁/指數’

好,應用程序正與上述網址,但是當我打電話一樣casecade dropdwonlist任何Ajax的數據,我回到404

操作都工作正常,但只有當我返回Json(數據)它返回404. 我試過wi TH GET和POST

代碼

[HttpPost] 
    public ActionResult GetSubCategories2(int id) 
    { 
     var data = from subCat in CategoryService.GetChildByParentCategory(
      CategoryService.GetCategoryByID(id)) 
        select new { Value = subCat.ID, Text = subCat.CategoryName }; 

     return Json(data); 
    } 

我有一個安全過濾&錯誤處理程序

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method 
    , Inherited = true, AllowMultiple = false)] 
public class HandelRecordNotFound : HandleErrorAttribute 
{ 
    public override void OnException(ExceptionContext filterContext) 
    { 
     if (filterContext.Exception.Message.IndexOf("No row with the given identifier exists") > -1) 
     { 
      //filterContext.HttpContext.Response.Redirect("~/Admin/InvalidRequestOrRecordNotFound"); 
      filterContext.Result = new RedirectResult("~/Admin/InvalidRequestOrRecordNotFound"); 
      filterContext.ExceptionHandled = true; 
     } 

     if (filterContext.Exception.Message.IndexOf("The DELETE statement conflicted") > -1) 
     { 
      //filterContext.HttpContext.Response.Redirect("~/Admin/InvalidRequestOrRecordNotFound"); 
      filterContext.Result = new RedirectResult("~/Admin/InvalidRequestOrRecordNotFound"); 
      filterContext.ExceptionHandled = true; 
     } 
     //filterContext.Exception.Message 

    } 
} 

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method 
    , Inherited = true, AllowMultiple = false)] 
public class AdminAuthorization : AuthorizeAttribute 
{ 
    protected override bool AuthorizeCore(HttpContextBase httpContext) 
    { 
     base.AuthorizeCore(httpContext); 
     object userTypeObject = httpContext.Session["UserType"]; 

     if (userTypeObject == null || 
      (UserTypes)Enum.ToObject(typeof(UserTypes), userTypeObject) != UserTypes.Administrator) 
     { 
      return false; 
     } 
     return true; 
    } 
} 

除了以上每一件事情是正常的。

在客戶端,但是,JsonResult方法返回錯誤404

回答

0

您的應用程序安裝在所謂的「樣品」,而不是在站點根目錄的文件夾的virt服務器的所有做工精細。

請移動應用程序,調整您的路線或使用包含'/ sample /'前綴的正確URL。

+0

沒有我的客戶主要網站上運行的根,所以我不能將其移動到根。我通常在我自己的域名中展示我的工作,像「http://client.wayzsoft.com」這樣的子域名,因爲我從未在生成的Url中找到「wayzsoft」或「client」。就像我想的那樣,即使是子域也被託管爲虛擬目錄。第二我有問題與JsonResult不與ActionResult和內容 – 2010-12-04 09:22:00

2

你的動作過濾器的第一句話:改變

filterContext.Result = new RedirectResult("~/Admin/InvalidRequestOrRecordNotFound"); 

到:

var routes = new RouteValueDictionary(
    new { controller = "admin", action = "InvalidRequestOrRecordNotFound" } 
); 
filterContext.Result = new RedirectToRouteResult(routes); 

第二句話是你在呼喚你的阿賈克斯行動的方式。您應該始終使用url助手來生成正確的路線,並且永遠不要在腳本中對它們進行硬編碼。例如:

相反的:

$.get('/home/someajax', function(result) { 

}); 

務必:

$.get('<%= Url.Action("someajax") %>', function(result) { 

}); 
+0

謝謝你的答案,但InvalidRequestOrRecordNotFound是一個視圖,我只是重定向查看。對於URL,我嚴格用戶Url.Action。 – 2010-12-04 13:20:18