Click here to Skip to main content
15,889,553 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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?
Posted
Comments
Sandeep Mewara 9-May-12 2:37am    
Interesting. I only knew of manual way. Lets see if there is an automatic configuration too, will wait to post my manual way. 5!
axt_star 11-May-12 0:14am    
I have solved my problem.
Thank you for the comment.

1 solution

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
C#
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
HTML
<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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900