Category Archives: IIS

Upgrading SSL Certificates from SHA1 to SHA2

Posting this morning I noticed the missing green “lock” icon appearing in my Chrome browser. Upon investigating I saw an error similar to the one below:

sha1_minor

The mattlapaglia.com domain certificate was generated before the internet community decided it was time to deprecate the SHA1 hashing algorithm, first released in 1995, in favor of the more secure SHA2.

I got my SSL certificates through ssls.com, powered by namecheap.com, my domain name provider.

In order to regenerate the certificates for IIS 8 the old certificate should be deleted, the new CSR generated, and then used for regenerating the certificate on the ssls website. ssls has changed their service to always generate SHA2 certificates, so no extra options need to be selected.

SignalR with MVC 5

I had some difficulty getting SignalR set up with a recent web application being developeed for a client. Some of the documentation found online were geared towards older versions of SignalR, while others didn’t seem to work with my setup.

I am creating additional functionality for a web client that allows a server to push information to a client when certain events trigger. Being a MVC and HTML5 application I decided to utilize Web Sockets.

  • With Visual Studio 2012 I installed the SignalR nuget package to speed up the installation.
  • I created a Startup.cs file in the project’s App_Start folder placing the following code inside of it:
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Owin;
using Desking.SignalR;

[assembly: OwinStartup(typeof(Desking.Startup))]
namespace Desking
   {
      public class Startup
      {
         public void Configuration(IAppBuilder app)
         {
            app.MapSignalR();
         }
      }
   }
  • SignalR has the ability to dynamically generate the hub js file found at signalr/hub at the applications root used for talking to the server, but the generated file was not minified and I couldn’t find a way to integrate it with MVC’s script bundles I use across the application. I decided instead to take the dynamically generated file and place into a normal js file.
  • At the end of the hub.js file I needed to modify the relative path url
signalR.hub = $.hubConnection("/applicationPath/signalr", { useDefaultPath: false });
  • I created the following hub file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using Desking.Models;

namespace Desking.SignalR
{
    [HubName("deskingHub")]
    public class DeskingHub : Hub
    {
        public void sendNotification(String Name, String Message)
        {
            Clients.Client(Context.ConnectionId).addMessage(Name + ": " + Message);
        }

        public void registerClient(long DeskingDraftRevisionID)
        {
            DealMethods.RegisterClient(DeskingDraftRevisionID, Guid.Parse(Context.ConnectionId));
        }

        public enum Statuses
        {
            FinancingConfirmed = 0,
            NeedManager,
            ReadyForDocuments,
        }
    }
}
  • The registerClient method is used when the client first loads the application by registering and linking the draft id they have opened to the connection ID generated by SignalR. This allows the server to send notifications based on the draft id needing to be notified
  • The following js is included on the initial page load:
function SetupFinancingNotifications() {
    // Declare a proxy to reference the hub. 
    var chat = $.connection.deskingHub;

    // Create a function that the hub can call to broadcast messages.
    chat.client.addMessage = function (message) {
        alert(message);
    };

    // Start the connection.
    $.connection.hub.start().done(function () {
        chat.server.registerClient($('#labelDealStatusQuoteNumber').text());
        $('#sendmessage').click(function () {
            // Call the Send method on the hub. 
            chat.server.sendNotification($('#displayname').val(), $('#message').val());
            // Clear text box and reset focus for next comment. 
            $('#message').val('').focus();
        });
    });
}
  • The js registers itself with the server given the revision id currently opened. The SignalR’s client instance ID is taken from the request context on the server side and isn’t needed to be pass in manually.
  • After the client is set up all that is left to do is create a method that will signal the web client:
public static void NotifyClient(long DealID, DeskingHub.Statuses DealStatus, String Message)
{
   using (CRMEntities db = new CRMEntities())
   {
       DeskingDraftFinancingNotification notification = db.DeskingDraftFinancingNotifications.Where(x => x.DealID == DealID).FirstOrDefault();

       if (notification != null)
       {
           try
           {
               IHubContext notificationHub = GlobalHost.ConnectionManager.GetHubContext<DeskingHub>();

               notificationHub.Clients.Client(notification.ConnectionID.ToString()).addMessage(DealStatus, Message);
           }
           catch (Exception ex)
           {
               ex.LogToElmah();
           }
       }
   }
}

In the future I will need to add more functionality to allow client -> server communication, as well as getting SignalR to function behind a load balancer across 3 servers using the SQL backplane.