2010-12-03 21 views
0

Asp.net 3.5 は、仮想ディレクトリでホストされている7 NHibernet www.sample.com ウェブサイトをIISASP.NET MVC 2.0 IIS 7.0と404エラー

その「/サンプル/ホーム/インデックスのようなURLを生成/ホーム/インデックスも 『

「代わりに』、アプリケーションは上記のURLに取り組んでいるが、私はcasecadeのdropdwonlistのような任意のAjaxのデータを呼び出すときに、私は404

アクションが正常に動作しているが、私が戻るときにのみ返しますJson(データ)が返す404. 私はwiを試しました

コード

[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); 
    } 

をGETとPOSTの両方番目の私はすべてのもの上記以外の1つのセキュリティフィルタ&エラーハンドラ

[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; 
    } 
} 

が正常である持っています。

答えて

0

あなたのアプリは、「サンプル」と呼ばれるのvirtフォルダに代わりのサイトのルートにインストールされている化するJsonResultメソッドの戻り値のエラー、クライアント側ではなく、サーバー上のすべての作業罰金。

アプリを移動するか、ルートを調整するか、 '/ sample /'プレフィックスを含む正しいURLを使用してください。あなたのアクションフィルタについて

+0

んが、私のクライアントのメインウェブサイトは、ルート上で実行されていません。私は通常、 "http://client.wayzsoft.com"のようなサブドメインとして私自身のドメインで私の仕事を実演しています。私は生成されたURLに "wayzsoft"や "client"が見つかりませんでした。私も思うように、サブドメインさえも仮想ディレクトリとしてホストされています。私はActionResultとコンテンツではないJsonResultとの問題を持っています –

2

まず発言:に変更

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

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

セカンド発言は、あなたのAJAXアクションを呼び出す方法についてです。適切なルートを生成するために、常にURLヘルパーを使用し、スクリプト内でそれらをハードコードしないでください。例:

の代わりに:

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

}); 

の操作を行います。私はルートに移動することはできませんので

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

}); 
+0

あなたの答えはありがとう、しかしInvalidRequestOrRecordNotFoundはビューです、私はちょうど表示するためにリダイレクトしています。 URLでは、私は厳密にユーザーUrl.Actionです。 –

関連する問題