8

私は公開 Web サイトの構築と購入のトレードオフを指定している最中で、かなり興味深い道にたどり着きました。

バックグラウンド

Web サイトの設計の一部は、明らかに独自の ID を持つさまざまな「アイテム」のセットに対するコメントを組み込むことです。(つまり、/recipes/23 または equipment/16 など)。

最初は、タグ付きのコメント システムを指定していました。しかし、プロジェクトのスポンサーが戻ってきて、Disqus をミックスに組み込むのは簡単かどうか尋ねてきました。これは以前に Joomla で使用したことがあり (.NET では使用したことがありません)、デフォルトで通常のソーシャル ネットワーク メディアを介してコメントが自動的に配信されるため、これは素晴らしいアイデアになると思います。

質問

シームレスに動作する ASP.NET MVC で Disqus の実装をセットアップするのはかなり簡単ですか? ASP.NET MVC で動作する Disqus ソリューションのチュートリアルまたは例はありますか? 私はこの例を見て、これまでのドキュメントを読みました

4

4 に答える 4

16

明らかに、Disqus用の素晴らしいnugetパッケージがあります。

Install-Package Disqus.Helper

そして、これをビュー、セクション、または部分ビューのどこかに貼り付けるのと同じくらい簡単です...

@Disqus {
     Disqus.Initialize("YourForumShortName")
}
@Discus.ShowComments("PageIdentifierOfYourChoice")

http://disqusforwebpages.codeplex.com/documentation

于 2011-05-25T14:19:59.623 に答える
6

(本格的な API メソッドを使用するのではなく) 非同期 JavaScript ロード アプローチを使用することにしました。ASPNET MVC でこれを使用する方法は簡単です (ASP.NET でも機能します)。

ドキュメントから:

<!-- add the div to receive the comments via ajax -->
<div id="disqus_thread"></div>

<!-- the required javascript link to disqus -->
<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'mydisqusname';

    // Question pour XWiki : ici il faut que je configure un identifier
    // c'est comme un sujet de Mail. Il faudrait que je mette par exemple
    // l'url de la page XWiki afin que les commentaires soient regroupes

    // ensemble par article. Bref est ce que vous pouvez me mettre un ID ?

    var disqus_identifier = 'comments-league-<%= Html.Encode(Model.ID) %>';
    var disqus_url = '<%= HttpContext.Current.Request.Url %>';
    // using disqus_developer = 1 helps to debug to localhost etc..
    var disqus_developer = 1;


    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';

        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>

それだけです。

于 2011-01-19T12:59:53.603 に答える
3

disqus のブランディングに問題がなければ、javascript API 呼び出しを使用することをお勧めします。より深い統合が必要な場合、またはコメントがサイトに残るようにする必要がある場合は、私が書いたdisqussharpという小さなライブラリをチェックしてみてください。 disqus API であり、さまざまな用途に使用できます。

于 2011-01-19T14:46:28.340 に答える
2

Disqus と IntenseDebate の両方を対象とする拡張メソッドの組み合わせを次に示します。

まず、Disqus ヘルパー (PieterG に同意):

/// <summary>
/// Display Comments for Post
/// </summary>
/// <param name="html"></param>
/// <param name="postIdentifier"></param>
/// <returns></returns>
public static MvcHtmlString DisqusScript(this HtmlHelper html, string postIdentifier)
{
    var commentsBuilder = new StringBuilder();
    var id = Config.DisqusId; // get the Disqus id from config file
    var devMode = Config.DevMode; // get the devmode ('0' or '1') from config file

    commentsBuilder.Append("<div id=\"disqus_thread\"></div>");

    commentsBuilder.Append("<script type=\"text/javascript\">");
    commentsBuilder.Append("var disqus_shortname = '" + id + "';");
    commentsBuilder.Append("var disqus_identifier = '" + postIdentifier + "';");
    commentsBuilder.Append("var disqus_url = '" + HttpContext.Current.Request.Url + "';");
    commentsBuilder.Append("var disqus_developer = '" + devMode + "';");

    /* * * DON'T EDIT BELOW THIS LINE * * */
    commentsBuilder.Append("(function () {");
    commentsBuilder.Append("var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;");
    commentsBuilder.Append("dsq.src = 'http://" + id + ".disqus.com/embed.js';");

    commentsBuilder.Append("(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);");
    commentsBuilder.Append("})();");
    commentsBuilder.Append("</script>");

    commentsBuilder.Append("<noscript>");
    commentsBuilder.Append("Please enable JavaScript to view the <a href=\"http://disqus.com/?ref_noscript\">comments");
    commentsBuilder.Append("powered by Disqus.</a>");
    commentsBuilder.Append("</noscript>");
    return MvcHtmlString.Create(commentsBuilder.ToString());
}

そして激しい討論バージョン:

/// <summary>
/// Display Comments for Post
/// </summary>
/// <param name="html"></param>
/// <param name="postIdentifier"></param>
/// <returns></returns>
public static MvcHtmlString IntenseDebateScript(this HtmlHelper html, string postIdentifier)
{
    var commentsBuilder = new StringBuilder();
    var id = Config.IntenseDebateId; // get the IntenseDebate id from config file

    // js variables for embedded wrapper script
    commentsBuilder.Append("<script type=\"text/javascript\">");
    commentsBuilder.Append("var idcomments_acct = '" + id + "';");
    commentsBuilder.Append("var idcomments_post_id = '" + postIdentifier + "';");
    commentsBuilder.Append("var idcomments_post_url = '" + HttpContext.Current.Request.Url + "';");
    commentsBuilder.Append("</script>");

    /* * * DON'T EDIT BELOW THIS LINE * * */
    commentsBuilder.Append("<script type=\"text/javascript\" ");
    commentsBuilder.Append("src = 'http://www.intensedebate.com/js/genericCommentWrapperV2.js'>");
    commentsBuilder.Append("</script>");

    // add the target span for the comments
    commentsBuilder.Append("<span id='IDCommentsPostTitle' style='display:none'></span>");

    commentsBuilder.Append("<noscript>");
    commentsBuilder.Append("Please enable JavaScript to view the IntenseDebate comments");
    commentsBuilder.Append("</noscript>");
    return MvcHtmlString.Create(commentsBuilder.ToString());
}

どちらの場合の使用法:

// for intensedebate
<%=Html.IntenseDebateScript("comments-id-that-i-can-use") %>

//and for disqus
<%=Html.DisqusScript("another-comments-id-that-i-can-use") %>

楽しい...

于 2011-02-15T10:37:19.773 に答える