2011-08-08 4 views

答えて

1

ASP.NETルーティングは、.NET 4でWebフォームのために利用可能で、3.5私は思います。

MSDNに関するガイダンスがあります。 http://msdn.microsoft.com/en-us/library/cc668201.aspx

Webフォームの例はRouteCollectionExtensionsタイプがMVCフレームワークのRouteCollectionを拡張する拡張メソッドを提供し、あなたがRouteCollectionを拡張するextension methods独自に作成することができますglobal.asax

protected void Application_Start(object sender, EventArgs e) 
{ 
    RegisterRoutes(RouteTable.Routes); 
} 

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.MapPageRoute("", 
     "Category/{action}/{categoryName}", 
     "~/categoriespage.aspx"); 
} 

に以下を追加する必要があります。

以下の簡単な例では、MyRouteCollectionExtensionsを別の場所に置くことをお勧めします。

using System; 
using System.Web.Routing; 

namespace WebFormsExtension 
{ 
    public class Global : System.Web.HttpApplication 
    { 

     void Application_Start(object sender, EventArgs e) 
     { 
      RegisterRoutes(RouteTable.Routes); 
     } 

     public static void RegisterRoutes(RouteCollection routes) 
     { 
      routes.MapCustomRoute("SampleRoute/{name}"); 
     } 

    } 

    public static class MyRouteCollectionExtensions 
    { 
     public static void MapCustomRoute(this RouteCollection routes, string url) 
     { 
      PageRouteHandler handler = new PageRouteHandler("~/default.aspx"); 
      Route myRoute = new Route(url, handler);  
      routes.Add(myRoute); 
     } 
    } 
} 
+0

クリス、ありがとう、私はあなたのポイントを理解していますが、私は別のsmtをする必要があります。 http://goneale.com/2008/12/19/lowercase-route-urls-in-aspnet-mvc/を見てください。MVCの代わりにAsp.net Web Formsに実装する必要があります。また、RouteCollectionExtensionsクラスはMVCルーティング専用です私は思うだろうExtend RouteCollectionは私にあなたの考えを教えてくれました – GibboK

+0

あなたは型名に混乱していると思います。そのサンプルを使用できない理由はありません。そのサンプルの 'RouteCollectionExtensions'クラスは' System.Web.MVC.RouteCollectionExtensions'クラスと同じではなく、作者はMVCクラスと同じ名前の独自のクラスを作成しています。あなたは 'MyRouteCollectionExtensions ' '上記の私の例では。 WebFormsの小文字のUrlの場合とほとんど同じです。 –

+0

[OK]私はあなたのポイントを参照して、ちょうど最後の質問どのように私はPage.GetRouteUrlメソッドであなたのコードを使用するでしょうか?あなたの時間をありがとうございます:-) – GibboK

関連する問題