zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    URL传参到servlet含特殊字符——#号无法传递
    textarea标签中间出现空格问题
    MySQL学习笔记(23)——自定义函数
    修改日期插件问题
    获取Spring的ApplicationContext的方法
    数据库用户被锁
    ava获得当前文件路径
    前端框架
    LeetCode 485. 最大连续1的个数
    LeetCode 283. 移动零
  • 原文地址:https://www.cnblogs.com/volnet/p/1512761.html
Copyright © 2011-2022 走看看