您现在的位置: 无忧电子商务网 >> 信息学院 >> 程序开发 >> asp.net >> 正文

asp.net 1.1中url重写的问题

作者:作者:未…    信息学院来源:网络收集    点击数:    更新时间:2006-8-28 我要参与讨论

   

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

如以下的正则表达式:

<Rules>
  <RewriterRule>
    <LookFors>
      <LookFor>~/(\d{4})/(\d{2})\.html</LookFor>---------<1>
      <LookFor>~/(\d{4})/(\d{2})/</LookFor>--------------<2>
      <LookFor>~/(\d{4})/(\d{2})</LookFor>-----------<3>
      <LookFor>~/(\d{4})/(\d{2})/index.html</LookFor>----<4>
    </LookFors>
    <SendTo>~/Pro.aspx?year=$1&amp;month=$2</SendTo>
  </RewriterRule>
 </Rules>

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

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

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

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

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

<httpHandlers>
   
          <add verb="*" path="404.aspx" type="lt.Http404,lt"></add>
   </httpHandlers>
   <httpModules>
  <add type="lt.ReWriteModule,lt" name="ModuleRewriter" />
 </httpModules>

源代码如下:

  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[]{';'})[1];
   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("<BR>");
    context.Response.Write("转向的目的URL:" + newUrl);
    context.Response.Write("<BR>");
    context.RewritePath(newUrl);
   }
   else
   {
    context.Response.Write("你请求的资源不存在!!");

[1] [2] [3] [4] 下一页

在google里搜索更多asp.net 1.1中url重写的问题

Google
Web www.51ec.org
  • 上一篇信息学院:

  • 下一篇信息学院:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    我来说两句 对此文章发表了评论
      昵 称: *必填    ·注册用户·
      评 分: 1分 2分 3分 4分 5分     严禁发表危害国家安全、政治、黄色淫秽等内容的评论,用户需对自己在使用本网站服务过程中的行为承担法律责任。本站管理员有权保留或删除评论内容,评论内容只代表机友个人观点,与本网站立场无关。  
    评 论
    内 容

     
    评论列表 (最新 评论仅限网友观点!)

    供求信息




    | 设为首页 | 加入收藏 | 关于我们 | 广告服务 | 联系方式 | 友情链接 | 版权申明