- 浏览: 142769 次
- 性别:
- 来自: 成都
文章分类
最新评论
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>
发表评论
-
SQL Server 2008 R2 中英文 开发版/企业版/标准版 链接地址
2015-01-19 11:08 902SQL Server 2008 R2 中英文 开发版/企业版/ ... -
C# SQLSERVER2008数据库备份和还原的两种方法 (有进度条)
2013-06-21 11:01 1992C# SQLSERVER2008数据库备份和还原的两种方 ... -
C#的web Service 调用的简单例子
2013-01-10 15:18 1252是webservice.就概念上来说,可能比较复杂,不 ... -
编程的三种循环
2011-12-20 10:37 913大家都应该知道,其实java和C#都出自同师门的。虽然他们是不 ... -
农历,阳历 倒计时源码
2011-11-15 13:49 936自己没事写了一个倒计时,里面有每年阳历的倒计时和农历的倒计时。 ... -
winform 特殊字符判断控件下载
2011-09-20 10:30 1512以前我听说过一个软件科技公司,写了一个控件,只要在那个软件里面 ... -
iis发布网站
2011-07-27 10:25 787本人自己写的,给大家参考的。 1.安装iis(网络上下载 ... -
鼠标和键盘事件
2011-07-15 11:28 1063鼠标事件有11个,常用八个,都不用说了。click,Doubl ... -
winform读写ini配置文件
2011-07-14 11:29 1457public static string re ... -
winform 增删改查
2011-07-13 16:27 1842增删改,是一个样的指令: //添加物品 ... -
winform中的datagridview数据添加方式
2011-07-13 16:10 5053winform中的datagridview数据添加方式,在我现 ... -
Winform的dataGridView中添加序号
2011-07-13 15:40 6351dataGridView的RowPostPa ... -
vs多级树动态加载
2011-06-25 22:37 997private void LoadCategoryTree ... -
VS2008 验证控件的用法
2011-05-23 11:09 3812ASP.NET为开发人员提供了 ... -
<meta name="description" content="string"/> 用法
2011-03-16 11:59 818一、语法: <meta name="nam ... -
利用js获取服务器时间的两个简单方法
2011-03-02 18:02 1147有时用js来获取服务 ... -
Asp收藏当前页面的网址到收藏夹
2011-01-13 11:28 773<%function getip '获 ... -
asp.net(fileupload)上传图片预览
2010-12-21 10:55 7969<script language="java ... -
asp上传图片及删除图片,并从文件夹里删除
2010-12-16 15:21 3884一.上传图片 public s ... -
VS2005打不开Web设计器的处理方法
2010-11-19 10:30 12111、设置系统变量 VsLogActivity=1 右击“我的电 ...
相关推荐
通过webrequest, webclient两种方式请求url获取对应的返回值
通过 webrequest,webclient两种方法请求远程url,获取返回值
【ASP.NET编程知识】asp.net获取URL和IP地址的方法汇总.docx
ASP.NET C# URL重写 地址重写 伪静态 转HTML
ASP.NET2.0 c# 获取浏览器,IP,URL,操作系统
//获取完整url (协议名+域名+站点名+文件名+参数) string fullUrl = Request.Url.ToString(); //获取客户端请求的URL信息(不包括主机和端口) string rawUrl = Request.RawUrl;...//获取服务器上ASP.NET应
asp.net实现URL的伪静态,重写URL地址
任何URL都可生成二维码,可以用微信扫一扫跳转,用C#的ASP.NET实现。解决上一版本小bug,本人腾讯微博:http://t.qq.com/djk8888,欢迎交流
在Asp.net中如何用SQLDMO来获取SQL Server中的对象信息 使用Relations建立表之间的关系并却使用PagedDataSource类对DataList进行分页 通过作业,定时同步两个数据库 SQLSERVER高级注入技巧 利用反射实现ASP.NET控件和...
asp.net获取URL和IP地址的方法汇总,需要的朋友可以参考一下
AspNetPager针对ASP.NET分页控件的不足,提出了与众不同的解决asp.net中分页问题的方案,即将分页导航功能与数据显示功能完全独立开来,由用户自己控制数据的获取及显示方式,因此可以被灵活地应用于任何需要实现...
//获取从wxProcess.aspx传递过来的跳转地址reurl if (Request.QueryString["reurl"] != null && Request.QueryString["reurl"] != "") { reurl = Request.QueryString["reurl"].ToString(); } string code = ...
1.3.6 建立在ASP.NET平台的精华之上 7 1.3.7 现代API 7 1.3.8 ASP.NET MVC是开源的 8 1.4 本书的预备知识 8 1.5 本书的结构 8 1.5.1 第1部分:ASP.NET MVC 5导论 8 1.5.2 第2部分:ASP.NET MVC细节 8 1.6 本版的新...
第一部分 使用ASP.NET Web表单 <br>第1章 建立ASP.NET页面 <br>1.1 ASP.NET和.NET框架 1.1.1 .NET框架类库 1.1.2 理解名称空间 1.1.3 标准的ASP.NET名称空间 1.1.4 与.NET框架兼容的语言 ...
在ASP.NET中,如果你使用了URL重写,通过HttpContext.Request获取到的是重写后的地址。如果这个地址要返回给客户端(比如Redirect),我们一般希望是重写前的友好地址。
AfengPager通用ASP.NET URL分页控件,很多参数可以自定义,比如分页样式的显示、分布按钮的样式、总页数(动态,前置条件:总记录数、每页显示的记录数)等,代码可获取或设置位于页索引框右边的文字、获取或设置...
C#获取当前页面的url 和JavaScript 获取当前页面的URL
获取Url的方法有两种,通过后台获得或通过前面js获得,如下: 1、通过C#获取当前页面的URL string url = Request.Url.AbsoluteUri; //结果: //www.jb51.net/web/index.aspx string host = Request.Url.Host; //结果...
asp.net 网易微博 OAuth 2.0 实例源码 1.需要在http://open.t.163.com/ 申请一个帐号 2.获取Appkey,AppSecret 3.需要配置 oauth.config 填入相应的Appkey,AppSecret,原来上面的是我自己乱填的,所以测试需要填你...