Popular Posts
Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i... 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 - Layout BorderLayout BorderLayoutPane.xml <?xml version="1.0" encoding="UTF-8"?> <panel layout="BorderLayout...
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>