【说明】如果你已经熟悉了,请不必往下看,如果你还不熟悉,请做下参考,因为经常在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>
分享到:
相关推荐
asp.net 中重写url
ASP.NET中重写URL 共4种方法,大家可以参考
在 ASP.NET 中执行 URL 重写.pdf 介绍如何使用Microsoft ASP.NET执行动态URL重写。
asp.net页面通过URL参数传值中文乱码问题解决办法
ASP.NET-(URL编码解码)开发人员工具ASP.NET-(URL编码解码)开发人员工具ASP.NET-(URL编码解码)开发人员工具ASP.NET-(URL编码解码)开发人员工具ASP.NET-(URL编码解码)开发人员工具ASP.NET-(URL编码解码)开发人员工具
asp.net中URL参数传值中文乱码的三种解决办法
Asp.Net的URLReWrite的源代码含详细具体的配置方法,在info.doc里。
ASP.NET MVC URL重写与优化
ASP.NET中的URL重定向方法。使用的是微软DLL提供的dll,在web.confif中简单配置就OK了。安装后有示例查看。
ASP.NET 中执行 URL 重写实例教程
asp.net2.0的URL重写例子 以及伪静态,具体请看这里: http://yangmingsheng.cn/?/_articleshow/117.html
为了有助于描述如何在 ASP.NET Web 应用程序中实现 URL 重写,我创建了 URL 重写引擎。此重写引擎将提供以下功能: 使用 URL 重写引擎的 ASP.NET 页面开发人员可以在 Web.config 文件中指定重写规则。 重写规则...
asp.net c# Url重写和无扩展名Url重写 内有所有源码 注:无扩展名Url重写,必须是虚拟目录的相对路径
asp.net 2.0 URL 映射 实例 asp.net 2.0 URL 映射 实例
通过webrequest, webclient两种方式请求url获取对应的返回值
分析如何使用微软提供的ASP.NET来对动态产生的URL地址进行网址重写。 网址重写是实现一种截取网址请求并将其进行处理后重新指向到一个指定的网址的过程。作者本人在对各种实现网址重写的技术进行研究和探讨后得出的...
asp.net web URL 伪装或加密 能保护 URL 地址!
asp.net url重写 demo 框架 3.5 利用Intelligencia.UrlRewriter.dll组件实现url重写
URL映射是ASP.NET 2.0中提供的新特性。URL映射技术帮助我们将一个特定URL映射为另一个URL。为了帮助理解,我们假设你在站点有一个叫Homepage.aspx的页面来访问主页,所有的用户也都用这个页面来访问你的主页。但由于...
asp+asp.net1.1 URL重写后出现的问题