zoukankan      html  css  js  c++  java
  • ASP.NET中Request.RawUrl、Request.Url的区别Path.GetFileName、Path.GetExtension、Path.GetDirectoryName

    如果访问的地址是:

    http://hovertree.com/guestbook/addmessage.aspx?key=hovertree%3C&n=myslider#zonemenu

    那么

    Request.Url.ToString() 的值是:
    http://hovertree.com/guestbook/addmessage.aspx?key=hovertree<&n=myslider 

    Request.RawUrl.ToString() 的值是:
    /guestbook/addmessage.aspx?key=hovertree%3C&n=myslider

    我们可以看出

    Request.RawUrl 不包含主机名及前面的内容。

    Request.RawUrl 完整地体现地址栏的 QueryString,

    而 Request.Url 会进行 Server.URLDecode 解析。

    而且两个的相同地方是,都不包含#以及后面的字符串

    Path.GetFileName

    string s1 = Path.GetFileName("D:\dir\asp.net\readme.txt"); // readme.text
    string s2 = Path.GetFileName("D:\dir\asp.net\readme."); // readme.
    string s3 = Path.GetFileName("D:\dir\asp.net\readme"); // readme
    string s4 = Path.GetFileName("D:\dir\asp.net\readme\"); // 零长度字符串
    string s5 = Path.GetFileName("D:\"); // 零长度字符串
    string s6 = Path.GetFileName("D:"); // 零长度字符串

    说明:路径中的  和 / 是一样的结果。

    只要不是以 或 / 结束,都是当作文件对待(盘符除外)。

    Path.GetExtension

    string s1 = Path.GetExtension("D:\dir\asp.net\readme.txt"); // .txt
    string s2 = Path.GetExtension("D:\dir\asp.net\readme."); // 零长度字符串
    string s3 = Path.GetExtension("D:\dir\asp.net\readme"); // 零长度字符串
    string s4 = Path.GetExtension("D:\dir\asp.net\readme\"); // 零长度字符串
    string s5 = Path.GetExtension("D:\"); // 零长度字符串
    string s6 = Path.GetExtension("D:"); // 零长度字符串

    Path.GetDirectoryName

    string s1 = Path.GetDirectoryName("D:\dir\asp.net/readme.txt"); // D:dirasp.net
    string s2 = Path.GetDirectoryName("D:\dir\asp.net/readme."); // D:dirasp.net
    string s3 = Path.GetDirectoryName("D:\dir\asp.net/readme"); // D:dirasp.net
    string s4 = Path.GetDirectoryName("D:\dir\asp.net/readme/"); // D:dirasp.net eadme
    string s5 = Path.GetDirectoryName("D:\"); // null,注意是 null
    string s6 = Path.GetDirectoryName("D:"); // null,注意是 null

    这里,我们故意在路径中使用“/”,可以发现最终还是会转换成“”。

     查看留言:http://hovertree.com/guestbook/

    转自:http://keleyi.com/a/bjae/avh3bdvq.htm

    技术文章:http://www.cnblogs.com/sosoft/p/kaifajishu.html

  • 相关阅读:
    软件架构感悟.
    浏览器缓存技术
    as到底干嘛了???
    关于WebForm开发问题(给新手的建议)
    疑难问题ASP.NET
    破解hash算法.高手请进,求解.
    (MVC和JVPL模式)Moon.Web架构谈
    Moon.NET框架架构及介绍
    调用API设置安卓手机的Access Point
    gtShell 为你常用的目录建立标签并快速跳转
  • 原文地址:https://www.cnblogs.com/ZGQ-VIP/p/12750062.html
Copyright © 2011-2022 走看看