检索 ASP.NET URL 中的锚链接
我有一个像这样的URL:
http://localhost/place/663828/bangkok-paradise-restaurant-toronto#r306040
我试图看看是否存在锚标记以及获取其值来执行一些代码逻辑后面的代码。
我一直在尝试使用 Page.Request,但没有一个属性显示 URL 的锚链接部分。
例如:
Response.Write(this.Page.Request.RawUrl.ToString());
我几乎尝试了此页面上的组合/属性: http:// /www.west-wind.com/weblog/posts/269.aspx
只是为了完成这个主题:
我用永久链接复制了 Stack Overflow 的方法... :D
I have a URL like so:
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.
I have been trying to use the Page.Request, but none of the properties show the anchor link portion of the URL.
For example:
Response.Write(this.Page.Request.RawUrl.ToString());
I pretty much tried the combinations/properties on this page: http://www.west-wind.com/weblog/posts/269.aspx
Just to finalize this topic:
I copied Stack Overflow's approach with a permalink... :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无法从 ASP.NET 中的服务器端检索#anchor。
这是一个客户端标志,用于告诉浏览器移动到页面内的特定位置。
您可以在正文 onLoad 事件中使用一些 JavaScript 代码来检查锚点并使用 Ajax。
参考:从 a 中检索锚点值网址
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.
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.
Ref: Retrieving the anchor value from a URL
更明确地说,任何浏览器都不会将锚标记作为 HTTP 请求的一部分发送。 它仅在浏览器中本地解释。 ASP.NET 或任何其他 Web 服务器技术、Microsoft 或其他技术都不会看到该请求上的锚点。
正如其他人所建议的,您可以获得的最接近的结果是使用客户端读取浏览器窗口位置。
Being more explicit, the anchor tag is never sent as part of the HTTP request by any browser. It is only interpreted locally within the browser. Neither ASP.NET nor any other web server technology, Microsoft or otherwise will see the anchor on that request.
As others have suggested, the nearest you could get would be using client-side to read the browser window location.
可以通过以下方式从 C# 中的 URL 解析片段:
但是存在一个问题,浏览器不会将片段发送到服务器。 如果您收到的服务请求中包含此信息,则服务器端也可以使用该信息。
A fragment can be parsed from a URL in C# in the following way:
There is a problem however in that the browser won't send fragments to the server. If you receive requests from a service that includes this information in the request, it will be available from the server side too.