asp.net Request获取url信息的各种方法比较

本页地址: Request.URL;
上页地址:


代码如下:

Request.UrlReferrer
Request.ServerViables["http_referer"]
Request.RawUrl
Request.RawUrl.QueryAndPath
System.IO.Path.GetFileName(Request.FilePath.ToString())

在ASP.NET编程中经常需要用Request获取url的有关信息,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

当url中带参数时可以使用:
HttpContext.Current.Request.Url.PathAndQuery.ToString()

(0)

相关推荐

  • jsp获取url路径的方法分析

    本文实例讲述了jsp获取url路径的方法.分享给大家供大家参考,具体如下: 如果你请求的URL是  http://localhost:8080/demo/Index.jsp request.getScheme() //输出:http request.getServerName() //输出: localhost request.getServerPort() //输出: 8080 request.getContextPath() //输出: /demo request.getRequestPat

  • 在jsp页面如何获得url参数

    当一个url过来时,如:http://localhost:8080/pro/demo/hello.jsp?name=john,在hello.jsp页面,我们可以这样得到name的值: 复制代码 代码如下: <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getSer

  • jsp Request获取url信息的各种方法对比

    从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+&q

  • asp.net Request获取url信息的各种方法比较

    本页地址: Request.URL; 上页地址: 复制代码 代码如下: Request.UrlReferrer Request.ServerViables["http_referer"] Request.RawUrl Request.RawUrl.QueryAndPath System.IO.Path.GetFileName(Request.FilePath.ToString()) 在ASP.NET编程中经常需要用Request获取url的有关信息,Request中有多种方法获取 ur

  • 详解javascript获取url信息的常见方法

    先以"http://www.cnblogs.com/wuxibolgs329/p/6188619.html#flag?test=12345"为例,然后获得它的各个组成部分. 1.获取页面完整的url var a=location.href; console.log(a); // "http://www.cnblogs.com/wuxibolgs329/p/5261577.html#flag?test=12345" 2.获取页面的域名 var host = windo

  • 一个用php实现的获取URL信息的类

    获取URL信息的类 使用这个类,你能获得URL的如下信息: - Host  - Path  - Statuscode (eg. 404,200, ...)  - HTTP Version  - Server  - Content Type  - Date  - The whole header string of the URL 复制代码 代码如下: <? /** * Class for getting information about URL's * @author    Sven Wage

  • jQuery获取URL请求参数的方法

    本文实例讲述了jQuery获取URL请求参数的方法.分享给大家供大家参考.具体如下: $.extend({ getUrlVars: function(){ var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].

  • 使用jquery获取url以及jquery获取url参数的实现方法

    使用jquery获取url以及使用jquery获取url参数是我们经常要用到的操作 1.jquery获取url很简单,代码如下 window.location.href; 其实只是用到了javascript的基础的window对象,并没有用jquery的知识 2.jquery获取url参数比较复杂,要用到正则表达式,所以学好javascript正则式多么重要的事情 首先看看单纯的通过javascript是如何来获取url中的某个参数 function getUrlParam(name) { va

  • Android获取窗体信息的Util方法

    Android获取窗体信息的Util方法,方法很简单,这里就不多废话了,直接上代码 package com.wangyi.tools; import android.app.Activity; import android.util.DisplayMetrics; public class DisplayUtils { private static DisplayUtils instance; private Activity mActivity; private DisplayUtils(Ac

  • js中获取URL参数的共用方法getRequest()方法实例详解

    下面通过一段代码给大家介绍js中获取URL参数的共用方法getRequest()方法,具体代码如下所示: getRequest : function() { var url = location.search; //获取url中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&am

  • Js+Jq获取URL参数的集中方法示例代码

    JQ取值方法: jquery本身也不存在取得URL参数的方法,但是已经存在插件,可以直接取得URL等参数 插件连接主页:https://github.com/allmarkedup/jQuery-URL-Parser 下载链接:http://download.github.com/allmarkedup-jQuery-URL-Parser-bb2bf37.zip Examples of use Using the current page's url (for these examples ht

  • 基于JavaScript获取url参数2种方法

    这次是使用JavaScript来获取url(request)中的参数 在日常页面编写的过程中为了方便操作在<script>中通过使用window.location.href="要跳转的页面?参数1=" rel="external nofollow" +值1+"&参数2="+值2 来进行页面跳转并传值. 那么在跳转过去的页面怎样在<script>中获取到传过来的参数呢? 下面是小编的一个案例: //参数传出页面 wi

随机推荐