私は自分の問題を解決したようです。カスタム ルート制約で使用することはできますが、IIS7.0 では Application_Start で Request オブジェクトにアクセスすることはできません。これが私がやった方法です。
カスタム ルート制約を定義します。
Imports System.Web
Imports System.Web.Routing
Public Class ConstraintHost
Implements IRouteConstraint
Private _value As String
Sub New(ByVal value As String)
_value = value
End Sub
Public Function Match(ByVal httpContext As System.Web.HttpContextBase, ByVal route As System.Web.Routing.Route, ByVal parameterName As String, ByVal values As System.Web.Routing.RouteValueDictionary, ByVal routeDirection As System.Web.Routing.RouteDirection) As Boolean Implements System.Web.Routing.IRouteConstraint.Match
Dim hostURL = httpContext.Request.Url.Host.ToString()
Return hostURL.IndexOf(_value, StringComparison.OrdinalIgnoreCase) >= 0
End Function
End Class
次に、ルートを定義します。
routes.MapPageRoute(
"Search_Area1",
"Search",
"~/area1/search.aspx",
True,
Nothing,
New RouteValueDictionary(New With {.ArbitraryParamName = New ConstraintHost("domain1.com")})
)
routes.MapPageRoute(
"Search_Area2",
"Search",
"~/area2/search.aspx")
)
この手法は、サブドメインに基づいて異なるルーティングを適用する場合にも使用できます。
私を正しい方向に向けてくれた Steven Wather のasp.net mvc ルーティングポストに大いに感謝します (Web フォームではなく mvc のためのものでしたが)。