zoukankan
html css js c++ java
利用IHttpModule实现URL地址转发功能
using
System;
using
System.Web;
using
System.Text.RegularExpressions;
namespace
WebControlLibrary1
{
/**/
///
<summary>
///
BaseModuleRewriter 的摘要说明。
///
</summary>
public
abstract
class
BaseModuleRewriter:IHttpModule
{
public
BaseModuleRewriter()
{
//
//
TODO: 在此处添加构造函数逻辑
//
}
IHttpModule 成员
#region
IHttpModule 成员
public
virtual
void
Init(HttpApplication app)
{
app.AuthorizeRequest
+=
new
EventHandler(app_AuthorizeRequest);
}
public
virtual
void
Dispose()
{
//
TODO: 添加 BaseModuleRewriter.Dispose 实现
}
#endregion
protected
virtual
void
app_AuthorizeRequest(
object
sender, EventArgs e)
{
HttpApplication app
=
(HttpApplication)sender;
this
.Rewrite(app.Request.Path,app);
}
protected
abstract
void
Rewrite(
string
requestedPath, HttpApplication app);
}
public
class
ModulRewriter:BaseModuleRewriter
{
protected
override
void
Rewrite(
string
requestedPath, HttpApplication app)
{
string
strPath
=
requestedPath;
string
strFileName
=
strPath.Substring(strPath.LastIndexOf(
"
/
"
)
+
1
);
string
strReg
=
@"
^\d+
"
;
Regex reg
=
new
Regex(strReg,RegexOptions.IgnoreCase);
if
(reg.IsMatch(strFileName))
{
string
strTruePath
=
strPath.Remove(strPath.LastIndexOf(
"
/
"
)
+
1
,strFileName.Length);
strTruePath
=
strTruePath
+
"
go.aspx?id=
"
+
reg.Match(strFileName).Value;
HttpContext.Current.RewritePath(strTruePath);
//
app.Server.Execute(strTruePath);
}
else
{
//
app.Server.Execute(strPath);
HttpContext.Current.RewritePath(strPath);
}
}
}
}
其实网上已经有很多人都实现了,但我现在自己实现了一下,以加深印象。在web.config中写入:
<httpModules>
<add type="WebControlLibrary1.ModulRewriter, WebControlLibrary1" name="ModuleRewriter" />
</httpModules>
即可。
查看全文
相关阅读:
(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated UXXXXXXXX escape 错误
Pandas_key_point
鲁棒性、稳定性、非脆弱性
防止过拟合的处理方法
Python中的random模块
Python reload(sys)找不到,name 'reload' is not defined
sigmoid 和 soft-max总结
2.7 Structured Regression Models
2.x ESL第二章习题2.4
2.6. Statistical Models, Supervised Learning and Function Approximation
原文地址:https://www.cnblogs.com/sxlfybb/p/585138.html
最新文章
Alpha 冲刺 (10/10)
Alpha 冲刺 (9/10)
Alpha 冲刺 (8/10)
Alpha 冲刺 (7/10)
Alpha 冲刺 (6/10)
团队作业-随堂小测(同学录)
Alpha 冲刺 (5/10)
Java面向对象之封装
我的Java之旅——答答租车系统的改进
我的Java之旅——答答租车系统
热门文章
Java面向对象之继承
Java重写&重载
Java补充内容
Java编程练习题
我的Java之旅——之后的学习计划
我的Java之旅——第一个Java程序
Java代码规范
常用的推荐算法分类
Matplotlib_key_point
Pandas之locilocix
Copyright © 2011-2022 走看看