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

黄舟
黄舟Original
2017-01-19 11:05:301166browse

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

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

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 (www.php.cn)!


Statement:
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