在IIS站点属性中添加自定义映射,如添加一个扩展名为.fbsx的文件类型,通过实现IHttpHandler来进行重定向。
实现IHttpHandler的类:
使用IRequiresSessionState的目的是:能够在目标页面中使用Session。注意如果目标页面中使用Ajax.Net组件,在注册类型的时候应使用第二个参数:
AjaxPro.Utility.RegisterTypeForAjax(typeof(YourClass), this);
打开IIS管理器,在站点属性的映射中添加一个.fbsx的文件扩展名,其他设置与.aspx的一致,注意“确认文件是否存在”不能勾选。
在web.config中配置httpHandlers节:
<configSections>
<section name="URLRewriterConfig" type="FaibClass.Common.Web.URLRewriterConfigSerializerSectionHandler, FaibClass.Common" />
</configSections>
<URLRewriterConfig>
<Rules>
<URLRewriterRule>
<MatchUrl>([\d]+)\.fbsx</MatchUrl>
<RedirectUrl><![CDATA[target.aspx?to=$1]]></RedirectUrl>
</URLRewriterRule>
</Rules>
</URLRewriterConfig>
这样,只要我们键入一个1234.fbsx文件,浏览器就会重定向到target.aspx页面进行相应的执行。
实现IHttpHandler的类:
1
using System;
2
using System.Text.RegularExpressions;
3
using System.Web;
4
using System.Web.SessionState;
5![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
namespace FaibClass.Common.Web
7
{
8
public class URLRewriterHandler : IHttpHandler, IRequiresSessionState
9
{
10
public void ProcessRequest(HttpContext context)
11
{
12
URLRewriterRuleCollection rules = URLRewriterConfiguration.GetConfig().Rules;
13
string requestedPath = context.Request.FilePath;
14
for(int i = 0; i < rules.Count; i++)
15
{
16
Regex reg = new Regex(rules[i].MatchUrl, RegexOptions.IgnoreCase);
17
bool isMatch = reg.IsMatch(requestedPath);
18
if(isMatch)
19
{
20
context.Server.Execute(reg.Replace(requestedPath, rules[i].RedirectUrl));
21
}
22
}
23
}
24![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
public bool IsReusable
26
{
27
get
28
{
29
return true;
30
}
31
}
32
}
33
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
使用IRequiresSessionState的目的是:能够在目标页面中使用Session。注意如果目标页面中使用Ajax.Net组件,在注册类型的时候应使用第二个参数:
AjaxPro.Utility.RegisterTypeForAjax(typeof(YourClass), this);
打开IIS管理器,在站点属性的映射中添加一个.fbsx的文件扩展名,其他设置与.aspx的一致,注意“确认文件是否存在”不能勾选。
在web.config中配置httpHandlers节:
1
<httpHandlers>
2
<add verb="POST,GET" path="*.fbsx" type="FaibClass.Common.Web.URLRewriterHandler, FaibClass.Common" />
3
</httpHandlers>
并配置重定向配置节![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
这样,只要我们键入一个1234.fbsx文件,浏览器就会重定向到target.aspx页面进行相应的执行。