学习志(一):Request直观学习属性(更新)
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Web" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString["do"]))
{
GetValue();
}
}
protected void GetValue()
{
this.Panel1.Visible = true;
this.ApplicationPath.Text = Request.ApplicationPath;
this.AppRelativeCurrentExecutionFilePath.Text = Request.AppRelativeCurrentExecutionFilePath;
this.CurrentExecutionFilePath.Text = Request.CurrentExecutionFilePath;
this.FilePath.Text = Request.FilePath;
this.IsLocal.Text = Request.IsLocal.ToString();
this.Path.Text = Request.Path;
this.PathInfo.Text = Request.PathInfo;
this.PhysicalApplicationPath.Text = Request.PhysicalApplicationPath;
this.PhysicalPath.Text = Request.PhysicalPath;
this.RawUrl.Text = Request.RawUrl;
this.UserHostAddress.Text = Request.UserHostAddress;
this.UserHostName.Text = Request.UserHostName;
this.UrlAbsolutePath.Text = Request.Url.AbsolutePath;
this.UrlAbsoluteUri.Text = Request.Url.AbsoluteUri;
this.UrlAuthority.Text = Request.Url.Authority;
this.UrlDnsSafeHost.Text = Request.Url.DnsSafeHost;
this.UrlFragment.Text = Request.Url.Fragment;
this.UrlHost.Text = Request.Url.Host;
this.UrlHostNameType.Text = Request.Url.HostNameType.ToString();
this.UrlIsAbsoluteUri.Text = Request.Url.IsAbsoluteUri.ToString();
this.UrlIsDefaultPort.Text = Request.Url.IsDefaultPort.ToString();
this.UrlIsFile.Text = Request.Url.IsFile.ToString();
this.UrlIsLoopback.Text = Request.Url.IsLoopback.ToString();
this.UrlLocalPath.Text = Request.Url.LocalPath;
this.UrlOriginalString.Text = Request.Url.OriginalString;
this.UrlPathAndQuery.Text = Request.Url.PathAndQuery;
this.UrlPort.Text = Request.Url.Port.ToString();
this.UrlQuery.Text = Request.Url.Query;
this.UrlScheme.Text = Request.Url.Scheme;
this.UrlUserInfo.Text = Request.Url.UserInfo;
if (Request.UrlReferrer != null)
{
this.UrlReferrer.Text = Request.UrlReferrer.ToString();
}
}
protected void btnExport_Click(object sender, EventArgs e)
{
Response.Redirect("RequestTest.aspx?do=show");
}
protected void btnBack_Click(object sender, EventArgs e)
{
Response.Redirect("RequestTest.aspx");
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Request</title>
<style type="text/css">
body{margin:0;padding:0;font:14px Verdana, Arial, sans-serif;line-height:200%;}
#content{padding-left:50px;padding-right:50px;}
#content h2{font-size:18px;color:#1E9300;padding-top:8px;margin-bottom:8px;}
#content h3{margin-top:8px;margin-bottom:8px;FONT:bold 14px 宋体,tahoma,arial,sans-serif;COLOR:#0033CC;}
#content div{margin-top:10px;margin-bottom:30px;border:#E9C94D solid 1px;background:#FFFFD1;padding:10px;}
#content input{margin-bottom:5px;height:22px;font:12px Tahoma;border:1px solid #808080;}
#content span{color:#f00;font-weight:bold;}
.content{padding:20px;text-align:center;}
.content h3{font-size:26px;font-weight:bold;}
ul, ol{color:#000000;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="content">
<h3>Request类常用方法</h3>
</div>
<div class="content" style="text-align:center;">
<asp:Button ID="btnExport" runat="server" Text="跳转URL开始输出Request"
onclick="btnExport_Click" />
<asp:Button ID="btnBack" runat="server" onclick="btnBack_Click" Text="返回"
Width="76px" />
</div>
<asp:Panel ID="Panel1" runat="server" Visible="false">
<div id="content">
<h3>Request.ApplicationPath</h3>
<div>
<span>返回:</span><asp:Literal ID="ApplicationPath" runat="server"></asp:Literal><br />
<span>说明:</span>获取服务器上asp.net应用程序虚拟应用程序根路径
</div>
<h3>Request.AppRelativeCurrentExecutionFilePath</h3>
<div>
<span>返回:</span><asp:Literal ID="AppRelativeCurrentExecutionFilePath" runat="server"></asp:Literal><br />
<span>说明:</span>获取应用程序根的虚拟路径,并通过对应用程序根使用波形符 (~) 表示法(例如,以“~/page.aspx”的形式)使该路径成为相对路径。
</div>
<h3>Request.CurrentExecutionFilePath</h3>
<div>
<span>返回:</span><asp:Literal ID="CurrentExecutionFilePath" runat="server"></asp:Literal><br />
<span>说明:</span>获取当前请求的虚拟路径。
</div>
<h3>Request.FilePath</h3>
<div>
<span>返回:</span><asp:Literal ID="FilePath" runat="server"></asp:Literal><br />
<span>说明:</span>获取当前请求的虚拟路径。
</div>
<h3>Request.IsLocal</h3>
<div>
<span>返回:</span><asp:Literal ID="IsLocal" runat="server"></asp:Literal><br />
<span>说明:</span>获取一个值,该值表示该请求是否来自本地计算机
</div>
<h3>Request.Path</h3>
<div>
<span>返回:</span><asp:Literal ID="Path" runat="server"></asp:Literal><br />
<span>说明:</span>获取当前请求的虚拟路径。
</div>
<h3>Request.PathInfo</h3>
<div>
<span>返回:</span><asp:Literal ID="PathInfo" runat="server"></asp:Literal><br />
<span>说明:</span>获取具有 URL 扩展名的资源的附加路径信息
</div>
<h3>Request.PhysicalApplicationPath</h3>
<div>
<span>返回:</span><asp:Literal ID="PhysicalApplicationPath" runat="server"></asp:Literal><br />
<span>说明:</span>获取当前正在执行的服务器应用程序的根目录的物理文件系统路径。
</div>
<h3>Request.PhysicalPath</h3>
<div>
<span>返回:</span><asp:Literal ID="PhysicalPath" runat="server"></asp:Literal><br />
<span>说明:</span>获取与请求的 URL 相对应的物理文件系统路径。
</div>
<h3>Request.RawUrl</h3>
<div>
<span>返回:</span><asp:Literal ID="RawUrl" runat="server"></asp:Literal><br />
<span>说明:</span>获取当前请求的原始 URL。
</div>
<h3>Request.UserHostAddress</h3>
<div>
<span>返回:</span><asp:Literal ID="UserHostAddress" runat="server"></asp:Literal><br />
<span>说明:</span>获取远程客户端的 IP 主机地址。
</div>
<h3>Request.UserHostName</h3>
<div>
<span>返回:</span><asp:Literal ID="UserHostName" runat="server"></asp:Literal><br />
<span>说明:</span>获取远程客户端的 DNS 名称。
</div>
<h3>Request.Url.AbsolutePath</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlAbsolutePath" runat="server"></asp:Literal><br />
<span>说明:</span>获取URI的绝对路径
</div>
<h3>Request.Url.AbsoluteUri</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlAbsoluteUri" runat="server"></asp:Literal><br />
<span>说明:</span>获取绝对URI
</div>
<h3>Request.Url.Authority</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlAuthority" runat="server"></asp:Literal><br />
<span>说明:</span>获取服务器的域名系统(DNS)主机名或IP地址和端口号
</div>
<h3>Request.Url.DnsSafeHost</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlDnsSafeHost" runat="server"></asp:Literal><br />
<span>说明:</span>获得可安全用于DNS解析的未转义主机名
</div>
<h3>Request.Url.Fragment</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlFragment" runat="server"></asp:Literal><br />
<span>说明:</span>获取转义URI片段
</div>
<h3>Request.Url.Host</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlHost" runat="server"></asp:Literal><br />
<span>说明:</span>获取此实例的主机部分
</div>
<h3>Request.Url.HostNameType</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlHostNameType" runat="server"></asp:Literal><br />
<span>说明:</span>获取URL中指定的主机名的类型
</div>
<h3>Request.Url.IsAbsoluteUri</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlIsAbsoluteUri" runat="server"></asp:Literal><br />
<span>说明:</span>获取一个值,该值指示指定的System.Uri实例是否为绝对uri
</div>
<h3>Request.Url.IsDefaultPort</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlIsDefaultPort" runat="server"></asp:Literal><br />
<span>说明:</span>获取一个值,该值指示URI的端口值是否为此方案的默认值
</div>
<h3>Request.Url.IsFile</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlIsFile" runat="server"></asp:Literal><br />
<span>说明:</span>获取一个值,该值指示指定的System.Uri是否为文件URI
</div>
<h3>Request.Url.IsLoopback</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlIsLoopback" runat="server"></asp:Literal><br />
<span>说明:</span>获取一个值,该值指示指定的System.Uri是否引用了本地主机
</div>
<h3>Request.Url.LocalPath</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlLocalPath" runat="server"></asp:Literal><br />
<span>说明:</span>获取文件名的本地操作系统表示形式
</div>
<h3>Request.Url.OriginalString</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlOriginalString" runat="server"></asp:Literal><br />
<span>说明:</span>获取传递给System.Uri构造函数的原始URI字符串
</div>
<h3>Request.Url.PathAndQuery</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlPathAndQuery" runat="server"></asp:Literal><br />
<span>说明:</span>获取用问号(“?”)分割的Request.Url.AbsolutePath和Request.Url.Query的属性
</div>
<h3>Request.Url.Port</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlPort" runat="server"></asp:Literal><br />
<span>说明:</span>获取此URL的端口号
</div>
<h3>Request.Url.Query</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlQuery" runat="server"></asp:Literal><br />
<span>说明:</span>获取此URL中包括的任何查询信息
</div>
<h3>Request.Url.Scheme</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlScheme" runat="server"></asp:Literal><br />
<span>说明:</span>获取此URL方案的名称
</div>
<h3>Request.Url.UserInfo</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlUserInfo" runat="server"></asp:Literal><br />
<span>说明:</span>获取用户名、密码或者其他与指定URL关联的特定与用户的信息
</div>
<h3>Request.UrlReferrer</h3>
<div>
<span>返回:</span><asp:Literal ID="UrlReferrer" runat="server"></asp:Literal><br />
<span>说明:</span>获取有关客户端上次请求的 URL 的信息,该请求链接到当前的 URL。
</div>
</div>
</asp:Panel>
</form>
</body>
</html>
运行结果:http://bbs.chinawts.com/common/RequestTest.aspx?do=show