ASP.NET 如何获取地址栏URL地址

2024-03-26 15:18
文章标签 地址 获取 url asp net 地址栏

本文主要是介绍ASP.NET 如何获取地址栏URL地址,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

ASP.NET 如何获取地址栏URL地址?看下面的实现方法:

第一种: 

http://www.liehuo.net/liehuonet/default.aspx 

Request.ApplicationPath: /liehuonet 
Request.CurrentExecutionFilePath: /liehuonet/default.aspx 
Request.FilePath: /liehuonet/default.aspx 
Request.Path: /liehuonet/default.aspx 
Request.RawUrl: /liehuonet/default.aspx 
Request.Url.AbsolutePath: /liehuonet/default.aspx 
Request.Url.AbsoluteUri: http://www.liehuo.net/liehuonet/default.aspx 
Request.Url.Host: www.liehuo.net 
Request.Url.LocalPath: /liehuonet/default.aspx

第二种: 

RawUrl 
属性属性值当前请求的原始 URL。 
备注 

原始 URL 定义为 URL 中域信息之后的部分。在 URL 字符串 http://www.liehuo.net/cn/introduct/lanmu_24_57.html中,原始 URL 为/cn/introduct/lanmu_24_57.html。原始 URL 包括查询字符串(如果存在)。

测试的url地址是http://www.liehuo.net/liehuonet/default.aspx?id=1, 结果如下:

Request.ApplicationPath: /liehuonet 

Request.CurrentExecutionFilePath: /liehuonet/default.aspx 

Request.FilePath: /liehuonet/default.aspx 

Request.Path: /liehuonet/default.aspx 

Request.PathInfo: 

Request.PhysicalApplicationPath: E:\WWW\liehuonet\ 

Request.PhysicalPath: E:\WWW\liehuonet\default.aspx 

Request.RawUrl: /liehuonet/default.aspx?id=1 

Request.Url.AbsolutePath: /liehuonet/default.aspx 

Request.Url.AbsoluteUri: http://www.liehuo.net/liehuonet/default.aspx?id=1 

Request.Url.Host: www.liehuo.net 

Request.Url.LocalPath: /liehuonet/default.aspx

获取URL:   
   1、通过ASP.NET获取   
   如果测试的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.PhysicalApplicationPath:                 E:\WWW\testweb\   
   Request.PhysicalPath:                                       E:\WWW\testweb\default.aspx   
   Request.RawUrl:                                                   /testweb/default.aspx   
   Request.Url.AbsolutePath:                               /testweb/default.aspx   
   Request.Url.AbsoluteUrl:                                 http://www.test.com/testweb/default.aspx   
   Request.Url.Host:                                               www.test.com   
   Request.Url.LocalPath:                                     /testweb/default.aspx     
    
   2、通过JS获取   
    
   <table   width=100%   cellpadding=0   cellspacing=0   border=0   >       
   <script>         
   thisURL   =   document.URL;   
   thisHREF   =   document.location.href;    
   thisSLoc   =   self.location.href;        
   thisDLoc   =   document.location;         
   strwrite   =   "<tr><td   valign=top>thisURL:   </td><td>["   +   thisURL   +   "]</td></tr>"strwrite   +=   "<tr><td   valign=top>thisHREF:   </td><td>["   +   thisHREF   +   "]</td></tr>" strwrite   +=   "<tr><td   valign=top>thisSLoc:   </td><td>["   +   thisSLoc   +   "]</td></tr>" strwrite   +=   "<tr><td   valign=top>thisDLoc:   </td><td>["   +   thisDLoc   +   "]</td></tr>" document.write(   strwrite   );     
   </script>     
   thisDLoc   =   document.location;   <BR>      
   thisURL   =   document.URL;   <BR>       
   thisHREF   =   document.location.href;   <BR>       
   thisSLoc   =   self.location.href;<BR>       
   <script>         
   thisTLoc   =   top.location.href;         
   thisPLoc   =   parent.document.location;      
   thisTHost   =   top.location.hostname;       
   thisHost   =   location.hostname;        
   strwrite   =   "<tr><td   valign=top>thisTLoc:   </td><td>["   +   thisTLoc   +   "]</td></tr>"strwrite   +=   "<tr><td   valign=top>thisPLoc:   </td><td>["   +   thisPLoc   +   "]</td></tr>"strwrite   +=   "<tr><td   valign=top>thisTHost:   </td><td>["   +   thisTHost   +   "]</td></tr>"strwrite   +=   "<tr><td   valign=top>thisHost:   </td><td>["   +   thisHost   +   "]</td></tr>"document.write(   strwrite   );  
   </script>     
   thisTLoc   =   top.location.href;   <BR>     
   thisPLoc   =   parent.document.location;   <BR>      
   thisTHost   =   top.location.hostname;   <BR>      
   thisHost   =   location.hostname;<BR>      
   <script>        
   tmpHPage   =   thisHREF.split(   "/"   );        
   thisHPage   =   tmpHPage[   tmpHPage.length-1   ];        
   tmpUPage   =   thisURL.split(   "/"   );         
   thisUPage   =   tmpUPage[   tmpUPage.length-1   ];      
   strwrite   =   "<tr><td   valign=top>thisHPage:   </td><td>["   +   thisHPage   +   "]</td></tr>"      
   strwrite   +=   "<tr><td   valign=top>thisUPage:   </td><td>["   +   thisUPage   +   "]</td></tr>"        
   document.write(   strwrite   );    
   </script><tr><td> 

这篇关于ASP.NET 如何获取地址栏URL地址的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/848927

相关文章

MySQL 获取字符串长度及注意事项

《MySQL获取字符串长度及注意事项》本文通过实例代码给大家介绍MySQL获取字符串长度及注意事项,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录mysql 获取字符串长度详解 核心长度函数对比⚠️ 六大关键注意事项1. 字符编码决定字节长度2

解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题

《解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题》:本文主要介绍解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4... 目录未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘打开pom.XM

python3如何找到字典的下标index、获取list中指定元素的位置索引

《python3如何找到字典的下标index、获取list中指定元素的位置索引》:本文主要介绍python3如何找到字典的下标index、获取list中指定元素的位置索引问题,具有很好的参考价值,... 目录enumerate()找到字典的下标 index获取list中指定元素的位置索引总结enumerat

SpringMVC高效获取JavaBean对象指南

《SpringMVC高效获取JavaBean对象指南》SpringMVC通过数据绑定自动将请求参数映射到JavaBean,支持表单、URL及JSON数据,需用@ModelAttribute、@Requ... 目录Spring MVC 获取 JavaBean 对象指南核心机制:数据绑定实现步骤1. 定义 Ja

javax.net.ssl.SSLHandshakeException:异常原因及解决方案

《javax.net.ssl.SSLHandshakeException:异常原因及解决方案》javax.net.ssl.SSLHandshakeException是一个SSL握手异常,通常在建立SS... 目录报错原因在程序中绕过服务器的安全验证注意点最后多说一句报错原因一般出现这种问题是因为目标服务器

C++中RAII资源获取即初始化

《C++中RAII资源获取即初始化》RAII通过构造/析构自动管理资源生命周期,确保安全释放,本文就来介绍一下C++中的RAII技术及其应用,具有一定的参考价值,感兴趣的可以了解一下... 目录一、核心原理与机制二、标准库中的RAII实现三、自定义RAII类设计原则四、常见应用场景1. 内存管理2. 文件操

SpringBoot服务获取Pod当前IP的两种方案

《SpringBoot服务获取Pod当前IP的两种方案》在Kubernetes集群中,SpringBoot服务获取Pod当前IP的方案主要有两种,通过环境变量注入或通过Java代码动态获取网络接口IP... 目录方案一:通过 Kubernetes Downward API 注入环境变量原理步骤方案二:通过

使用Python实现获取屏幕像素颜色值

《使用Python实现获取屏幕像素颜色值》这篇文章主要为大家详细介绍了如何使用Python实现获取屏幕像素颜色值,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 一、一个小工具,按住F10键,颜色值会跟着显示。完整代码import tkinter as tkimport pyau

python获取cmd环境变量值的实现代码

《python获取cmd环境变量值的实现代码》:本文主要介绍在Python中获取命令行(cmd)环境变量的值,可以使用标准库中的os模块,需要的朋友可以参考下... 前言全局说明在执行py过程中,总要使用到系统环境变量一、说明1.1 环境:Windows 11 家庭版 24H2 26100.4061

使用Python获取JS加载的数据的多种实现方法

《使用Python获取JS加载的数据的多种实现方法》在当今的互联网时代,网页数据的动态加载已经成为一种常见的技术手段,许多现代网站通过JavaScript(JS)动态加载内容,这使得传统的静态网页爬取... 目录引言一、动态 网页与js加载数据的原理二、python爬取JS加载数据的方法(一)分析网络请求1