Request获取url各种信息的方法
1、Request获取url各种信息的方法
测试的url地址:http://www.test.com/testweb/default.aspx, 结果如下:
Request.ApplicationPath: /testweb
Request.CurrentExecutionFilePath: /testweb/default.aspx
Request.FilePath: /testweb/default.aspx
Request.Path: /testweb/default.aspx
Request.PathInfo:
Request.PhysicalApplicationPath: E:\WWW\testweb\
Request.PhysicalPath: E:\WWW\testweb\default.aspx
Request.RawUrl: /testweb/default.aspx
Request.Url.AbsolutePath: /testweb/default.aspx
Request.Url.AbsoluteUri: http://www.test.com/testweb/default.aspx
Request.Url.Host: www.test.com
Request.Url.LocalPath: /testweb/default.aspx
2、Request.UrlReferrer的使用
Request.UrlReferrer可以获取客户端上次请求的url的有关信息,这样我们就可以通过这个属性返回到“上一页”。
示例如下:
1. 首先在Page_load中获得并储存该信息
Page_load(object obj,EventArgs e)
{
if(!IsPostBack)
{
if(Request.UrlReferrer!=null)
{
ViewState["UrlReferrer"]=Request.UrlReferrer.ToString();
}
}
}
l 页面回发后会改变Request.UrlReferrer,将其指向当前页面,所以需要进行判断:只有在第一次请求页面的时候才储存该信息;
l 因为可能“上一次”的url不存在,所以需要进行判断,只有在Request.UrlReferrer存在的情况下才进行储存;
2. 然后在返回函数中使用该信息
void Return()
{
if(ViewState["UrlReferrer"]!=null)
Response.Redirect(ViewState["UrlReferrer"].ToString();
}
在使用Request.UrlReferrer时还要注意:
(1) 如果上一页面使用document.location方法导航到当前页面,Request.UrlReferrer返回空值;
(2) 如果有A,B两个页面,在浏览器中直接请求A页面,在A页面的中Page_Load事件中导航到B 页面,则 Request.UrlReferrer返回空。因为 在Page_load事件中页面还未初始化,所以无法记录当前页的信息,导航到b页面也就无法获得上一页面的信息;
(3) 点击刷新按钮不会改变Request.UrlReferrer;
Request获取url各种信息的方法的更多相关文章
- PHP获取http头信息和CI中获取HTTP头信息的方法
CI中获取HTTP头信息的方法: $this->input->request_headers() 在不支持apache_request_headers()的非Apache环境非常有用.返回 ...
- 获取url查询参数的方法
/** * 获取url查询参数的方法 * @param name * @returns {null} * @constructor */ function GetQueryString(name) { ...
- vue不通过路由直接获取url中参数的方法示例
vue不通过路由直接获取url中参数的方法示例 vuejs取得URL中参数的值地址:http://localhost:3333/#/index?id=128console.log(this.$rout ...
- jsp Request获取url信息的各种方法比较
从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 String p ...
- js ajax设置和获取自定义header信息的方法总结
目录 1.js ajax 设置自定义header 1.1 方法一: 1.2 方法二: 2.js ajax 获取请求返回的response的header信息 3.js ajax 跨域请求的情况下获取自定 ...
- 获取URL网页信息
static string GetHtml(string url) {string strHTML = ""; WebClient myWebClient = new WebCli ...
- C#获取Url不同路径的方法大全
在 C# 中,用 Request 对象来获取 Url 的各种路径,包括上一页 Url.域名.绝对路径.相对路径和物理路径.虽然在某些情况下,无法获取到 Url,但可以获取到大部分情况下的 Url,下 ...
- JS获取Url参数的通用方法
//获取URL中的参数 function request(paras) { var url = location.href.replace('#', ''); var paraString = url ...
- Request 获取Url
1.获取页面,HttpContext.Current.Request也是Request //获取当前页面url string myurl = HttpContext.Current.Request.U ...
随机推荐
- URI和URL
URI(uniform resource identifier),统一资源标识符,用来唯一的标识一个资源. URL(uniform resource locator),统一资源定位器,它是一种具体的U ...
- poj1159 dp(滚动数组优化)
H - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:3000MS Memory Limit:65536KB ...
- [UVA] 11995 - I Can Guess the Data Structure! [STL应用]
11995 - I Can Guess the Data Structure! Time limit: 1.000 seconds Problem I I Can Guess the Data Str ...
- 使用 JUnit 进行单元测试 - 教程
tanyuanji@126.com 版本历史 JUnit 该教程主要讲解 JUnit 4.x 版本的使用,以及如何在Eclipse IDE 中如何使用JUnit 目录 tanyuanji@126. ...
- yii CMenu的配置(导航栏)
给主键的li 和a标签添加元素$this->myMenu = array( 'id'=>'myMenu', 'items'=>array( array( 'label'=>'H ...
- shell操作mysql
参考: http://blog.csdn.net/hbcui1984/article/details/5125387
- android WebView, WebChromeClient和WebViewClient加载网页基本用法
WebView, WebChromeClient和WebViewClient加载网页基本用法 webview是android中的浏览器控件,在一些手机应用中常会用到b/s模式去开发应用,这时webvi ...
- codility上的问题 (21) Upsilon 2012
这是我目前最喜欢的codiltiy上的问题之一.问题描述是:给定一个整数数组A,所有的数均不相同.假设下标从0开始,找到一个数组B, 满足A[B[0]] > A[B[1]] > A[B[2 ...
- Eclipse + CDT + YAGARTO + J-Link,STM32开源开发环境搭建与调试
Eclipse+CDT+YAGARTO+J-Li:开源开发环境搭建与调试:作者:Chongqing:邮箱:ycq.no1@163.com:文档版本:V1.0:发布日期:2014-08-04:前言:此文 ...
- 数据结构之顺序表,c#实现
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using S ...