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的方法(转)相关推荐

  1. asp.net中获取当前url的方法

    HttpContext.Current.Request.Url.ToString() 并不可靠. 如果当前URL为 http://localhost/search.aspx?user=http://c ...

  2. magento block 程序中获取各种url及绝对路径的方法

    magento block 程序中获取各种url的方法 Mage::getBaseUrl('media') //可获得 media 带 http 的url 地址.//同理也可以获得skin 和js 目 ...

  3. 在ASP.NET MVC 中获取当前URL、controller、action

    在ASP.NET MVC 中获取当前URL.controller.action URL的获取很简单,ASP.NET通用: [1]获取 完整url  (协议名+域名+虚拟目录名+文件名+参数) stri ...

  4. ASP.NET中文件上传下载方法集合

    asp.net 2008-08-23 21:10:35 阅读0 评论0   字号:大中小 订阅 ASP.NET中文件上传下载方法集合 文件的上传下载是我们在实际项目开发过程中经常需要用到的技术,这里给 ...

  5. cmd 调用oracle存储过程,asp.net中调用oracle存储过程的方法

    存储过程(Stored Procedure)是在大型数据库系统中,一组为了完成特定功能的SQL 语句集,存储在数据库中经过第一次编译后再次调用不需要再次编译,用户通过指定存储过程的名字并给出参数(如果 ...

  6. 介绍一种在MATLAB中获取股市数据的方法

    介绍一种在MATLAB中获取股市数据的方法: >>clear >>c=yahoo 系统会返回 c = url: 'http://finance.yahoo.com'       ...

  7. 在ASP.NET中获取文件属性

    www.chinacs.net  2001-8-13  中文C#技术站 在ASP.NET中获取文件属性(Retrieving File Information In ASP.NET) By Steve ...

  8. 【转】Java中获取文件大小的正确方法

    [转]Java中获取文件大小的正确方法 本文出处:http://blog.csdn.net/chaijunkun/article/details/22387305,转载请注明.由于本人不定期会整理相关 ...

  9. legend3---laravel中获取控制器名称和方法名称

    legend3---laravel中获取控制器名称和方法名称 一.总结 一句话总结: \Route::current()->getActionName();会有完整的当前控制器名和方法名 pub ...

最新文章

  1. 常见TS权限问题“通过终端服务访问”
  2. Connect to dl.google.com:443 [dl.google.com/142.250.66.142] failed: Connection timed out:
  3. android xml导进数据库,Android通过xml文件配置数据库
  4. linux hadoop etc目录,Hadoop系列——Linux下Hadoop的安装与伪分布式配置
  5. android 创建模拟器打不开,解决Android模拟器打不开的问题!...
  6. ubunt18.04LTS+vscode+anaconda3下的python+C++调试
  7. 7. Shell 脚本编写
  8. 医疗大数据服务平台技术架构有哪些
  9. python与队列入门
  10. 非常好的关于android安全的博客
  11. 极客大学架构师训练营--食堂就餐系统架构设计⽂档 -- 第一次作业
  12. CentOS上安装Git
  13. linux 调节风扇速度命令,ubuntu系统调节GPU风扇转速
  14. iris流程图_IRIS项目管理流程
  15. 笔记(一)Home Assistant简介
  16. 希捷硬盘无法安全弹出如何解决?
  17. 计算机专业笔记本电脑华为,大学生不知道买什么电脑?来看这款华为荣耀极致性价比笔记本!...
  18. Ubuntu 好用的BT下载工具qBittorrent
  19. day23 Java8新特性
  20. 一个C#开发的、跨平台的服务器性能监控工具

热门文章

  1. GRE新东方推荐学习方法(2010年左右)
  2. windows下Administrator与Guest账号权限被互换,无法获取管理员权限
  3. 浅谈数据抓取的几种方法
  4. 零基础自学UI设计要看什么书籍和资料
  5. openCV色彩空间转换
  6. Qt使用html生成word文档
  7. Opengl入门基础-shader着色器画方形并且填颜色
  8. 如何让绘画灵气十足-张聪-专题视频课程
  9. 解决 command not found: netstat
  10. Java随机生成验证码