Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... SwiXml SwiX ml , is a small GUI generating engine for Java applications and applets. Graphical User Interfaces are described in XML documents that ... executeOrDelayUntilScriptLoaded Executes the specified function if the file containing it is loaded; otherwise, adds it to the pending job queue. ExecuteOrDelayUntilScrip...
Stats
Url rewrite using IHttpModule
UrlRewriter.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

/// <summary>
/// UrlRewriter 的摘要描述
/// </summary>
namespace idv.modules
{
    public class UrlRewriter : IHttpModule
    {

        #region IHttpModule 成員

        public void Dispose()
        {
            //throw new NotImplementedException();
        }

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

        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;
            HttpContext context = application.Context;

            if (context.Request.Path.EndsWith("TranslatedPage.html", StringComparison.CurrentCultureIgnoreCase))
            {
                string currentUrl = context.Request.Path;

                // rewrite url [http://www.domain.com/actionValue/TranslatedPage.html]
                // to [http://www.domain.com/TranslatedPage.aspx?action=actionValue]
                string action = Regex.Match(currentUrl, "/([^/]+)/TranslatedPage.html", RegexOptions.IgnoreCase).Groups[1].Value;
                context.RewritePath("~/TranslatedPage.aspx?action=" + action);
            }
        }

        #endregion
    }
}
Web.config
<httpModules>
    <add name="UrlRewriter" type="idv.modules.UrlRewriter"/>
</httpModules>