Click here to Skip to main content
15,886,258 members
Articles / Web Development / ASP.NET

An Introduction to Disqus (Pluggable Commenting System) with ASP.NET MVC 3

Rate me:
Please Sign up or sign in to vote.
4.79/5 (10 votes)
31 Jul 2013CPOL11 min read 51.3K   1.5K   28  
This article discusses ways by which you could utilize Disqus in your web applications.
@using System.Globalization
@using DisqusTutorial.Infrastructure

@{
    ViewBag.Title = "Disqus Ajaxified";
}

<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = '@ApplicationConfiguration.DisqusShortName'; // required: replace example with your forum shortname
    var disqus_identifier = '';
    var disqus_url = '';
    var disqus_developer = 1;
</script>

<script type="text/javascript">
    $(document).ready(function () {
        initializeDisqus();

        $('#btnNext').click(function () {
            var disqusId = 'another-page';
            reset(disqusId);
        });

        $('#btnPrevious').click(function () {
            var disqusId = 'yet-another-page';
            reset(disqusId);
        });

        $('#btnInit').click(function () {
            var disqusId = 'hello-world';
            reset(disqusId);
        });
    });

    function initializeDisqus() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';

        dsq.onload = function () {
            var disqusId = 'hello-world';
            reset(disqusId);
        };

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

    function reset(disqusId) {
        DISQUS.reset({
            reload: true,
            config: function () {
                this.page.identifier = disqusId;
                this.page.url = $('#rootUrl').val() + disqusId;
            }
        });
    }
</script>

<h2>Disqus Ajaxified</h2>

<div style="float: right">
    Page loaded initially at: <b>@DateTime.Now.ToString(CultureInfo.InvariantCulture)</b>
</div>

<div style="clear: both"></div>

<div id="controls">
    <div style="float: left">
        <a id="btnPrevious" href="javascript:void(0)">&lt;&lt; Previous</a>
    </div>
    <div style="text-align: center">
        <a id="btnInit" href="javascript:void(0)">First</a>
    </div>
    <div style="float: right">
        <a id="btnNext" href="javascript:void(0)">Next &gt;&gt;</a>
    </div>
</div>
<br/><br/>
<input type="hidden" id="rootUrl" value="@string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"))"/>
<div id="disqus_thread"></div>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>        

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Just another passionate software developer!

Some of the contributions to the open source world - a blog engine written in MVC 4 - sBlog.Net. Check it out here. For the codeproject article regarding sBlog.Net click here!

(Figuring out this section!)

Comments and Discussions