易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET 如何取得 Request URL 的各個部分?


我們在開發網頁應用程式,時常需要去解析網址(Request.Url)的每個片段,進行一些判斷。例如說 "http://localhost:1897/News/Press/Content.aspx/123?id=1#toc
",我們想要取得網址裡第一層目錄的名字(News)用以判斷不同的頁面標題(Page Title)。
我看很多人都用字串的 IndexOf 方法與 Substring 方法:
Request.Url.PathAndQuery.Substring(1, Request.Url.PathAndQuery.IndexOf("/", 1)-1)
這實在太埋沒 .NET 的強大設計了,事實上在 Request 物件就已經提供很多方便的屬性(Property)可供取得網址的片段。
底下這張表就是各種跟 Browser Request 的網址相關的屬性與用法:
網址:http://localhost:1897/News/Press/Content.aspx/123?id=1#toc
Request.ApplicationPath
/
Request.PhysicalPath
D:\Projects\Solution\web\News\Press\Content.aspx
System.IO.Path.GetDirectoryName(Request.PhysicalPath)
D:\Projects\Solution\web\News\Press
Request.PhysicalApplicationPath
D:\Projects\Solution\web\
System.IO.Path.GetFileName(Request.PhysicalPath)
Content.aspx
Request.CurrentExecutionFilePath
/News/Press/Content.aspx
Request.FilePath
/News/Press/Content.aspx
Request.Path
/News/Press/Content.aspx/123
Request.RawUrl
/News/Press/Content.aspx/123?id=1
Request.Url.AbsolutePath
/News/Press/Content.aspx/123
Request.Url.AbsoluteUri
http://localhost:1897/News/Press/Content.aspx/123?id=1
Request.Url.Scheme
http
Request.Url.Host
localhost
Request.Url.Port
1897
Request.Url.Authority
localhost:1897
Request.Url.LocalPath
/News/Press/Content.aspx/123
Request.PathInfo
/123
Request.Url.PathAndQuery
/News/Press/Content.aspx/123?id=1
Request.Url.Query
?id=1
Request.Url.Fragment
 
Request.Url.Segments
/
News/
Press/
Content.aspx/
123

所以當你看了這張表之後,你還會想用 Request.Url.PathAn


相关文档:

asp.net发布网站时三个选项的问题


asp.net发布网站时三个选项的问题
 
发布网站的时候有三个选项: 
第一个选项指定发布后是不是可以修改aspx文件,如果勾选,则发布后的网站行为基本与ASP.NET   1.1一致,只要没有增删修改控件,可以直接在服务器上修改aspx文件不用重新发布网站。 
第二个选项指定是不是将每个aspx文件都编 ......

VFP如何调用ASP.NET Web服务中的DataSet

一、ASP.NET Web Service代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
 
namespace WebService1
{
    /// <sum ......

ASP.Net + SQL Server 存储过程实现分页排序

问题提出:
在应用程序中经常需要查询数据。当查询结果数据量比较大的时候,检索结果、界面显示都需要花费大量的时间。为了避免这个问题,应该每次只检索部分数据,也就是使用常见的分页方式来处理。分页的问题在asp.net中好像非常简单,只要在GridView中启用分页就可以了。启用分页后,GridView关联数据源控件,依旧会加载 ......

处理asp.net的回车事件

1.添加js函数
function TextBoxEntered(buttton) {
if (event.which || event.keyCode) {
if ((event.which == 13) || (event.keyCode == 13)) {
document.getElementById(button).click();
return false;
}
......

输出PDF文档到ASP.NET页面


protected
void Page_Load(object sender, EventArgs e)
{
         try
        {
             //query the pdf path
       & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号