在 ASP.NET 的 URL 中检索锚链接 [英] Retrieving anchor link in URL for ASP.NET

查看:42
本文介绍了在 ASP.NET 的 URL 中检索锚链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的网址:

http://localhost/place/663828/bangkok-paradise-restaurant-toronto#r306040

http://localhost/place/663828/bangkok-paradise-restaurant-toronto#r306040

我正在尝试查看锚标记是否存在以及获取其值以在后面的代码中执行一些代码逻辑.

I am trying to see if there's the existence of the anchor tag along with getting its value to do some code logic in the code behind.

我一直在尝试使用 Page.Request,但没有任何属性显示 URL 的锚链接部分.

I have been trying to use the Page.Request, but none of the properties show the anchor link portion of the URL.

例如:

Response.Write(this.Page.Request.RawUrl.ToString());

我几乎尝试过此页面上的组合/属性:http://www.west-wind.com/weblog/posts/269.aspx

I pretty much tried the combinations/properties on this page: http://www.west-wind.com/weblog/posts/269.aspx

只是为了完成这个主题:

Just to finalize this topic:

我用一个永久链接复制了 Stack Overflow 的方法...... :D

I copied Stack Overflow's approach with a permalink... :D

推荐答案

在 ASP.NET 中无法从服务器端检索 #anchor.

It's not possible to retrieve the #anchor from the server side in ASP.NET.

这是一个客户端标志,告诉浏览器移动到页面内的特定位置.

This is a client-side flag to tell the browser to move to a specific place within the page.

您可以在正文 onLoad 事件中使用一些 JavaScript 代码来检查锚点并使用 Ajax.

You can use some JavaScript code in the body onLoad event to check for an anchor and send it back to the server using Ajax.

var anchorValue;
var url = document.location;
var strippedUrl = url.toString().split("#");
if(strippedUrl.Length > 1)
    anchorvalue = strippedUrl[1];

参考:检索锚点来自 URL 的值

这篇关于在 ASP.NET 的 URL 中检索锚链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆