一步范域名解析
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;
namespace demohttpmodel
{
public class MyFirstHttpModule : IHttpModule
{
private void Application_BeginRequest(object sender, EventArgs e)
{
//HttpApplication application = (HttpApplication)sender;
//HttpContext context = application.Context;
//HttpRequest request = application.Request;
//HttpResponse response = application.Response;
string host = System.Web.HttpContext.Current.Request.Url.Host;
string domain = host.Split('.')[0];
if (domain != "www")
{
//System.Web.HttpContext.Current.Response.Write(System.Web.HttpContext.Current.Request.RawUrl + "<br>");
//System.Web.HttpContext.Current.Response.Write(System.Web.HttpContext.Current.Request.FilePath + "<br>");
//System.Web.HttpContext.Current.Response.Write(System.Web.HttpContext.Current.Request.Url + "<br>");
string tempurl = System.Web.HttpContext.Current.Request.RawUrl;
tempurl = tempurl.Substring(tempurl.LastIndexOf("/")+1);
tempurl = tempurl.IndexOf("?") > 0 ? (tempurl+"&") : (tempurl+"?");
// System.Web.HttpContext.Current.Response.Write(string.Format("/demo/{1}ID={0}", domain, tempurl) + "<br>");
System.Web.HttpContext.Current.RewritePath(string.Format("/Industry/{1}GroupID={0}", domain, tempurl));
}
//else
//{
// System.Web.HttpContext.Current.Response.Write(System.Web.HttpContext.Current.Request.RawUrl + "selex<br>");
//}
// System.Web.HttpContext.Current.Response.Write("<script>alert('demo')</script>");
// response.Write("我来自自定义HttpModule中的BeginRequest<br />");
}
private void Application_EndRequest(object sender, EventArgs e)
{
//HttpApplication application = (HttpApplication)sender;
//HttpContext context = application.Context;
//HttpRequest request = application.Request;
//HttpResponse response = application.Response;
//response.Write("我来自自定义HttpModule中的EndRequest<br />");
}
#region IHttpModule 成员
public void Dispose()
{ }
public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(Application_BeginRequest);
application.EndRequest += new EventHandler(Application_EndRequest);
}
#endregion
}
}
<system.web>
<httpModules>
<add name="MyFirstHttpModule" type="demohttpmodel.MyFirstHttpModule,demohttpmodel"/>
<!--
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />-->
</httpModules>