2009-06-17 6 views
0

From my last question、私はAsp.netルーティングの詳細情報read thisための既存のURLのルートではないことが判明しています。 Asp.netルーティングを使用して別のURLに既存のURLをリダイレクトする方法はAsp.netのルーティングを使用することで、既存のURLをルーティングすることは不可能ですか?

ヒント!私が思う

は、アクセスのようなこのbeheviorは常にログインページをデフォルトにリダイレクトすることbehevior否定しました。

おかげで、

+0

答えがある場合は、なぜ質問していますか? – Avitus

+0

私は何の答えもありません。アイデアはありますか? –

答えて

0

コントローラのアクション/ルート)にリダイレクトされます。 HttpModuleを使うととても簡単です。私の次のサンプルコードを見てください。もっとINFOMATIONについては

グローバルweb.configファイルで

<configuration> 
    <system.web> 
     <httpModules> 
      <add name="RedirectModule" type="MySolution.RedirectModule, MySolution" /> 
     </httpModules> 
    </system.web> 
    <!-- The following code will be used by IIS 7+ --> 
    <system.webServer> 
     <modules runAllManagedModulesForAllRequests="true"> 
      <remove name="RedirectModule" /> 
      <add name="RedirectModule" type="MySolution.RedirectModule MySolution" /> 
     </modules> 
    </system.webServer> 
</configuration> 

MySolution/RedirectModule.csで

using System; 
using System.Web; 

namespace MySolution 
{ 
    public class RedirectModule : IHttpModule 
    { 
     #region IHttpModule Members 

     public void Init(HttpApplication context) 
     { 
      context.BeginRequest += new EventHandler(HttpApplication_BeginRequest); 
     } 

     public void Dispose() {} 

     #endregion 

     void HttpApplication_BeginRequest(object sender, EventArgs e) 
     { 
      HttpApplication app = sender as HttpApplication; 

      if (*[logic for checking before redirect]*) 
      { 
       app.Response.Redirect(*[url]*); 
      } 
     } 
    } 
} 

UrlRewritingNet.UrlRewriteのようなURLマッピングのソースコードを見てください。

PS。 IHttpModuleは非常に強力なインターフェイスです。それはすべての要求タイプで処理できます。それで、私はこの質問を完全に解決するのに役立ちます。

0

あなたは-existing- URLが/ルートテーブルに「マッチした」「発見」、そしてあなたがリダイレクト先となるURLではないされていることを確認する必要があります....(しない限り、私は解決策を見つけた

+0

私はこのパターンを使用します( "{* anything}")。 –

関連する問題