2010-12-03 3 views
0

私は免許上の理由からウェブサイトをプログラム的に無効にしたいのですが、httpmoduleでそれをやりたいのです。ウェブサイトを無効にするためにIHttpModuleでどのようなイベントを使用する必要がありますか?

public void Init(HttpApplication context) 
{ 
    context.Response.Redirect("http://vls.pete.videolibraryserver.com"); 
} 

をしかし、私はエラーを取得する:

アイブ氏は、コンテキストをリダイレクトしようとした

Response is not available in this context. 

誰もが、私は効果的にウェブサイトを無効にし、好ましくはカスタムページにそれらを送ることができる方法を知っています。あなたは次のように、リダイレクト用BeginRequestイベントを使用することができます

答えて

2

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

void context_BeginRequest(object sender, EventArgs e) 
{ 
    HttpApplication application = (HttpApplication)sender; 
    application.Context.Response.Redirect("http://vls.pete.videolibraryserver.com"); 
} 
0

使用Server.Transferこれは往復の節約になりますようにカスタムページを提供する同じマシン上にあります。 HTTPModule BeginRequest should us Response.Redirect or Server.Transfer(これは私が答えた自分の質問です - 自己宣伝になろうとしていない)おそらく、サイトを閉鎖するより良い方法は、プログラムのWebサイトのルートにApp_Offline.htmファイルを書き出すことであろう

0

Scott Guthrie's blogから引用すると:

"The way app_offline.htm works is that you place this file in the root of the application. When ASP.NET sees it, it will shut-down the app-domain for the application (and not restart it for requests) and instead send back the contents of the app_offline.htm file in response to all new dynamic requests for the application. When you are done updating the site, just delete the file and it will come back online."

0
public void Init(HttpApplication context) 
{ 

    context.Response.Write("for licence visit this <a href=\"http://vls.pete.videolibraryserver.com\">link</a>"); 
    context.Response.End(); 

} 

を、あなたはこのコードを使用することができます

関連する問題