Book Image

SignalR: Real-time Application Development - Second Edition

By : Einar Ingerbrigsten
Book Image

SignalR: Real-time Application Development - Second Edition

By: Einar Ingerbrigsten

Overview of this book

Table of Contents (19 chapters)
SignalR – Real-time Application Development Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
11
Hosting a Server Using Self-hosted OWIN
Index

The great finale


Now, the final piece of the puzzle. SignalR uses the underlying credential information found on threads in .NET. This means we will have to populate this information based on the cookie generated by our security handler. For this, we're going to need Global Application Class. Right-click on the web project and navigate to Add | New item. Select Web and then select Generic Handler. Give it the name Global.asax:

  1. If the request coming in is authenticated, we want to get the cookie and decrypt it. From this, we want to put the identity into the HttpContext. Open the Global.asax.cs file and make the Application_AuthenticateRequest method look like follows:

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        if( HttpContext.Current.User != null )
        {
            if( Request.IsAuthenticated == true )
            {
                var ticket = FormsAuthentication.Decrypt(
                    Context.Request.Cookies[FormsAuthentication.FormsCookieName].Value);
         ...