2

私のサイトのaspネットページはwww.mydomain.comにあり、ブログはwww.mydomain.com/blog内にありました。ブログをサブドメインに移動する必要があったため、ブログ内の任意のページの呼び出しを新しいサブドメインにリダイレクトするモジュールを作成する必要があります。

私のマシンでは機能しますが、共有ホスティングにアップロードすると機能しません。何が悪いのか考えてみませんか?

私は次のコードを書きました

    public void ProcessRequest(HttpContext context)
{
    string sourceUrl =  @"www.mydomain.com/blog";// @"localhost:51393/blog"
    string destinationUrl = @"blog.mydomain.com/blog"; 
    string currentLocation = context.Request.Url.AbsoluteUri;
   if(currentLocation.ToLower().Contains(sourceUrl))
   {
       System.Web.HttpContext.Current.Response.Clear();
       System.Web.HttpContext.Current.Response.StatusCode = 301;
       System.Web.HttpContext.Current.Response.AddHeader("Location", currentLocation.Replace(sourceUrl, destinationUrl));
       System.Web.HttpContext.Current.Response.End();           
   }
}

そして、これらのハンドラーを追加しました

 <httpHandlers>
  <add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />
  <add verb="*" path="*" type="MyHandler,App_Code.dll"/>

どんな助けでも深く感謝します。

私はそれがこの1つのhttpHandler-サブフォルダの問題にかなり似ていることを知っていますが、それは機能しませんでした。

4

1 に答える 1

2

IISリライトを使用するだけです

これは、1つのURLを別のURLにリダイレクトする同様のコードです。少し調整すればそれができます。私はこれを私のsmarterasp.netホスティングアカウントで動作させました。

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:0}"
               redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
于 2012-09-19T18:40:14.487 に答える