类URLRewriter程序清单中有用到IHttpHandler接口
public void ProcessRequest(HttpContext Context)
{
try
{
//取得原始URL屏蔽掉参数
string Url = Context.Request.RawUrl;
//建立正则表达式
System.Text.RegularExpressions.Regex Reg = new System.Text.RegularExpressions.Regex
(@"/Apply/aspx/show-(\d+)-(\d+)\..+", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
//用正则表达式进行匹配
System.Text.RegularExpressions.Match m =
Reg.Match(Url, Url.LastIndexOf("/"));//从最后一个“/”开始匹配
if (m.Success)//匹配成功
{
String RealPath =
@"/Apply/aspx/show.aspx?type=" + m.Groups[1] + "&id=" + m.Groups[2];
//Context.Response.Write(RealPath);
//Context.RewritePath(RealPath);//(RewritePath 用在无 Cookie 会话状态中。)
Context.Server.Execute(RealPath);
}
else
{
Context.Response.Redirect(Context.Request.Url.ToString());
}
}
catch
{
Context.Response.Redirect(Context.Request.Url.ToString());
}
}在web.config文件还要添加一下设置项
在<system.web>节点下添加如下代码:
程序代码
<httpHandlers>
<add verb="*" path="*/show-?*-?*.aspx" type="UrlRewriter" />
</httpHandlers>在页面没反应,不知问题出在那里,我有找了点资料说要在IIS 里进行配置,要如何配置高手帮我指点下。
public void ProcessRequest(HttpContext Context)
{
try
{
//取得原始URL屏蔽掉参数
string Url = Context.Request.RawUrl;
//建立正则表达式
System.Text.RegularExpressions.Regex Reg = new System.Text.RegularExpressions.Regex
(@"/Apply/aspx/show-(\d+)-(\d+)\..+", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
//用正则表达式进行匹配
System.Text.RegularExpressions.Match m =
Reg.Match(Url, Url.LastIndexOf("/"));//从最后一个“/”开始匹配
if (m.Success)//匹配成功
{
String RealPath =
@"/Apply/aspx/show.aspx?type=" + m.Groups[1] + "&id=" + m.Groups[2];
//Context.Response.Write(RealPath);
//Context.RewritePath(RealPath);//(RewritePath 用在无 Cookie 会话状态中。)
Context.Server.Execute(RealPath);
}
else
{
Context.Response.Redirect(Context.Request.Url.ToString());
}
}
catch
{
Context.Response.Redirect(Context.Request.Url.ToString());
}
}在web.config文件还要添加一下设置项
在<system.web>节点下添加如下代码:
程序代码
<httpHandlers>
<add verb="*" path="*/show-?*-?*.aspx" type="UrlRewriter" />
</httpHandlers>在页面没反应,不知问题出在那里,我有找了点资料说要在IIS 里进行配置,要如何配置高手帮我指点下。
解决方案 »
- 发布.net网站配置文件出错
- winform的datagridvew的拖i放下载功能如何实现
- VS2005中怎么改变控件的默认事件,比如说双击TextBox默认是TextChanged,我想改成单击事件
- 简单的问题:::最匹配的重载方法具有一些无效参数
- 关于一个实际问题,如何实现客户端自动判断金额大小!datalist+checkboxlist问题!
- 下载文本文件后,页面不响应任何操作。报javascript error,对象拒绝访问。
- 在关闭模式窗体时,让原窗口执行一个方法,这样应该怎么做?
- 在.net中如何使用request.form
- 向高手请教asp.net运行问题,急!急!
- 用VC#开发ASP.NET自定义类的奇怪问题,不知大家有没有遇到过?
- 新闻系统中中新闻自动分两列显示问题
- 高分-----讨论服务器防火墙品牌
// rewrite path
context.RewritePath(targetUrl, context.Request.PathInfo, queryString);
IHttpHandler handler = PageParser.GetCompiledPageInstance(targetUrl, context.Server.MapPath(targetUrl), context);
handler.ProcessRequest(context);