<httpModules>
<add type="Discuz.Forum.HttpModule, Discuz.Forum" name="HttpModule" />
</httpModules>
<add type="Discuz.Forum.HttpModule, Discuz.Forum" name="HttpModule" />
</httpModules>
<?xml version="1.0" encoding="utf-8" ?>
<urls>
<rewrite name="showforum"
path="/showforum-{0}-{1}.aspx"
pattern = "/showforum-(\d+)(-(\d+))?.aspx"
page="/showforum.aspx"
querystring="forumid=$1^page=$3" />
<rewrite name="showtopic"
path="/showtopic-{0}-{1}.aspx"
pattern = "/showtopic-(\d+)(-(\d+))?.aspx"
page="/showtopic.aspx"
querystring="topicid=$1^page=$3" />
<rewrite name="userinfo"
path="/userinfo-{0}.aspx"
pattern = "/userinfo-(\d+)*.aspx"
page="/userinfo.aspx"
querystring="userid=$1" />
<rewrite name="rss"
path="/rss-{0}.aspx"
pattern = "/rss(-(\d+))?.aspx"
page="/rss.aspx"
querystring="forumid=$2" />
</urls>
<urls>
<rewrite name="showforum"
path="/showforum-{0}-{1}.aspx"
pattern = "/showforum-(\d+)(-(\d+))?.aspx"
page="/showforum.aspx"
querystring="forumid=$1^page=$3" />
<rewrite name="showtopic"
path="/showtopic-{0}-{1}.aspx"
pattern = "/showtopic-(\d+)(-(\d+))?.aspx"
page="/showtopic.aspx"
querystring="topicid=$1^page=$3" />
<rewrite name="userinfo"
path="/userinfo-{0}.aspx"
pattern = "/userinfo-(\d+)*.aspx"
page="/userinfo.aspx"
querystring="userid=$1" />
<rewrite name="rss"
path="/rss-{0}.aspx"
pattern = "/rss(-(\d+))?.aspx"
page="/rss.aspx"
querystring="forumid=$2" />
</urls>
/*
* Discuz!NT Version: 1.0
* Created on 2007-3-30
*
* Web: http://www.discuznt.com
* Copyright (C) 2001 - 2007 Comsenz Technology Inc., All Rights Reserved.
* This is NOT a freeware, use is subject to license terms.
*
*/
using System;
using System.Diagnostics;
using System.Threading;
using System.Web;
using System.Xml;
using System.Text.RegularExpressions;
using Discuz.Common;
namespace Discuz.Forum
{
/// <summary>
/// HttpModule 的摘要说明。
/// </summary>
public class HttpModule : System.Web.IHttpModule
{
//public readonly static Mutex m=new Mutex();
/// <summary>
/// 实现接口的Init方法
/// </summary>
/// <param name="context"></param>
public void Init(HttpApplication context)
{
OnlineUserFactory.ResetOnlineList();
context.BeginRequest += new EventHandler(ReUrl_BeginRequest);
}
public void Application_OnError(Object sender , EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
//if (context.Server.GetLastError().GetBaseException() is MyException)
{
//MyException ex = (MyException) context.Server.GetLastError().GetBaseException();
context.Response.Write("<html><body style=\"font-size:14px;\">");
context.Response.Write("Discuz!NT Error:<br />");
context.Response.Write("<textarea name=\"errormessage\" style=\"width:80%; height:200px; word-break:break-all\">");
context.Response.Write(System.Web.HttpUtility.HtmlEncode(context.Server.GetLastError().ToString()));
context.Response.Write("</textarea>");
context.Response.Write("</body></html>");
context.Response.End();
}
}
/// <summary>
/// 实现接口的Dispose方法
/// </summary>
public void Dispose()
{
}
/// <summary>
/// 重写Url
/// </summary>
/// <param name="sender">事件的源</param>
/// <param name="e">包含事件数据的 EventArgs</param>
private void ReUrl_BeginRequest(object sender, EventArgs e)
{
BaseConfigInfo config = Providers.BaseConfigProvider.Instance();
if (config == null)
return;
HttpContext context = ((HttpApplication)sender).Context;
string forumPath = BaseConfigFactory.GetForumPath.ToLower();
string requestPath = context.Request.Path.ToLower();
if (requestPath.StartsWith(forumPath))
{
if (requestPath.Substring(forumPath.Length).IndexOf("/") == -1)
{
// 当前样式id
string strTemplateid = ConfigFactory.GetDefaultTemplateID().ToString();
//string ttt = Utils.GetCookie("dnttemplateid");
if (Utils.InArray(Utils.GetCookie("dnttemplateid"), TemplateFactory.GetValidTemplateIDList()))
{
strTemplateid = Utils.GetCookie("dnttemplateid");
}
foreach (SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls)
{
if (Regex.IsMatch(requestPath, url.Pattern, RegexOptions.Compiled|RegexOptions.IgnoreCase))
{
string newUrl = Regex.Replace(requestPath.Substring(context.Request.Path.LastIndexOf("/")), url.Pattern, url.QueryString, RegexOptions.Compiled|RegexOptions.IgnoreCase);
context.RewritePath(forumPath + "aspx/" + strTemplateid + url.Page, string.Empty, newUrl);
return;
}
}
context.RewritePath(forumPath + "aspx/" + strTemplateid + requestPath.Substring(context.Request.Path.LastIndexOf("/")));
}
else if (requestPath.StartsWith(forumPath + "archiver/"))
{
string path = requestPath.Substring(forumPath.Length + 8);
foreach(SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls)
{
if (Regex.IsMatch(path, url.Pattern, RegexOptions.Compiled|RegexOptions.IgnoreCase))
{
string newUrl = Regex.Replace(path, url.Pattern, url.QueryString, RegexOptions.Compiled|RegexOptions.IgnoreCase);
context.RewritePath(forumPath + "archiver" + url.Page, string.Empty, newUrl);
return;
}
}
return;
}
else if (requestPath.StartsWith(forumPath + "tools/"))
{
string path = requestPath.Substring(forumPath.Length + 5);
foreach (SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls)
{
if (Regex.IsMatch(path, url.Pattern, RegexOptions.Compiled|RegexOptions.IgnoreCase))
{
string newUrl = Regex.Replace(path, url.Pattern, url.QueryString, RegexOptions.Compiled|RegexOptions.IgnoreCase);
context.RewritePath(forumPath + "tools" + url.Page, string.Empty, newUrl);
return;
}
}
return;
}
}
}
}
//////////////////////////////////////////////////////////////////////
public class SiteUrls
{
内部属性和方法
public static SiteUrls GetSiteUrls()
{
if (instance == null)
{
lock (lockHelper)
{
if (instance == null)
{
instance = new SiteUrls();
}
}
}
return instance;
}
public static void SetInstance(SiteUrls anInstance)
{
if (anInstance != null)
instance = anInstance;
}
public static void SetInstance()
{
SetInstance(new SiteUrls());
}
/// <summary>
/// 输出URL示例
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public string Show(int id)
{
return string.Format(Paths["Show"], id);
}
public class URLRewrite
{
成员变量
构造函数
}
}
}
* Discuz!NT Version: 1.0
* Created on 2007-3-30
*
* Web: http://www.discuznt.com
* Copyright (C) 2001 - 2007 Comsenz Technology Inc., All Rights Reserved.
* This is NOT a freeware, use is subject to license terms.
*
*/
using System;
using System.Diagnostics;
using System.Threading;
using System.Web;
using System.Xml;
using System.Text.RegularExpressions;
using Discuz.Common;
namespace Discuz.Forum
{
/// <summary>
/// HttpModule 的摘要说明。
/// </summary>
public class HttpModule : System.Web.IHttpModule
{
//public readonly static Mutex m=new Mutex();
/// <summary>
/// 实现接口的Init方法
/// </summary>
/// <param name="context"></param>
public void Init(HttpApplication context)
{
OnlineUserFactory.ResetOnlineList();
context.BeginRequest += new EventHandler(ReUrl_BeginRequest);
}
public void Application_OnError(Object sender , EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
//if (context.Server.GetLastError().GetBaseException() is MyException)
{
//MyException ex = (MyException) context.Server.GetLastError().GetBaseException();
context.Response.Write("<html><body style=\"font-size:14px;\">");
context.Response.Write("Discuz!NT Error:<br />");
context.Response.Write("<textarea name=\"errormessage\" style=\"width:80%; height:200px; word-break:break-all\">");
context.Response.Write(System.Web.HttpUtility.HtmlEncode(context.Server.GetLastError().ToString()));
context.Response.Write("</textarea>");
context.Response.Write("</body></html>");
context.Response.End();
}
}
/// <summary>
/// 实现接口的Dispose方法
/// </summary>
public void Dispose()
{
}
/// <summary>
/// 重写Url
/// </summary>
/// <param name="sender">事件的源</param>
/// <param name="e">包含事件数据的 EventArgs</param>
private void ReUrl_BeginRequest(object sender, EventArgs e)
{
BaseConfigInfo config = Providers.BaseConfigProvider.Instance();
if (config == null)
return;
HttpContext context = ((HttpApplication)sender).Context;
string forumPath = BaseConfigFactory.GetForumPath.ToLower();
string requestPath = context.Request.Path.ToLower();
if (requestPath.StartsWith(forumPath))
{
if (requestPath.Substring(forumPath.Length).IndexOf("/") == -1)
{
// 当前样式id
string strTemplateid = ConfigFactory.GetDefaultTemplateID().ToString();
//string ttt = Utils.GetCookie("dnttemplateid");
if (Utils.InArray(Utils.GetCookie("dnttemplateid"), TemplateFactory.GetValidTemplateIDList()))
{
strTemplateid = Utils.GetCookie("dnttemplateid");
}
foreach (SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls)
{
if (Regex.IsMatch(requestPath, url.Pattern, RegexOptions.Compiled|RegexOptions.IgnoreCase))
{
string newUrl = Regex.Replace(requestPath.Substring(context.Request.Path.LastIndexOf("/")), url.Pattern, url.QueryString, RegexOptions.Compiled|RegexOptions.IgnoreCase);
context.RewritePath(forumPath + "aspx/" + strTemplateid + url.Page, string.Empty, newUrl);
return;
}
}
context.RewritePath(forumPath + "aspx/" + strTemplateid + requestPath.Substring(context.Request.Path.LastIndexOf("/")));
}
else if (requestPath.StartsWith(forumPath + "archiver/"))
{
string path = requestPath.Substring(forumPath.Length + 8);
foreach(SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls)
{
if (Regex.IsMatch(path, url.Pattern, RegexOptions.Compiled|RegexOptions.IgnoreCase))
{
string newUrl = Regex.Replace(path, url.Pattern, url.QueryString, RegexOptions.Compiled|RegexOptions.IgnoreCase);
context.RewritePath(forumPath + "archiver" + url.Page, string.Empty, newUrl);
return;
}
}
return;
}
else if (requestPath.StartsWith(forumPath + "tools/"))
{
string path = requestPath.Substring(forumPath.Length + 5);
foreach (SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls)
{
if (Regex.IsMatch(path, url.Pattern, RegexOptions.Compiled|RegexOptions.IgnoreCase))
{
string newUrl = Regex.Replace(path, url.Pattern, url.QueryString, RegexOptions.Compiled|RegexOptions.IgnoreCase);
context.RewritePath(forumPath + "tools" + url.Page, string.Empty, newUrl);
return;
}
}
return;
}
}
}
}
//////////////////////////////////////////////////////////////////////
public class SiteUrls
{
内部属性和方法
public static SiteUrls GetSiteUrls()
{
if (instance == null)
{
lock (lockHelper)
{
if (instance == null)
{
instance = new SiteUrls();
}
}
}
return instance;
}
public static void SetInstance(SiteUrls anInstance)
{
if (anInstance != null)
instance = anInstance;
}
public static void SetInstance()
{
SetInstance(new SiteUrls());
}
/// <summary>
/// 输出URL示例
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public string Show(int id)
{
return string.Format(Paths["Show"], id);
}
public class URLRewrite
{
成员变量
构造函数
}
}
}