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;
}
}
下面是输出:
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
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/volnet/archive/2009/06/28/4680667.aspx