当前位置:编程学习 > asp >>

asp.net中有关URL的信息

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

using System; 
using System.Data; 
using System.Configuration; 
using System.Collections; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
 
public partial class AjaxDemo : System.Web.UI.Page 

    protected void Page_Load(object sender, EventArgs e) 
    { 
        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>"); 
 
        Uri uri = 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 www.zzzyk.com
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,


摘自 在希望的田野上
补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,