如何在 MVC 3 中获取当前页面 URL [英] How to get current page URL in MVC 3
问题描述
我正在构建的博客上使用 Facebook 评论插件.它有一些由页面上引用的 facebook javascript 解释的 FBXML 标签.
这一切正常,但我必须将当前的、完全限定的 URL 传递给插件.
<div id="fb-root"></div><fb:comments href="URL HERE" num_posts="10" width="900"></fb:comments>
获取当前页面 URL 的最佳方式是什么?请求网址.
解决方案
这是我的解决方案的最终代码:
<fb:comments href="@Request.Url.AbsoluteUri" num_posts="15" width="900"></fb:comments>
您可以使用 Request.RawUrl
、Request.Url.OriginalString
、Request.Url.ToString()
或 Request.Url.AbsoluteUri代码>.
I am using the Facebook comments plugin on a blog I am building. It has some FBXML tags that are interpreted by the facebook javascript that is referenced on the page.
This all works fine, but I have to pass in the current, fully-qualified URL to the plugin.
<div style="width: 900px; margin: auto;">
<div id="fb-root"></div>
<fb:comments href="URL HERE" num_posts="10" width="900"></fb:comments>
</div>
What is the best way to get the URL of the current page? The request URL.
Solution
Here is the final code of my solution:
<fb:comments href="@Request.Url.AbsoluteUri" num_posts="15" width="900"></fb:comments>
You could use the Request.RawUrl
, Request.Url.OriginalString
, Request.Url.ToString()
or Request.Url.AbsoluteUri
.
这篇关于如何在 MVC 3 中获取当前页面 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!