您现在的位置是:首页 > 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企业网站源码为供应链管理、进出口服务类企业设计,特别适合展示物流网络、贸易服务和供应链解决方案。采用响应式技术,确保在各类设备上都能呈现企业服务内容。查看源码
  • (自适应响应式)AI智能电子科技产品pbootcms网站模板下载基于PbootCMS内核的响应式模板,为AI智能硬件、电子产品等科技企业打造,通过技术创新实现品牌数字化升级。查看源码
  • (自适应响应式)蓝色律师事务所法务团队网站pbootcms模板为律师事务所和法律服务机构打造的专业网站模板,展现法律专业性与权威性,手工编写标准DIV+CSS代码,结构清晰优化,确保高效运行,自动适配电脑、平板和手机等各类设备,提供更好浏览体验查看源码
  • (自适应)绿色新闻生活百科资讯文章博客类网站pbootcms模板源码本模板基于PbootCMS开发,为生活百科、资讯文章和博客类网站设计。采用清新绿色系风格,提供舒适的阅读体验,同时适配PC和移动设备。适用于生活技巧分享、健康知识传播查看源码
  • (自适应)中英双语配线器材扎带线卡网站pbootcms模板免费下载为线缆管理、电气配线领域打造的响应式网站模板,采用PbootCMS内核开发,可快速搭建企业级产品展示平台,数据实时同步管理。查看源码
  • (自适应)蓝色自动溶剂萃取仪器设备类网站pbootcms模板下载本模板为溶剂萃取设备、实验室仪器等精密仪器行业设计,采用PbootCMS内核开发,具有高度专业性和行业适配性。模板设计充分考虑了仪器设备行业展示需求,能够呈现各类精密仪器的技术参数、应用场景和解决方案。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐