2010-12-03 72 views
0

我想通過編程方式禁用網站出於許可原因,我想在httpmodule中執行此操作。我應該在IHttpModule中使用什麼事件來禁用網站?

伊夫試圖重定向上下文:

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

但我得到的錯誤:

Response is not available in this context. 

任何人都知道我怎樣纔能有效地禁止的網站,最好送他們到自定義頁面。

回答

2

您可以使用BeginRequest事件重定向,像以下:

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

也許有更好的方式來關閉該網站將程序寫出來的App_Offline.htm文件到網站的根。若要從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(); 

} 

您可以使用此代碼

相關問題