224 lines
10 KiB
C#
224 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Web;
|
|
using System.Web.SessionState;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Web.Security;
|
|
namespace Mtxfw.DAL
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class ReWriteModule : System.Web.IHttpModule
|
|
{
|
|
public ReWriteModule()
|
|
{
|
|
//
|
|
// TODO: 在此处添加构造函数逻辑
|
|
//
|
|
}
|
|
#region IHttpModule 成员
|
|
|
|
public void Init(System.Web.HttpApplication context)
|
|
{
|
|
// TODO: 添加 ReWriteModule.Init 实现
|
|
context.BeginRequest += new EventHandler(this.ReWrite);
|
|
}
|
|
|
|
protected void ReWrite(object sender, EventArgs e)
|
|
{
|
|
//System.Web.HttpContext context = (sender as System.Web.HttpApplication).Context;
|
|
HttpApplication app = (HttpApplication)sender;
|
|
HttpContext context = app.Context;
|
|
|
|
|
|
DateTime dt = DateTime.Now;
|
|
if (context.Request.ContentType != "image/pjpeg" && context.Request.ContentType != "aspx")
|
|
{
|
|
|
|
string oldUrl = context.Request.RawUrl.ToString().ToLower();
|
|
string oldUrl2 = context.Request.RawUrl.ToString();
|
|
string HostName = HttpContext.Current.Request.Url.Host.ToString();
|
|
string[] UserHost = HostName.Split(new Char[] { '.' }); //数组,以“.”分隔
|
|
if (UserHost.Length == 3 || UserHost[0] == "localhost")
|
|
{
|
|
string pattern = @"^(.+)article-(.*?)\.html(\?.*)*$";
|
|
Regex R = new Regex(pattern);
|
|
Match M = R.Match(oldUrl);
|
|
if (M.Success)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "article.aspx?ID=" + M.Groups[2].ToString();
|
|
context.RewritePath(newUrl);
|
|
|
|
}
|
|
pattern = @"^(.+)wxpay_(.*?)_(.*?)_(.*?)\.html(\?.*)*$";
|
|
R = new Regex(pattern);
|
|
M = R.Match(oldUrl2);
|
|
if (M.Success)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "wxpay.aspx?je=" + M.Groups[2].ToString() + "&t=" + M.Groups[3].ToString() + "&billbo=" + M.Groups[4].ToString() + M.Groups[5].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
|
|
}
|
|
pattern = @"^(.+)view-(.*?)\.html(\?.*)*$";
|
|
R = new Regex(pattern);
|
|
M = R.Match(oldUrl);
|
|
if (M.Success)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "shop_view.aspx?id=" + M.Groups[2].ToString() + "" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
|
|
}
|
|
pattern = @"^(.+)category-(.*?)\.html(\?.*)*$";
|
|
R = new Regex(pattern);
|
|
M = R.Match(oldUrl);
|
|
if (M.Success)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "shop_category.aspx?id=" + M.Groups[2].ToString() + "" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
|
|
}
|
|
pattern = @"^(.+)search-class-(.*?)\.html(\?.*)*$";
|
|
R = new Regex(pattern);
|
|
M = R.Match(oldUrl);
|
|
if (M.Success)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "shop_search.aspx?classid=" + M.Groups[2].ToString() + "" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
|
|
}
|
|
else
|
|
{
|
|
pattern = @"^(.+)search-(.*?)\.html(\?.*)*$";
|
|
R = new Regex(pattern);
|
|
M = R.Match(oldUrl);
|
|
if (M.Success)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "shop_search.aspx?stype=" + M.Groups[2].ToString() + "" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
|
|
}
|
|
else
|
|
{
|
|
pattern = @"^(.+)search\.html(\?.*)*$";
|
|
R = new Regex(pattern);
|
|
M = R.Match(oldUrl);
|
|
if (M.Success)
|
|
{
|
|
if (M.Groups[1].ToString().IndexOf("e/") == -1)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "shop_search.aspx" + M.Groups[2].ToString();
|
|
context.RewritePath(newUrl);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
pattern = @"^(.+)bbs/forum-type-(.*?)\.html(\?.*)*$";
|
|
R = new Regex(pattern);
|
|
M = R.Match(oldUrl);
|
|
if (M.Success)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "bbs/list.aspx?stype=" + M.Groups[2].ToString() + "" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
|
|
}
|
|
else
|
|
{
|
|
pattern = @"^(.+)bbs/forum-(.*?)\.html(\?.*)*$";
|
|
R = new Regex(pattern);
|
|
M = R.Match(oldUrl);
|
|
if (M.Success)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "bbs/list.aspx?classid=" + M.Groups[2].ToString() + "" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
|
|
}
|
|
else
|
|
{
|
|
pattern = @"^(.+)bbs/forum\.html(\?.*)*$";
|
|
R = new Regex(pattern);
|
|
M = R.Match(oldUrl);
|
|
if (M.Success)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "bbs/list.aspx" + M.Groups[3].ToString();
|
|
context.RewritePath(newUrl);
|
|
|
|
}
|
|
}
|
|
}
|
|
pattern = @"^(.+)bbs/thread-(.*?)\.html(\?.*)*$";
|
|
R = new Regex(pattern);
|
|
M = R.Match(oldUrl);
|
|
if (M.Success)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "/bbs/particular.aspx?BBSID=" + M.Groups[2].ToString() + "" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
|
|
}
|
|
/* pattern = @"^(.+)e/(.*?)\.html(\?.*)*$";
|
|
R = new Regex(pattern);
|
|
M = R.Match(oldUrl);
|
|
if (M.Success)
|
|
{
|
|
string str1 = M.Groups[2].ToString();
|
|
if (str1.ToLower().IndexOf("cp-") == -1 && str1.ToLower().IndexOf("cplist-") == -1 && str1.ToLower().IndexOf("search") == -1 && str1.ToLower().IndexOf("companynews") == -1 && str1.ToLower().IndexOf("industrynews") == -1 && str1.ToLower().IndexOf("newcx-") == -1)
|
|
{
|
|
string str = new Mtxfw.DAL.Article().Getzd("ID", "ParentID=12 And Paths='/e/" + Mtxfw.Utility.Tools.SafeSQL(str1) + ".html'").ToString();
|
|
if (str != "")
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "e/about.aspx?ID=" + str + "" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (str1.IndexOf("cp-") != -1)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "e/cp.aspx?ID=" + Mtxfw.Utility.Tools.SafeSQL(str1.Replace("cp-", "")) + "" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
}
|
|
if (str1.IndexOf("cplist-") != -1)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "e/cplist.aspx?ClassID=" + Mtxfw.Utility.Tools.SafeSQL(str1.Replace("cplist-", "")) + "" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
}
|
|
if (str1.IndexOf("newcx-") != -1)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "e/newcx.aspx?ID=" + Mtxfw.Utility.Tools.SafeSQL(str1.Replace("newcx-", "")) + "" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
}
|
|
if (str1.ToLower() == "companynews")
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "e/newslist.aspx?t=0" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
}
|
|
if (str1.ToLower() == "industrynews")
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "e/newslist.aspx?t=1" + M.Groups[3].ToString().Replace("?", "&");
|
|
context.RewritePath(newUrl);
|
|
}
|
|
if (str1.IndexOf("search") != -1)
|
|
{
|
|
string newUrl = M.Groups[1].ToString() + "e/cplist.aspx" + M.Groups[3].ToString();
|
|
context.RewritePath(newUrl);
|
|
}
|
|
}
|
|
}*/
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// TODO: 添加 ReWriteModule.Dispose 实现
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|