您现在的位置是:首页 > cms教程 > Discuz教程Discuz教程

Discuz!NT的.net中伪静态方式

如萱2025-07-19Discuz教程已有人查阅

导读Discuz!NT的.net中伪静态

<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>
/*
* Discuz!NT Version: 1.0
* Created on 2007-3-30
*
* Web:
* 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
{
成员变量
构造函数
}
}
}

本文标签:

很赞哦! ()

相关源码

  • (自适应)蓝色建材亚克力板材装饰材料pbootcms网站模板这款基于PbootCMS开发的响应式模板为建材板材行业优化设计,适用于亚克力板材、建筑装饰材料等企业展示需求。采用HTML5技术实现手机/PC跨终端适配,管理员通过统一后台即可同步查看源码
  • (自适应)调节阀门气动球阀控制阀网站模板源码下载为调节阀门、气动球阀等工业设备企业打造的响应式网站模板,基于PbootCMS系统开发。突出产品参数展示与技术文档管理功能,通过专业化的布局设计有效呈现工业设备特性,适配各类终端访问需求。查看源码
  • (自适应)幽默笑话脑筋急转弯搞笑趣图博客pbootcms模板下载本模板基于PbootCMS系统开发,专为幽默笑话、搞笑趣图类网站设计。采用轻松活泼的布局风格,突出娱乐内容分享特色,适合各类笑话、段子、搞笑图片等内容展示。查看源码
  • (自适应响应式)HTML5甲醛环境检测网站模板带在线留言和资料下载本模板为甲醛检测与环保科技企业开发,采用PbootCMS内核构建。首页集成空气质量数据可视化模块,服务流程采用时间轴展示设计,检测报告板块支持PDF在线预览功能查看源码
  • (PC+WAP)压缩机离心风机红色机械设备营销型网站pbootcms模板基于PbootCMS开发的压缩机/离心风机专用模板,助力机械设备企业构建高效营销平台;模板可编辑压缩机参数表、风机性能曲线等专业展示模块查看源码
  • (自适应响应式)英文外贸医疗科研耗材设备pbootcms网站模板为医疗设备和外贸企业设计的响应式网站模板,基于PbootCMS系统开发。突出医疗产品认证展示和国际化特性,通过专业化的产品参数展示模块和文档管理系统,满足医疗行业严格的信息披露要求。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐