我用Httphandler重写URL改地址栏文件扩展名,但是运行结果文件扩展名还是没有变,但是可以手动改变,请问怎么样才能使他运行处来时就改变扩展名
解决方案 »
- 框架刷新问题,各位大虾帮忙啊!急~~~
- 从未见过的问题(grideview)
- server is too busy 是什么原因啊 急死了 ~~
- Asp.Net编程的人被骗了,都上电视了(UP有分)
- 日期控件怎么与文章(博客)发布的日期关联?
- 关于LoadControl的一个问题
- 分页存储过程
- ORACLE两个数据库相互取数问题。
- 请教一个关于Context的问题。我在一个登录页面写了Session,可是当转到下一个页面的时候为什么Session为未定义
- 哪位高手用.net做过微信?帮忙看看这段代码为什么不能实现被关注时自动回复图文消息?
- 子窗口取父窗口textbox的ID??
- iframe scrolling=yes的情况下,有一个页面却需要scrolling=no怎么处理?
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;/// <summary>
/// MyHandler 的摘要说明
/// </summary>
public class MyHandler : IHttpHandler
{
public MyHandler()
{
//
// TODO: 在此处添加构造函数逻辑
//
} #region IHttpHandler 成员 public bool IsReusable
{
get { return false; }
} public void ProcessRequest(HttpContext context)
{
context.Response.Write("DuoTian");
string path = context.Request.RawUrl;
context.Server.Transfer(path.Replace(".html", ".aspx"));
} #endregion
}<httpHandlers>
<add verb="*" path="*.html" type="MyHandler"/>
</httpHandlers>
这句有问题, 应该是: Server.Execute(path.Replace(".aspx", ".html"));
{
public UrlRewriter()
{
}
public void ProcessRequest(HttpContext Context)
{
try
{
string Url = Context.Request.RawUrl;
System.Text.RegularExpressions.Regex Reg = new System.Text.RegularExpressions.Regex(@"/show-(\d+)-(\d+)\..+",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Match m =
Reg.Match(Url,Url.LastIndexOf("/"));
if (m.Success)
{
String RealPath = @"~/aspx/show.aspx?type=" + m.Groups[1] + "&id=" + m.Groups[2];
Context.Server.Execute(RealPath);
}
else
{
Context.Response.Redirect(Context.Request.Url.ToString());
}
}
catch
{
Context.Response.Redirect(Context.Request.Url.ToString());
}
}
public bool IsReusable
{
get { return false; }
}
}
在<system.web>节点下添加如下代码:
<httpHandlers>
<add verb="*" path="*/show-?*-?*.aspx" type="UrlRewriter" />
</httpHandlers>
参考