2011-11-13 16 views
2

company.com/store/bank_accountはMVCビューの代わりにcompany.com/store/bank_account/default.aspxをロードするようにMVCルーティングにどのように伝えることができますか?MVCビューとASPXページを同じフォルダに混在させるにはどうすればよいですか?

ありがとうございました。

+0

MVCとWebformsを混在させることはお勧めできません。 – Prasanth

+0

どのように右上にLoginリンクがあるMVCに何百もの静的ページを表示しますか?それぞれのためのビューを作る? – abenci

+1

あなたはその質問の静的なページについて言及していません。各ページでログインリンクを繰り返す場合は、mvcのマスターページを使用することができます – Prasanth

答えて

3

これは、IgnoreRouteを使用して行うことができます。あなたはこの

routes.IgnoreRoute("{resource}.aspx/{*pathInfo}"); 

チェックアウトこの http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx

http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc

+0

IgnoreRouteが '/ store/bank_account'のような拡張のないURLをaspxパスにどのようにマッピングするのか分かりません。 IgnoreRouteは、*拡張子付きのページ*を簡単に打つことができますが、それは本当に問題ではありませんでした。しかし、良い情報のために+1。 –

0

をオプションでは、このようなHelicon's ISAPI Rewriteとして、書き換えエンジンを使用することであるようなのglobal.asaxでこれを設定することができます。または、IIS7以上を使用している場合は、Microsoft's URL rewriterを使用できます。

MVCアプリが既に用意されているため、a method like this oneを使用してウェブフォームページのルーティングを使用できます。

This articleは、上記のものとリンクされており、シナリオに役立つ便利なクラスです。リンクは時々

public class WebFormRouteHandler : IRouteHandler 
{ 
    public WebFormRouteHandler(string virtualPath) : this(virtualPath, true) 
    { 
    } 

    public WebFormRouteHandler(string virtualPath, bool checkPhysicalUrlAccess) 
    { 
    this.VirtualPath = virtualPath; 
    this.CheckPhysicalUrlAccess = checkPhysicalUrlAccess; 
    } 

    public string VirtualPath { get; private set; } 

    public bool CheckPhysicalUrlAccess { get; set; } 

    public IHttpHandler GetHttpHandler(RequestContext requestContext) 
    { 
    if (this.CheckPhysicalUrlAccess 
     && !UrlAuthorizationModule.CheckUrlAccessForPrincipal(this.VirtualPath 
       , requestContext.HttpContext.User 
       , requestContext.HttpContext.Request.HttpMethod)) 
     throw new SecurityException(); 

    var page = BuildManager 
     .CreateInstanceFromVirtualPath(this.VirtualPath 
     , typeof(Page)) as IHttpHandler; 

    if (page != null) 
    { 
     var routablePage = page as IRoutablePage; 
     if (routablePage != null) 
     routablePage.RequestContext = requestContext; 
    } 
    return page; 
    } 
} 

あなたはGlobal.asax.csであなたのルートを登録するときに使用したいということを消えるので

コードはここに再現しました。

public static void RegisterRoutes(RouteCollection routes) 
{ 
    // Note: Change the URL to "{controller}.mvc/{action}/{id}" to enable 
    //  automatic support on IIS6 and IIS7 classic mode 

    var routeHandler = new WebFormRouteHandler<Page>("~/MyPage.aspx"); 

    routes.Add(new Route("{page}", routeHandler)); 
    routes.Add(new Route("AccountServices/{page}", routeHandler)); 
    routes.Add(new Route("Default.aspx", routeHandler)); 
} 
関連する問題