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

Log Reporting Dashboard for ASP.NET MVC

Rate me:
Please Sign up or sign in to vote.
4.94/5 (60 votes)
23 Aug 2010CPOL12 min read 175.2K   5.6K   193  
Log reporting dashboard for Log4Net, NLog, ELMAH, and ASP.NET Health Monitoring.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
using DotNetOpenAuth.OpenId.RelyingParty;

namespace MvcRelyingParty
{

    public interface IOpenIdRelyingParty
    {
        Channel Channel { get; }

        IAuthenticationRequest CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy);

        IEnumerable<IAuthenticationRequest> CreateRequests(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy);

        ActionResult AjaxDiscovery(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy);

        ActionResult ProcessAjaxOpenIdResponse();

        IAuthenticationResponse GetResponse();

        IAuthenticationResponse GetResponse(HttpRequestInfo request);
    }

    /// <summary>
    /// A wrapper around the standard <see cref="OpenIdRelyingParty"/> class.
    /// </summary>
    public class OpenIdRelyingPartyService : IOpenIdRelyingParty
    {
        /// <summary>
        /// The OpenID relying party to use for logging users in.
        /// </summary>
        /// <remarks>
        /// This is static because it is thread-safe and is more expensive
        /// to create than we want to run through for every single page request.
        /// </remarks>
        private static OpenIdAjaxRelyingParty relyingParty = new OpenIdAjaxRelyingParty();

        /// <summary>
        /// Initializes a new instance of the <see cref="OpenIdRelyingPartyService"/> class.
        /// </summary>
        public OpenIdRelyingPartyService()
        {
        }

        #region IOpenIdRelyingParty Members

        public Channel Channel
        {
            get { return relyingParty.Channel; }
        }

        public IAuthenticationRequest CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy)
        {
            return this.CreateRequests(userSuppliedIdentifier, realm, returnTo, privacyPolicy).First();
        }

        public IEnumerable<IAuthenticationRequest> CreateRequests(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy)
        {
            if (userSuppliedIdentifier == null)
            {
                throw new ArgumentNullException("userSuppliedIdentifier");
            }
            if (realm == null)
            {
                throw new ArgumentNullException("realm");
            }
            if (returnTo == null)
            {
                throw new ArgumentNullException("returnTo");
            }

            var requests = relyingParty.CreateRequests(userSuppliedIdentifier, realm, returnTo);

            foreach (IAuthenticationRequest request in requests)
            {
                // Ask for the user's email, not because we necessarily need it to do our work,
                // but so we can display something meaningful to the user as their "username"
                // when they log in with a PPID from Google, for example.
                request.AddExtension(new ClaimsRequest
                {
                    Email = DemandLevel.Require,
                    FullName = DemandLevel.Request,
                    PolicyUrl = privacyPolicy,
                });

                yield return request;
            }
        }

        public ActionResult AjaxDiscovery(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy)
        {
            return relyingParty.AsAjaxDiscoveryResult(
                this.CreateRequests(userSuppliedIdentifier, realm, returnTo, privacyPolicy)).AsActionResult();
        }

        public ActionResult ProcessAjaxOpenIdResponse()
        {
            return relyingParty.ProcessAjaxOpenIdResponse().AsActionResult();
        }

        public IAuthenticationResponse GetResponse()
        {
            return relyingParty.GetResponse();
        }

        public IAuthenticationResponse GetResponse(HttpRequestInfo request)
        {
            return relyingParty.GetResponse(request);
        }

        #endregion
    }
}

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) Simbient
Australia Australia
Darren Weir is a senior .NET developer working for Simbient in North Sydney, Australia.

My blog is located at dotnetdarren.wordpress.com

Comments and Discussions