`
380071587
  • 浏览: 453998 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

asp.net中有关URL的信息

 
阅读更多
【说明】如果你已经熟悉了,请不必往下看,如果你还不熟悉,请做下参考,因为经常在asp.net中需要获取有关URL相关方面的信息,虽然msdn上列出了各种方法,无奈方法和属性太多,没办法一一记住,就做了个例子,将与路径和文件信息相关的参数通过一个方法列出来,以备平时查阅。
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;

publicpartialclassAjaxDemo:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
Response.Write(
"Request.AppRelativeCurrentExecutionFilePath="+Request.AppRelativeCurrentExecutionFilePath+"<br>");
Response.Write(
"Request.CurrentExecutionFilePath="+Request.CurrentExecutionFilePath+"<br>");
Response.Write(
"Request.FilePath="+Request.FilePath+"<br>");
Response.Write(
"Request.Path="+Request.Path+"<br>");
Response.Write(
"Request.PathInfo="+Request.PathInfo+"<br>");
Response.Write(
"Request.PhysicalApplicationPath="+Request.PhysicalApplicationPath+"<br>");
Response.Write(
"Request.PhysicalPath="+Request.PhysicalPath+"<br>");
Response.Write(
"Request.RawUrl="+Request.RawUrl+"<br>");
Response.Write(
"Request.Url="+Request.Url+"<br>");
Response.Write(
"Request.UrlReferrer="+Request.UrlReferrer+"<br>");
Response.Write(
"Request.UserHostAddress="+Request.UserHostAddress+"<br>");
Response.Write(
"Request.UserHostName="+Request.UserHostName+"<br>");

Uriuri
=Request.Url;
Response.Write(
"uri.AbsolutePath="+uri.AbsolutePath+"<br>");
Response.Write(
"uri.AbsoluteUri="+uri.AbsoluteUri+"<br>");
Response.Write(
"uri.Authority="+uri.Authority+"<br>");
Response.Write(
"uri.Host="+uri.Host+"<br>");
Response.Write(
"uri.HostNameType="+uri.HostNameType+"<br>");
Response.Write(
"uri.Scheme="+uri.Scheme+"<br>");
Response.Write(
"uri.LocalPath="+uri.LocalPath+"<br>");
Response.Write(
"uri.OriginalString="+uri.OriginalString+"<br>");
Response.Write(
"uri.PathAndQuery="+uri.PathAndQuery+"<br>");
Response.Write(
"uri.Port="+uri.Port+"<br>");
Response.Write("uri.Segments=");
foreach (string str in uri.Segments)
{
Response.Write( str+ ",");
}
}
}
前台没有任何控件,网页路径是:http://localhost:4336/Web/AjaxDemo.aspx,最后输出的结果:
Request.AppRelativeCurrentExecutionFilePath=~/AjaxDemo.aspx
Request.CurrentExecutionFilePath=/Web/AjaxDemo.aspx
Request.FilePath=/Web/AjaxDemo.aspx
Request.Path=/Web/AjaxDemo.aspx
Request.PathInfo=
Request.PhysicalApplicationPath=D:/SXJST/Web/
Request.PhysicalPath=D:/SXJST/Web/AjaxDemo.aspx
Request.RawUrl=/Web/AjaxDemo.aspx
Request.Url=http://localhost:4336/Web/AjaxDemo.aspx
Request.UrlReferrer=
Request.UserHostAddress=127.0.0.1
Request.UserHostName=127.0.0.1
uri.AbsolutePath=/Web/AjaxDemo.aspx
uri.AbsoluteUri=http://localhost:4336/Web/AjaxDemo.aspx
uri.Authority=localhost:4336
uri.Host=localhost
uri.HostNameType=Dns
uri.Scheme=http
uri.LocalPath=/Web/AjaxDemo.aspx
uri.OriginalString=http://localhost:4336/Web/AjaxDemo.aspx
uri.PathAndQuery=/Web/AjaxDemo.aspx
uri.Port=4336
uri.Segments=/,Web/,AjaxDemo.aspx, <style type="text/css"> body { font-family: Tahoma; } div.AlertStyle { background-color: #FFC080; top: 95%; left: 1%; height: 20px; position: absolute; visibility: hidden; }</style>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics