asp.net中获取当前url的方法(转)
HttpContext.Current.Request.Url.ToString() 并不可靠。
如果当前URL为
http://localhost/search.aspx?user=http://csharp.xdowns.com&tag=%BC%BC%CA%F5
通过HttpContext.Current.Request.Url.ToString()获取到的却是
http://localhost/search.aspxuser=http://csharp.xdowns.com&tag=¼¼Êõ
正确的方法是:HttpContext.Current.Request.Url.PathAndQuery1、通过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\testwebRequest.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>
=================
获取IP
1、ASP.NET中获取
获取服务器的IP地址:
using System.Net;
string myIP,myMac;
System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
if ( addressList.Length>1)
{
myIP = addressList[0].ToString();
myMac = addressList[1].ToString();
}
else
{
myIP = addressList[0].ToString();
myMac = "没有可用的连接";
}
myIP地址就是服务器端的ip地址。
获取客户端的ip地址,可以使用
//获取登录者ip地址
string ip = Request.ServerVariables["REMOTE_ADDR"].ToString();
2、通过JS获取
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
</head>
<body>
<object classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" id="locator" style="display:none;visibility:hidden"></object>
<object classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223" id="foo" style="display:none;visibility:hidden"></object>
<form name="myForm">
<br/>MAC地址:<input type="text" name="macAddress">
<br/>IP地址:<input type="text" name="ipAddress">
<br/>主机名:<input type="text" name="hostName">
</form>
</body>
</html>
<script language="javascript">
var sMacAddr="";
var sIPAddr="";
var sDNSName="";
var service = locator.ConnectServer();
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
</script>
<script FOR="foo" EVENT="OnObjectReady(objObject,objAsyncContext)" LANGUAGE="JScript">
if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true){
if(objObject.IPEnabled && objObject.IPAddress(0) !=null && objObject.IPAddress(0) != "undefined")
sIPAddr = objObject.IPAddress(0);
if(objObject.MACAddress != null &&objObject.MACAddress != "undefined")
sMacAddr = objObject.MACAddress;
if(objObject.DNSHostName != null &&objObject.DNSHostName != "undefined")
sDNSName = objObject.DNSHostName;
}
</script>
<script FOR="foo" EVENT="OnCompleted(hResult,pErrorObject, pAsyncContext)" LANGUAGE="JScript">
myForm.macAddress.value=sMacAddr;
myForm.ipAddress.value=sIPAddr;
myForm.hostName.value=sDNSName;
</script>
转载于:https://www.cnblogs.com/Byrd/archive/2011/05/27/2059864.html
asp.net中获取当前url的方法(转)相关推荐
- asp.net中获取当前url的方法
HttpContext.Current.Request.Url.ToString() 并不可靠. 如果当前URL为 http://localhost/search.aspx?user=http://c ...
- magento block 程序中获取各种url及绝对路径的方法
magento block 程序中获取各种url的方法 Mage::getBaseUrl('media') //可获得 media 带 http 的url 地址.//同理也可以获得skin 和js 目 ...
- 在ASP.NET MVC 中获取当前URL、controller、action
在ASP.NET MVC 中获取当前URL.controller.action URL的获取很简单,ASP.NET通用: [1]获取 完整url (协议名+域名+虚拟目录名+文件名+参数) stri ...
- ASP.NET中文件上传下载方法集合
asp.net 2008-08-23 21:10:35 阅读0 评论0 字号:大中小 订阅 ASP.NET中文件上传下载方法集合 文件的上传下载是我们在实际项目开发过程中经常需要用到的技术,这里给 ...
- cmd 调用oracle存储过程,asp.net中调用oracle存储过程的方法
存储过程(Stored Procedure)是在大型数据库系统中,一组为了完成特定功能的SQL 语句集,存储在数据库中经过第一次编译后再次调用不需要再次编译,用户通过指定存储过程的名字并给出参数(如果 ...
- 介绍一种在MATLAB中获取股市数据的方法
介绍一种在MATLAB中获取股市数据的方法: >>clear >>c=yahoo 系统会返回 c = url: 'http://finance.yahoo.com' ...
- 在ASP.NET中获取文件属性
www.chinacs.net 2001-8-13 中文C#技术站 在ASP.NET中获取文件属性(Retrieving File Information In ASP.NET) By Steve ...
- 【转】Java中获取文件大小的正确方法
[转]Java中获取文件大小的正确方法 本文出处:http://blog.csdn.net/chaijunkun/article/details/22387305,转载请注明.由于本人不定期会整理相关 ...
- legend3---laravel中获取控制器名称和方法名称
legend3---laravel中获取控制器名称和方法名称 一.总结 一句话总结: \Route::current()->getActionName();会有完整的当前控制器名和方法名 pub ...
最新文章
- 常见TS权限问题“通过终端服务访问”
- Connect to dl.google.com:443 [dl.google.com/142.250.66.142] failed: Connection timed out:
- android xml导进数据库,Android通过xml文件配置数据库
- linux hadoop etc目录,Hadoop系列——Linux下Hadoop的安装与伪分布式配置
- android 创建模拟器打不开,解决Android模拟器打不开的问题!...
- ubunt18.04LTS+vscode+anaconda3下的python+C++调试
- 7. Shell 脚本编写
- 医疗大数据服务平台技术架构有哪些
- python与队列入门
- 非常好的关于android安全的博客
- 极客大学架构师训练营--食堂就餐系统架构设计⽂档 -- 第一次作业
- CentOS上安装Git
- linux 调节风扇速度命令,ubuntu系统调节GPU风扇转速
- iris流程图_IRIS项目管理流程
- 笔记(一)Home Assistant简介
- 希捷硬盘无法安全弹出如何解决?
- 计算机专业笔记本电脑华为,大学生不知道买什么电脑?来看这款华为荣耀极致性价比笔记本!...
- Ubuntu 好用的BT下载工具qBittorrent
- day23 Java8新特性
- 一个C#开发的、跨平台的服务器性能监控工具