第一种是在页面global.asax中,相关代码如下:
复制代码 代码如下:
void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
string oldurl = context.Request.Path.ToLower();
if ( ( oldurl.IndexOf("-") > 0 && oldurl.IndexOf(".") == -1) || (oldurl.IndexOf("-") > 0 && oldurl.IndexOf("aspx") > 0) )
{
string[] url = oldurl.Substring(oldurl.LastIndexOf("/") + 1).Replace(".aspx", "").Split('-');
string path = oldurl.Substring(0, oldurl.LastIndexOf("/") + 1);
//file
string file = url[0];
file = file.Replace("about", "detail");
file = file.Replace("news", "list");
file = file.Replace("down", "detail");
file = file.Replace("case", "album");
file = file.Replace("contact", "detail");
//query
string query = "";
for ( int i=1;i<url.Length;i++ )
{
if (url[i] != "")
{
switch (i)
{
case 1:
query += "id=" + url[i];
break;
case 2:
query += "&page=" + url[i];
break;
case 3:
query += "&key=" + url[i];
break;
case 4:
query += "&v1=" + url[i];
break;
case 5:
query += "&v2=" + url[i];
break;
case 6:
query += "&v3=" + url[i];
break;
case 7:
query += "&v4=" + url[i];
break;
case 8:
query += "&v5=" + url[i];
break;
case 9:
query += "&v6=" + url[i];
break;
case 10:
query += "&v7=" + url[i];
break;
}
}
}
//newurl
string newurl = path + file + ".aspx?" + query;
if( context.Request.ServerVariables["QUERY_STRING"] != null && context.Request.ServerVariables["QUERY_STRING"] != "" )
newurl += "&" + context.Request.ServerVariables["QUERY_STRING"];
//Response.Write(newurl);
context.RewritePath(newurl);
}
第二种方法是在HttpModule.cs中,代码如下:
复制代码 代码如下:
public class HttpModule : IHttpModule
{
private const RegexOptions regexOptions = RegexOptions.IgnoreCase | RegexOptions.Compiled;
private static readonly Regex regexFileName = new Regex(@".*?/([^./]*)\.aspx(.*)", regexOptions);
private static readonly Regex regexRewritePath = new Regex(@"^.*?/(\w*)(-?(\w+)-([\w,\|,%]+))+\.aspx", regexOptions);
public void Dispose()
{
}
public void Init(HttpApplication httpApplication)
{
httpApplication.BeginRequest += ReUrl_BeginRequest;
}
private static void ReUrl_BeginRequest(object sender, EventArgs e)
{
Globals.Catch(
() =>
{
var context = ((HttpApplication)sender).Context;
var request = context.Request;
var url = request.Url;
if (!VerifyUrl(url))
{
string input = url.PathAndQuery.ToLower();
//Loger.Debug("PathAndQuery-->" + input);
//Loger.Debug("AbsolutePath-->" + url.AbsolutePath);
//Loger.Debug("AbsoluteUri-->" + url.AbsoluteUri);
//Loger.Debug("DnsSafeHost-->" + url.DnsSafeHost);
//Loger.Debug("LocalPath-->" + url.LocalPath);
//Loger.Debug("AppDomain.CurrentDomain.BaseDirectory-->" + AppDomain.CurrentDomain.BaseDirectory);
//Loger.Debug("Globals.GlobalsVirtualFilePath-->" + Globals.GlobalsVirtualFilePath);
if (input.StartsWith(Globals.GlobalsVirtualFilePath))
input = input.Remove(0, Globals.GlobalsVirtualFilePath.Length);
string viewmode = Globals.ViewMode;
var themeName = request.QueryString["theme"] ?? "";
if (string.IsNullOrEmpty(themeName))
{
themeName = Globals.ThemeName;
}
if (input == "/")
input = "/index.aspx";
if (viewmode == "Rewrite")
{
Loger.Debug("now input-->" + input);
Match match = regexRewritePath.Match(input);
if (match.Success && match.Groups.Count == 5)
{
var captures3 = match.Groups[3].Captures;
var captures4 = match.Groups[4].Captures;
var itemCount = match.Groups[3].Captures.Count;
var list = new List<string>();
for (var i = 0; i < itemCount; i++)
{
list.Add(string.Concat(captures3[i].Value, "=", captures4[i].Value));
}
context.RewritePath(Globals.AspxFileUrl(themeName, match.Groups[1].Value + ".aspx?" + string.Join("&", list.ToArray())));
return;
}
}
var fileName = regexFileName.Match(request.Path.ToLower()).Groups[1].ToString();
if (string.IsNullOrEmpty(fileName))
return;
new ConvertTheme(context)
{
ThemeName = themeName,
ViewMode = viewmode
}.Display(fileName);
}
});
}
private static bool VerifyUrl(Uri uri)
{
var url = uri.AbsolutePath.ToLower();
if (url.StartsWith(Globals.GlobalsVirtualFilePath))
url = url.Remove(0, Globals.GlobalsVirtualFilePath.Length);
return uri.IsFile
|| url.IndexOf("site") != -1
|| url.IndexOf("sys") != -1
|| url.IndexOf("html") != -1
|| url.IndexOf("user") != -1
|| url.IndexOf("bbs") != -1
|| url.IndexOf("_module.aspx") != -1
|| url.IndexOf("webresource.axd") != -1
|| url.IndexOf("scriptresource.axd") != -1;
}
}
复制代码 代码如下:
void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
string oldurl = context.Request.Path.ToLower();
if ( ( oldurl.IndexOf("-") > 0 && oldurl.IndexOf(".") == -1) || (oldurl.IndexOf("-") > 0 && oldurl.IndexOf("aspx") > 0) )
{
string[] url = oldurl.Substring(oldurl.LastIndexOf("/") + 1).Replace(".aspx", "").Split('-');
string path = oldurl.Substring(0, oldurl.LastIndexOf("/") + 1);
//file
string file = url[0];
file = file.Replace("about", "detail");
file = file.Replace("news", "list");
file = file.Replace("down", "detail");
file = file.Replace("case", "album");
file = file.Replace("contact", "detail");
//query
string query = "";
for ( int i=1;i<url.Length;i++ )
{
if (url[i] != "")
{
switch (i)
{
case 1:
query += "id=" + url[i];
break;
case 2:
query += "&page=" + url[i];
break;
case 3:
query += "&key=" + url[i];
break;
case 4:
query += "&v1=" + url[i];
break;
case 5:
query += "&v2=" + url[i];
break;
case 6:
query += "&v3=" + url[i];
break;
case 7:
query += "&v4=" + url[i];
break;
case 8:
query += "&v5=" + url[i];
break;
case 9:
query += "&v6=" + url[i];
break;
case 10:
query += "&v7=" + url[i];
break;
}
}
}
//newurl
string newurl = path + file + ".aspx?" + query;
if( context.Request.ServerVariables["QUERY_STRING"] != null && context.Request.ServerVariables["QUERY_STRING"] != "" )
newurl += "&" + context.Request.ServerVariables["QUERY_STRING"];
//Response.Write(newurl);
context.RewritePath(newurl);
}
第二种方法是在HttpModule.cs中,代码如下:
复制代码 代码如下:
public class HttpModule : IHttpModule
{
private const RegexOptions regexOptions = RegexOptions.IgnoreCase | RegexOptions.Compiled;
private static readonly Regex regexFileName = new Regex(@".*?/([^./]*)\.aspx(.*)", regexOptions);
private static readonly Regex regexRewritePath = new Regex(@"^.*?/(\w*)(-?(\w+)-([\w,\|,%]+))+\.aspx", regexOptions);
public void Dispose()
{
}
public void Init(HttpApplication httpApplication)
{
httpApplication.BeginRequest += ReUrl_BeginRequest;
}
private static void ReUrl_BeginRequest(object sender, EventArgs e)
{
Globals.Catch(
() =>
{
var context = ((HttpApplication)sender).Context;
var request = context.Request;
var url = request.Url;
if (!VerifyUrl(url))
{
string input = url.PathAndQuery.ToLower();
//Loger.Debug("PathAndQuery-->" + input);
//Loger.Debug("AbsolutePath-->" + url.AbsolutePath);
//Loger.Debug("AbsoluteUri-->" + url.AbsoluteUri);
//Loger.Debug("DnsSafeHost-->" + url.DnsSafeHost);
//Loger.Debug("LocalPath-->" + url.LocalPath);
//Loger.Debug("AppDomain.CurrentDomain.BaseDirectory-->" + AppDomain.CurrentDomain.BaseDirectory);
//Loger.Debug("Globals.GlobalsVirtualFilePath-->" + Globals.GlobalsVirtualFilePath);
if (input.StartsWith(Globals.GlobalsVirtualFilePath))
input = input.Remove(0, Globals.GlobalsVirtualFilePath.Length);
string viewmode = Globals.ViewMode;
var themeName = request.QueryString["theme"] ?? "";
if (string.IsNullOrEmpty(themeName))
{
themeName = Globals.ThemeName;
}
if (input == "/")
input = "/index.aspx";
if (viewmode == "Rewrite")
{
Loger.Debug("now input-->" + input);
Match match = regexRewritePath.Match(input);
if (match.Success && match.Groups.Count == 5)
{
var captures3 = match.Groups[3].Captures;
var captures4 = match.Groups[4].Captures;
var itemCount = match.Groups[3].Captures.Count;
var list = new List<string>();
for (var i = 0; i < itemCount; i++)
{
list.Add(string.Concat(captures3[i].Value, "=", captures4[i].Value));
}
context.RewritePath(Globals.AspxFileUrl(themeName, match.Groups[1].Value + ".aspx?" + string.Join("&", list.ToArray())));
return;
}
}
var fileName = regexFileName.Match(request.Path.ToLower()).Groups[1].ToString();
if (string.IsNullOrEmpty(fileName))
return;
new ConvertTheme(context)
{
ThemeName = themeName,
ViewMode = viewmode
}.Display(fileName);
}
});
}
private static bool VerifyUrl(Uri uri)
{
var url = uri.AbsolutePath.ToLower();
if (url.StartsWith(Globals.GlobalsVirtualFilePath))
url = url.Remove(0, Globals.GlobalsVirtualFilePath.Length);
return uri.IsFile
|| url.IndexOf("site") != -1
|| url.IndexOf("sys") != -1
|| url.IndexOf("html") != -1
|| url.IndexOf("user") != -1
|| url.IndexOf("bbs") != -1
|| url.IndexOf("_module.aspx") != -1
|| url.IndexOf("webresource.axd") != -1
|| url.IndexOf("scriptresource.axd") != -1;
}
}
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月29日
2024年11月29日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]