我应该在 IHttpModule 中使用什么事件来禁用网站?
出于许可原因,我想以编程方式禁用网站,并且我想在 httpmodule 中执行此操作。
我尝试重定向上下文:
public void Init(HttpApplication context)
{
context.Response.Redirect("http://vls.pete.videolibraryserver.com");
}
但我收到错误:
Response is not available in this context.
任何人都知道如何有效禁用该网站并最好将它们发送到自定义页面。
I want to disable a website programatically for licensing reasons, and I want to do it in a httpmodule.
Ive tried to redirect the context :
public void Init(HttpApplication context)
{
context.Response.Redirect("http://vls.pete.videolibraryserver.com");
}
But I get the error:
Response is not available in this context.
Anybody know how I can effectively disable the website and preferably send them to a custom page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
BeginRequest
事件进行重定向,如下所示:you can use
BeginRequest
event for redirection, like following:使用 Server.Transfer,因为如果自定义页面位于同一台计算机上,这将节省往返时间; HTTPModule BeginRequest 应该使用 Response.Redirect 或 Server.Transfer(这是我自己回答的问题 - 不是为了自我推销)
Use
Server.Transfer
as this will save a round trip provided the custom page is on the same machine; HTTPModule BeginRequest should us Response.Redirect or Server.Transfer (this is my own question I answered - not trying to be self promoting)也许关闭网站的更好方法是以编程方式将 App_Offline.htm 文件写入网站的根目录。引用 Scott Guthrie 的博客:
Perhaps a better way to close the site would be to programmatically write out an App_Offline.htm file to the root of the website. To quote from Scott Guthrie's blog:
你可以使用这个代码
you can use this code