我的的url地址是:http://localhost:6000/Pagination.aspx?currentPage=15
用Request.Url.AbsoluteUri ,结果是:http://localhost:6000/Pagination.aspx?currentPage=15
可我只想取到?之前的内容,就是想得到:http://localhost:6000/Pagination.aspx
应该怎么做呢,是要用到正则吗,请教大家,最好写上语句,只写大概说明我怕弄不懂哦

解决方案 »

  1.   

    Request.QueryString["currentPage"] 就可以取到15了
      

  2.   

    断点 quickwatch 然后一点点的往里面找,就能找到了。不行就自己分割出来。
      

  3.   

            Response.Write(Request.Path);//
      

  4.   

            string url = Request.Url.AbsoluteUri;
            string oldValue = "?currentPage=";
            if (Request["currentPage"] != null && Request["currentPage"] != "")
            {
                oldValue += Request["currentPage"].ToString().Trim();
            }        
            url.Replace(oldValue, "");
    我是楼主,我用上面的方法试了,单步调试,最后一步之前,oldValue的值已经等于?currentPage=15了,但执行完最后一句,
    url的值还是http://localhost:6000/Pagination.aspx?currentPage=15 
    就好像Replace方法没起作用,为啥呢
      

  5.   

    我是楼主,我知道了,是string oldValue = "?currentPage="; 少写了个@,
    该写成string oldValue = @"?currentPage=";
    最后一个问题了,@"?currentPage="里是哪个字符得用@搞一下呢,说了给分
      

  6.   

    应该是“?”吧··string url = Request.Url.AbsoluteUri.split('?')[0]
    这就 ok 啦
      

  7.   

    这么简单个问题,既然一下在找不到系统函数,自己写一个也很容易的吗!Response.Write("http://"+Request.Url.Authority+Request.Url.AbsolutePath);
      

  8.   

                string url = @"http://localhost:6000/Pagination.aspx?currentPage=15";
                string oldValue = @"?currentPage=15";
                url.Replace(oldValue, "");
    我是楼主,又不对了,用上面这个也替换不了,还是等高手吧,晕了
      

  9.   

    感谢wukai555 ,方法很管用,结贴,
    替换的问题不管了,
      

  10.   


                string url = @"http://localhost:6000/Pagination.aspx?currentPage=15";            url = s.Substring(0, s.LastIndexOf('?'));
      

  11.   

    写错了 改下
                string url = @"http://localhost:6000/Pagination.aspx?currentPage=15";            url = url.Substring(0, s.LastIndexOf('?'));
      

  12.   

    请参考
    http://hi.baidu.com/singsue/blog/item/7a7507176d54ee044b90a702.html
    这么简单,搜索就有了嘛