2011-07-11 13 views
0

私は、多くのアプリケーションで生成されたログを1つの共通データベースに読み込むオンラインログビューアアプリケーションを作成しています。ログの種類はerror、fatal、debugです。私はすべてをすべてのログを表すために使用します。ASP.NET MVCルーティングヘルプが必要です

私はAppsControllerという名前のコントローラを用意しています.ContentControllerは、以下のリクエストのためにサーバービューを必要とします。ここで、 "bi-reports"は、多くのアプリケーション名の1つです。

/apps/bi-reports/ 
/apps/bi-reports/all 
/apps/bi-reports/error/ 
/apps/bi-reports/2011/04/ 
/apps/bi-reports/2011/04/all 
/apps/bi-reports/2011/error 
/apps/bi-reports/2011/04/error 
/apps/bi-reports/all/last-hundred 
/apps/bi-reports/all/most-hundred 
/apps/bi-reports/2011/last-hundred 
/apps/bi-reports/2011/04/all/last-hundred 

これを実行するには、コントローラのアクションメソッドでルート設定パラメータを設定する必要がありますか?

+0

あなたの意図する結果は何ですか?私。 "/ apps /"の後のすべてをメソッドのパラメータとして扱い、それに基づいてデータを取得しますか? – GalacticCowboy

+0

私は 'most-hundred'を' last-hundred'に、 'all'をページングパラメータにします。また、「すべて」と「2011」をクエリーストリングのパラメータにすることもできます。エラーは、ActionFilterからプルアップされる「共有ビュー」にする必要があります。次に、 'apps'コントローラと' bi-reports'アクションが残っています。 –

+0

'?myParameter = all'を使わずにアクションにパラメータを送ることができることを覚えておいてください。スキップして'/all'を使うことができます –

答えて

1

のようなものを持っているでしょう、これらの線に沿って何かをするだろう。私はあなたが基本的にルートの3種類があることを見ることができます。

routes.MapRoute(
    "IrrelevantDates", 
    "{controller}/{application}/{type}/{range}", 
    // defaults 
    new { 
     controller = "Apps", 
     action = "UnboundReport", 
     type = "all", 
     range = "no-limit" 
    }, 
    // constraints 
    new { 
     type = "apps|error" 
    } 
); 

routes.MapRoute(
    "RelevantYearOnly", 
    "{controller}/{application}/{year}/{type}/{range}", 
    // defaults 
    new { 
     controller = "Apps", 
     action = "YearlyReport", 
     type = "all", 
     range = "no-limit" 
    }, 
    // constraints 
    new { 
     year = "19\d{2}|2[01]\d{2}", 
     type = "apps|error" 
    } 
); 

routes.MapRoute(
    "RelevantYearAndMonth", 
    "{controller}/{application}/{year}/{month}/{type}/{range}", 
    // defaults 
    new { 
     controller = "Apps", 
     action = "MonthlyReport", 
     type = "all", 
     range = "no-limit" 
    }, 
    // constraints 
    new { 
     year = "19\d{2}|2[01]\d{2}", 
     month = "0[1-9]|1[0-2]", 
     type = "apps|error" 
    } 
); 

を私は、彼らが実際に有効な月0112に指定する必要がありますので19002199、そして数ヶ月の間で年に合わせて、年間の制約を設定しました。

追加のコントローラがある場合は、既定のルートも定義してコントローラの制約をこのコントローラに設定するか、コントローラ名を静的にする必要があります。

0

私はこれがあなたのルーティング定義の目安である

''# note, this is untested VB and might need some tweaking. 
    routes.MapRouteLowercase("Base", "", 
          New With {.controller = "Home", 
             .action = "Index", 
             .year = UrlParameter.Optional, 
             .paging = UrlParameter.Optional}, 
          New With {.year = "[0-9]*"}) 

は、その後、あなたのコントローラが

Function Index(ByVal paging As String, ByVal year As Integer?) As ActionResult 

     ''# do your pre-processing for paging and year. 

     Return View() 
    End Function 
関連する問題