手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >C#获取当前页面的URL示例代码
C#获取当前页面的URL示例代码
摘要:本实例的测试URL:http://www.mystudy.cn/web/index.aspx1、通过C#获取当前页面的URL复制代码代码如下...

本实例的测试URL:http://www.mystudy.cn/web/index.aspx

1、通过C#获取当前页面的URL

复制代码 代码如下:

string url = Request.Url.AbsoluteUri; //结果: http://www.mystudy.cn/web/index.aspx

string host = Request.Url.Host; //结果:www.mystudy.cn

string rawUrl = Request.RawUrl; //结果:/web/index.aspx

string localPath = Request.Url.LocalPath; //结果:/web/index.aspx

2、通过Javascript获取当前页面的URL

复制代码 代码如下:

var url = document.URL; //结果:http://www.mystudy.cn/web/index.aspx

var href = document.location.href; //结果:http://www.mystudy.cn/web/index.aspx

var host = location.hostname; //结果:www.mystudy.cn

【C#获取当前页面的URL示例代码】相关文章:

.net获取本机公网IP地址示例

ASP.NET使用gridview获取当前行的索引值

在ASP.Net中实现flv视频转换的代码

asp.net 网页编码自动识别代码

asp.net 无重复随机数代码

js获取.aspx页面里面的服务器控件和.ascx中的服务器控件值

ASP.NET 输出缓存移除的实例代码

C#中发送邮件代码

asp.net 文章内容分页显示的代码

Asp.net下载功能的解决方案代码

精品推荐
分类导航