2011-12-08 24 views
1

私はASP.NET 4 WebFormsベースのアプリケーションを持っており、http://www.example.com/site/foo/Default.aspxが "foo"という名前のクライアント用で、http://www.example.com/site/bar/Default.aspxがbarという名前のクライアント用であるようなマルチテナントを許可するルーティングを使用したいとします。IRouteHandlerを使用してWebFormsアプリケーションでマルチテナントを設定するにはどうすればよいですか?

私は限りました:

// Global.asax in Application_Start 
routes.Add("ClientSelector", new System.Web.Routing.Route 
(
    "site/{client}/{*path}", 
    new Lcmp.Web.Configuration.ClientRoute() 
)); 


public class ClientRoute : System.Web.Routing.IRouteHandler 
{ 
    private string m_Path; 
    private string m_Client; 

    public ClientRoute() { } 

    public bool IsReusable 
    { 
     get { return true; } 
    } 

    public IHttpHandler GetHttpHandler(System.Web.Routing.RequestContext requestContext) 
    { 
     this.m_Path = (string)requestContext.RouteData.Values["path"]; 
     this.m_Client = (string)requestContext.RouteData.Values["client"]; 

     string virtualPath = "~/" + this.m_Path; 

     bool shouldValidate = false; 

     if (shouldValidate && !UrlAuthorizationModule.CheckUrlAccessForPrincipal(
      virtualPath, requestContext.HttpContext.User, 
          requestContext.HttpContext.Request.HttpMethod)) 
     { 
      requestContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized; 
      requestContext.HttpContext.Response.End(); 
      return null; 
     } 
     else 
     { 
      HttpContext.Current.RewritePath(virtualPath); 
      HttpContext.Current.Items.Add("Client", this.m_Client); 
      return (IHttpHandler)BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(Page)); 
     } 
    } 
} 

、最初の.aspxページのために働くようです。しかし、ルーティングでは、.jsやその他の非コンパイル可能なリソースが取り出され、例外がスローされます。これらのルーティングを避ける最善の方法は何ですか?

答えて

2

あなたcan use the StopRoutingHandler() to ignore requests for certain files

routes.Add(new Route("*{js}", new {[email protected]".*\.js(/.*)?", new StopRoutingHandler())); 
+0

ああ、本当に、私は答えとしてマークします。しかし、私の質問は悪かった - 実際には、私はそれらの他の要素(少なくともasmx)をルーティングする必要があり、何とかそれを修正します。ありがとう!私は別の質問を投稿した:http://stackoverflow.com/questions/8527677/how-do-i-use-asp-net-webforms-routing-to-an-asmx-scriptservice –

関連する問題