简体   繁体   English

如何在C#中使用书签获取网站网址

[英]How to get the site url with bookmark in c#

I want to get the absolute url of .net application with bookmark. 我想获取带有书签的.net应用程序的绝对URL。

So if the request is coming from - www.mysite.com/myapplication/Home/Index#about 因此,如果请求来自www.mysite.com/myapplication/Home/Index#about

then how to get the above url in .net application? 那么如何在.net应用程序中获取上述网址?

I tried HttpContext.Request.Url.AbsoluteUri but it is returning - www.mysite.com/myapplication/Home/Index but how to get bookmark ("#about") part of url? 我试图HttpContext.Request.Url.AbsoluteUri但它返回- www.mysite.com/myapplication/Home/Index可是如何才能让bookmark ("#about") URL的一部分?

这是不可能的:#之后的任何内容都不由浏览器发送,仅在加载的页面内部用于导航到锚点。

浏览器不会将该部分传输到服务器。您应该使用像这样的答案的Java脚本

Try this, 尝试这个,

assuming that the variable url holds your actual url 假设变量网址保存您的实际网址

string[] bookmark = url.Split('#');
and the bookmark[1] will hold the Value of your bookmark, also.

string bookmark = url.Replace(HttpContext.Request.Url.AbsoluteUri(url), string.Empty);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM