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

  • 相关阅读:
    sql 查询某个字段出现的次数
    Spark性能优化指导及总结
    数据结构与算法基础-排序
    数据仓库中数据模型之拉链表
    Hive over()窗口函数及应用实例
    dubbo 分布式服务框架
    netty 网络框架
    实现JavaScript继承
    【ThoughtWorks西安】澳洲业务线招聘大量C#开发工程师
    使用Docker搭建自己的GitLab服务
  • 原文地址:https://www.cnblogs.com/ZGQ-VIP/p/12750062.html
Copyright © 2011-2022 走看看