上一篇 | 下一篇

asp.net 1.1中url重写的问题

发布: 2008-6-29 22:11 | 作者: admin | 来源: | 查看: 0次

>

1:asp.net1.1中重写中可删节的问题!!!

如以下的正则表达式:

~/(\d{4})/(\d{2})\.html---------<1>

~/(\d{4})/(\d{2})/--------------<2>

~/(\d{4})/(\d{2})-----------<3>

~/(\d{4})/(\d{2})/index.html----<4>

~/Pro.aspx?year=$1&month=$2

其中的1,4可以正常映射到对应的页面

可2,3则会出现http404错误!!!

其原因在于IIS本身的处理流程,解决办法则是在网站自己重写404处理错误!!!

1:自定义处理404错误的URL(在IIS中配置,在web.config中的配置对重写无用)

2:在System.Web节中添加如下节:

源代码如下:

public class Http404:System.Web.IHttpHandler

{

public Http404()

{

//

// TODO: 在此处添加构造函数逻辑

//

}

#region IHttpHandler 成员

public void ProcessRequest(System.Web.HttpContext context)

{

// TODO: 添加 Http404.ProcessRequest 实现

string errorPath=context.Request.RawUrl.Split(new char[]{';'}) ;

string appPath=context.Request.ApplicationPath;

int ipos=errorPath.IndexOf(appPath);

string url=errorPath.Substring(ipos+appPath.Length );

// if(!url.EndsWith("/"))

// {

// url+="/";

// }

// url+="index.html";

// context.Response.Write(url);

// context.RewritePath(url);

//context.Response.Write(url);

url="~"+url;

string newUrl =lt.ReWriteModule.GetUrl(context,url);

//context.Response.Write(newUrl);

if (newUrl != null)

{

//cxt.Response.Filter = new ResponseFilter(cxt.Response.Filter,cxt.Request.Path);

context.Response.Write("请求的路径:" + url);

context.Response.Write("
");

context.Response.Write("转向的目的URL:" + newUrl);

context.Response.Write("
");

context.RewritePath(newUrl);

}

else

{

context.Response.Write("你请求的资源不存在!!");

context.Response.End ();

}

}

字号: | 推荐给好友

41/41234>

评分:0

我来说两句