IIS设置,例如TOMCAT过滤器 [英] IIS setting like TOMCAT filter
本文介绍了IIS设置,例如TOMCAT过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发asp.net网站.
有人注意到我IIS有像TOMCAT这样的过滤器吗?
我想在当地时间重定向我的网站.
例如)
9:00-18:00提供服务.
另一个是重定向非服务页面.
如果是Tomcat Web服务器,此设置很容易编译Jave并将其放到/WEB-INF/classes/filters并修改web.xml.
I''m now developing asp.net web site.
Anyone notice me IIS has filters like TOMCAT?
I would like to redirect my website by the local time.
ex)
9:00-18:00 is service available.
The other is redirect non-service page.
If Tomcat web server, this setting is easy to compile Jave and put it to /WEB-INF/classes/filters and modify web.xml.
Anyone knows?
推荐答案
我不知道以下方法与Java过滤器相同.
使用HTTPModule解决了此问题.
我在下面的源代码中实现并定制了web.config.
这样可以吗?
App_Code/TimeJudge.cs
I don''t know the below method is same as Java filter.
This problem was solved using HTTPModule.
I implemented below source and customized web.config.
Is this OK?
App_Code/TimeJudge.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class TimeJudge : IHttpModule
{
public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler
(this.OnBeginRequest);
}
private void OnBeginRequest(Object source, EventArgs e)
{
string nowTime = DateTime.Now.ToString("HHmm");
string startTime = System.Configuration.ConfigurationManager.AppSettings[WebConfigKey.StartTime.ToString()];
string endTime = System.Configuration.ConfigurationManager.AppSettings[WebConfigKey.EndTime.ToString()];
if (nowTime.CompareTo(startTime) > 0 && nowTime.CompareTo(endTime) < 0)
{
return;
}
HttpApplication application = (HttpApplication)source;
if (application.Request.Url.AbsoluteUri.EndsWith(".ASPX") && !application.Request.Url.AbsoluteUri.EndsWith("STOP.ASPX"))
application.Response.Redirect("~/STOP.ASPX");
}
public void Dispose()
{
}
}
web.config
web.config
<configuration>
<system.web>
<httpmodules>
<add name="TimeJudge" type="TimeJudge" />
</httpmodules>
</system.web>
<appsettings>
<!-- system Avilable Time -->
<add key="StartTime" value="0730" />
<add key="EndTime" value="2159" />
</appsettings>
</configuration>
这篇关于IIS设置,例如TOMCAT过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文