• About Request.Url


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Text;
    
    namespace WebAppRequestUrl
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                WriteLine<string>("Request.Url.AbsolutePath", Request.Url.AbsolutePath);
                WriteLine<string>("Request.Url.AbsolutePath.Split('/')[1]", Request.Url.AbsolutePath.Split('/')[1]);
    
                WriteLine<string>("Request.Url.AbsoluteUri", Request.Url.AbsoluteUri);
                WriteLine<string>("Request.Url.Authority", Request.Url.Authority);
                WriteLine<string>("Request.Url.DnsSafeHost", Request.Url.DnsSafeHost);
                WriteLine<string>("Request.Url.Fragment", Request.Url.Fragment);
                WriteLine<string>("Request.Url.Host", Request.Url.Host);
                WriteLine<UriHostNameType>("Request.Url.HostNameType", 
                    Request.Url.HostNameType, 
                    o => o.ToString());
                WriteLine<bool>("Request.Url.IsAbsoluteUri", Request.Url.IsAbsoluteUri);
                WriteLine<bool>("Request.Url.IsDefaultPort", Request.Url.IsDefaultPort);
                WriteLine<bool>("Request.Url.IsFile", Request.Url.IsFile);
                WriteLine<bool>("Request.Url.IsLoopback", Request.Url.IsLoopback);
                WriteLine<bool>("Request.Url.IsUnc", Request.Url.IsUnc);
                WriteLine<string>("Request.Url.LocalPath", Request.Url.LocalPath);
                WriteLine<string>("Request.Url.OriginalString", Request.Url.OriginalString);
                WriteLine<string>("Request.Url.PathAndQuery", Request.Url.PathAndQuery);
                WriteLine<int>("Request.Url.Port", Request.Url.Port);
                WriteLine<string>("Request.Url.Query", Request.Url.Query);
                WriteLine<string>("Request.Url.Scheme", Request.Url.Scheme);
                WriteLine<string[]>("Request.Url.Segments", Request.Url.Segments, o =>
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < o.Length; ++i)
                    {
                        sb.AppendFormat("<span style=\"color:blue;\">{0}</span>    :{1}<br />", i, o[i]);
                    }
                    return sb.ToString();
                });
                WriteLine<bool>("Request.Url.UserEscaped", Request.Url.UserEscaped, o => (o == true ? "true" : "false"));
                WriteLine<string>("Request.Url.UserInfo", Request.Url.UserInfo);
            }
    
            private void WriteLine<T>(string name, T output)
            {
                WriteLine<T>(name, output, o => o.ToString());
            }
    
            private void WriteLine<T>(string name, T output, Func<T, string> toString)
            {
                if (currentRow++ % 2 == 0)
                {
                    Output("<div style=\"border:1px solid; background-color:#cccccc; padding:10px; font-family:Arial;\">");
                }
                else
                {
                    Output("<div style=\"border:1px solid; background-color:#eeeeee; padding:10px; font-family:Arial;\">");
                }
                Output("<b style=\"color:blue;\">" + name + "</b>     " + output.GetType().FullName + "<br />               ");
                Output("<span style=\"font-family:consolas;\">" + toString(output) + "</span>");
                Output("</div><br />");
            }
    
            private void Output(string s)
            {
                this.form1.InnerHtml += s;
                this.form1.InnerHtml += "\n";
            }
    
            private int currentRow;
        }
    }
    

    下面是输出:

    image

    Request.Url.AbsolutePath System.String
    /Default.aspx

    Request.Url.AbsolutePath.Split('/')[1] System.String
    Default.aspx

    Request.Url.AbsoluteUri System.String
    http://localhost:17698/Default.aspx?myQuery=volnet

    Request.Url.Authority System.String
    localhost:17698

    Request.Url.DnsSafeHost System.String
    localhost

    Request.Url.Fragment System.String

    Request.Url.Host System.String
    localhost

    Request.Url.HostNameType System.UriHostNameType
    Dns

    Request.Url.IsAbsoluteUri System.Boolean
    True

    Request.Url.IsDefaultPort System.Boolean
    False

    Request.Url.IsFile System.Boolean
    False

    Request.Url.IsLoopback System.Boolean
    True

    Request.Url.IsUnc System.Boolean
    False

    Request.Url.LocalPath System.String
    /Default.aspx

    Request.Url.OriginalString System.String
    http://localhost:17698/Default.aspx?myQuery=volnet

    Request.Url.PathAndQuery System.String
    /Default.aspx?myQuery=volnet

    Request.Url.Port System.Int32
    17698

    Request.Url.Query System.String
    ?myQuery=volnet

    Request.Url.Scheme System.String
    http

    Request.Url.Segments System.String[]
    0 :/
    1 :Default.aspx

    Request.Url.UserEscaped System.Boolean
    false

    Request.Url.UserInfo System.String
  • 相关阅读:
    Winpcap网络开发库入门
    主机字节序与网络字节序的转换
    WORD与DWORD
    TCP/IP各种数据包结构体
    解析IPV4报文 和IPV6 报文的 checksum
    TCP头校验和计算算法详解
    第九次作业:DFA最小化,语法分析初步
    第八次作业:非确定的自动机NFA确定化为DFA
    第七次:正规式、正规文法与自动机
    第六次作业:正规文法与正规式
  • 原文地址:https://www.cnblogs.com/volnet/p/1512761.html
Copyright © 2020-2023  润新知