Home > Backend Development > C#.Net Tutorial > C# Get the URL sample code of the current page

C# Get the URL sample code of the current page

黄舟
Release: 2017-01-19 11:05:30
Original
1149 people have browsed it

Test URL of this example: http://www.mystudy.cn/web/index.aspx

1. Get the URL of the current page through C

#
string url = Request.Url.AbsoluteUri; //结果: <a href="http://www.mystudy.cn/web/index.aspx" target="_blank">http://www.mystudy.cn/web/index.aspx</a>   
string host = Request.Url.Host; //结果:www.mystudy.cn   
string rawUrl = Request.RawUrl; //结果:/web/index.aspx   
string localPath = Request.Url.LocalPath; //结果:/web/index.aspx
Copy after login

2. Through Javascript Get the URL of the current page

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
Copy after login

The above is the content of the C# Get the URL of the current page sample code. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template