看网上说嘴简单方法在GLOBLE里面写string path = Request.Url.ToString();
if (path.EndsWith("/test/WebForm3.aspx")) 
{
 Context.RewritePath("/test/WebForm3-11.aspx?");
}
这样写了以后,跑程序出现无法找到资源的错误吗.首页就是WebForm3.aspx,应该怎么写的,知道的来指点下吧

解决方案 »

  1.   


    这样写:
    string path = Request.Url.ToString();
    if (path.EndsWith("../WebForm3.aspx")) 
    {
     Context.RewritePath("../WebForm3-11.aspx?");
    }
      

  2.   

    string path = Request.Url.ToString(); 
    if (path.EndsWith("WebForm3.aspx")) 

    Context.RewritePath("../WebForm3-11.aspx?"); 
    }
    这样行吧
      

  3.   


    你写过没有呢?感觉这样写不是URL重写,报错了,他会去找WebForm3-11这个页面.但这个页面是不存在的
      

  4.   

    报错 无法找到资源。 
    说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。 
      

  5.   


     Response.Redirect("WebForm3-11.aspx",true);
      

  6.   

    你要将什么格式的url重写为什么格式的url啊??
    我看你的代码觉得很费解
    你的意思是用户看到的(或是输入的)url是/test/WebForm3.aspx格式的
    你要转到你网站项目下的哪个文件啊??难道是WebForm3-11.aspx??? 
    而你又说你根本没有这个文件 这样你怎么转呢???我理解的简单的例子
    string path = Request.Url.ToString();
    if (path.EndsWith("/test/WebForm3.aspx"))//这是用户看到的(输入的) 
    {
     Context.RewritePath("/test/WebForm.aspx?id=3");//这是你服务器处理的 要确定WebForm.aspx是存在的
    }不对之处请指教
      

  7.   


    WebForm3-11.aspx  这个页面没有的话那你想要往哪里连???
      

  8.   

    让我们假定一开始我们有个网页叫Products.aspx,通过查询字符串参数接受一个类别名称,相应地过滤显示的产品。与这个Products.aspx网页对应类别的URL看上去象这样:http://www.store.com/products.aspx?category=books
    http://www.store.com/products.aspx?category=DVDs
    http://www.store.com/products.aspx?category=CDs 但我们不想使用查询字符串来呈示每个类别,我们想修改应用,让每个产品类别对搜索引擎来说看上去象是一个独特的URL,并且在实际的URL中嵌入关键词(而不是通过查询字符串参数)。我们将在这个博客帖子剩下来的篇幅里,讨论一下达成这个目的我们可以采取的4种不同方法。 方法一:使用Request.PathInfo 参数而不是查询字符串我将示范的第一个方法根本不使用URL重写,而是使用ASP.NET中不太为人所知的一个特性,Request的PathInfo属性。为帮助解释这个属性的有用之处,考虑一下我们电子商店下面这些URL的情形: http://www.store.com/products.aspx/Books
    http://www.store.com/products.aspx/DVDs
    http://www.store.com/products.aspx/CDs
    你会在上面这些URL中注意到的一个东西是,他们不再含有查询字符串值,取而代之的是,类别参数的值是附加到URL上的,是以Products.aspx网页处理器名称之后的/参数 值的方式出现的。然后,一个自动化的搜索引擎爬虫(search engine crawler)会把这些URL解释成三个不同的URL,而不是一个URL带有三个不同的输入值 (搜索引擎是不理会文件扩展名的,只把它当作URL中的另一个字符而已)。 
      

  9.   

    http://www.cnblogs.com/superstone/archive/2007/04/02/696422.html
      

  10.   

    string path = Request.Url.ToString();
    if (path.EndsWith("/test/WebForm3-11.aspx")) 
    {
     Context.RewritePath("/test/WebForm3.aspx?id=11");
    }我看你是不是写反了,是不是想把WebForm3-11.aspx转到WebForm3.aspx?
      

  11.   

    URL重写我的理解不就是本来页面是WebForm3.ASPX,我现在不想显示这样的,随便显示个别的不可以吗?
      

  12.   

    16#兄弟说得对(其实我也是觉得你是这样的) 你的确是弄反了 没有理解url重写的意思
    RewritePath后面的才是"真实的"url 就是为了不给用户看到!!
      

  13.   

    你在Global里注册事件没,
    是在什么事件所处何生命周期里进行更改的,
    这是关键啊.
      

  14.   

    context .Request.ApplicationPath 使用绝对路径
      

  15.   


    那这么简单的说一下吧.我现在打开一个页面是http://localhost/test/WebForm3.aspx?id=11如果我不做任何修改,IE地址栏里面将显示该地址,现在我想通过我上面的方法,让IE地址栏里面显示的是
    http://localhost/test/WebForm3-11.aspx?
    这样的形式,那怎么做.用我上面的方法可以实现吗?
      

  16.   

    URLRewriter 用这个重写.网上有的是例子.
      

  17.   

    1. 楼主,你貌似用的是VS2003
    2. 一般自己写Url重写是使用HttpHandle,如果你用的是VS2003,没有asp.net 2.0好实现
      

  18.   

        string path = Request.Url.ToString(); 
        if(path.Contains("WebForm3-")) 
        { 
            int heng = path.LastIndexOf("-");//横 
            int dot = path.LastIndexOf("."); 
            if (dot - heng != 1) 
            { 
                string id = path.Substring(heng + 1, dot - heng - 1); 
                Context.RewritePath("~/WebForm3.aspx?id=" + num); 
            } 
        } 晕死 写的太笨了 谁来个正则解决下 最好连WebForm1 WebForm2也能考虑的
      

  19.   

    你的资源目录里是不是有WebForm3.aspx而不是WebForm3-11.aspx
      

  20.   

    楼主写反了,Context.RewritePath()里面是内部要被重写的路径
      

  21.   

    web.config里加<urlMappings>
    <add url="~/test/WebForm3-11.aspx" mappedUrl="~/test/WebForm3.aspx"/>
    </urlMappings>
      

  22.   

    方法二:使用HttpModule实现URL重写 
    上述Request.PathInfo技术的替换方法是,利用ASP.NET提供的HttpContext.RewritePath方法。这个方法允许开发人员动态地重写收到的URL的处理路径,然后让ASP.NET使用刚重写过后的路径来继续执行请求。 譬如,我们可以选择向大众呈示下列URL:
    http://www.store.com/products/Books.aspx
    http://www.store.com/products/DVDs.aspx
    http://www.store.com/products/CDs.aspx 在外界看来,网站上有三个单独的网页(对搜索爬虫而言,这看上去很棒)。通过使用 HttpContext的RewritePath方法,我们可以在这些请求刚进入服务器时,动态地把收到的URL重写成单个Products.aspx网页接受一个查询字符串的类别名称或者PathInfo参数。譬如,我们可以使用Global.asax中的Application_BeginRequest事件,来这么做:     void Application_BeginRequest(object sender, EventArgs e) {        string fullOrigionalpath = Request.Url.ToString();
            
            if (fullOrigionalpath.Contains("/Products/Books.aspx")) {
                Context.RewritePath("/Products.aspx?Category=Books");
            }
            else if (fullOrigionalpath.Contains("/Products/DVDs.aspx")) {
                Context.RewritePath("/Products.aspx?Category=DVDs");
            }
        }