您现在的位置是:首页 > 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
{
成员变量
构造函数
}
}
}
相关教程
图文教程
Discuz的authcode函数注释
Discuz函数中最经典的函数是authcode函数,因为supesite,UCenterHome,UCenter,Discuz X都使用了这个函数进行加密
配置Discuz与微信小程序开发环境的步骤介绍
在现代网络开发中,Discuz与微信小程序的结合是一个非常有趣的组合。它们可以让你的社区更加活跃,用户体验更为流畅。那么,如何配置Discuz与微信小程序开发环境呢?
CentOs7搭建论坛Discuz_X3.2的步骤方法
由于公司项目需要一个互动平台,可以发起活动,发消息留言,讨论过后发现这竟然是一个论坛的功能。 于是就不打算耗费功夫开发相关功能,直接另外搭一套BBS算球。。。 一直觉得搭建B
discuz X3.2自定义广告代码示例
dz自身是支持自定义广告位的归属于自定义类别,在广告位图标上不能够醒目的显示而且一些必要的后台交互也不好实现,所以找葫芦画瓢做个系统广告。
相关源码
-
(自适应)光伏测试仪器电站运维设备网站源码免费下载本模板为光伏检测设备与电站运维服务企业设计,采用PbootCMS内核开发,具备完整的设备展示、技术文档管理及客户服务功能模块。通过自适应结构与SEO优化框架,有效提升企业在移动端和搜索引擎中的专业形象。查看源码 -
自适应手机版五金机械阀门设备通用行业网站模板该PbootCMS内核开发的网站模板适用于阀门设备、五金机械类企业,通过更换文字图片也可快速适配其他工业领域。采用响应式设计,确保PC端与手机端数据同步,操作便捷,并附带测试数据。查看源码 -
(自适应)帝国CMS7.5模板淘宝客导购博客文章源码本模板基于帝国CMS7.5内核深度开发,为电商导购类网站设计。采用响应式布局技术,确保在手机、平板及电脑端均能获得优质浏览体验。模板内置商品推荐模块与优惠信息展示区,可快速搭建专业导购平台。查看源码 -
(自适应)大型农业机械设备水稻玉米收割机网站pbootcms源码下载本模板基于PbootCMS内核开发,为农业机械设备制造与销售企业设计,特别适合水稻玉米收割机、拖拉机、播种机等农用机械展示。模板充分考虑了农机行业的特性,从产品展示到技术参数,从作业案例到售后服务查看源码 -
(自适应)简繁双语响应式服装服饰西装工装校服定制pbootcms模板本模板基于PbootCMS内核开发,为服装服饰行业量身打造,尤其适合西装定制、工装生产、校服订制等服装类企业使用。模板采用响应式布局设计,确保在手机、平板、电脑查看源码 -
(自适应响应式)APP应用程序软件介绍落地页源码免费下载该模板为营销技术从业者设计,提供专业的内容展示平台。采用响应式布局,适配软件介绍、APP推广等营销场景,通过可视化后台可快速搭建符合行业特性的展示网站。查看源码
| 分享笔记 (共有 篇笔记) |
