Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I call SetSessionStateBehavior(SessionStateBehavior.ReadOnly)  in ASP .Net MVC SignalR 2.x application?

Posted on 2014-03-14
1
Medium Priority
?
1,494 Views
Last Modified: 2014-03-18
Hi:

I'm relatively new to the world of SignalR. I've got a couple of questions some of ya'll can possibly help me with.

My question sets are two fold. I've been looking at a chat example and there are a couple of things I'm trying understand.

This sample is built using SignalR 1.x libraries.
The code sample from the Global.asax.c file is as follows:
using System;
using System.Web;
using System.Web.Routing;
using System.Web.SessionState;
 
namespace MyApplication
{
    public class Global : System.Web.HttpApplication
    {
        private static RouteBase hubRoute;
 
        protected void Application_Start(object sender, EventArgs e)
        {
            hubRoute = RouteTable.Routes.MapHubs();
        }
 
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (IsSignalRRequest(Context))
            {
                // Turn readonly sessions on for SignalR
                Context.SetSessionStateBehavior(SessionStateBehavior.ReadOnly);
            }
        }
 
        private bool IsSignalRRequest(HttpContext context)
        {
            RouteData routeData = hubRoute.GetRouteData(new HttpContextWrapper(context));
 
            // If the routeData isn't null then it's a SignalR request
            return routeData != null;
        }
    }
}

Open in new window



Question 1) I'm not clear on the concept of SetSessionStateBehavior being set to ReadOnly. What is the effect of this and why would we do this in the SignalR instance?



Question 2) I've been currently tasked with moving our implementation from the SignalR 1.x to 2.x libraries. How would I replicate this functionality using the 2.x libraries?

Thanks,
JohnB
0
Comment
Question by:jxbma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 27

Accepted Solution

by:
Sammy Ageil earned 2000 total points
ID: 39930242
John,

1- Session state is not supported from within SignalR as it interferes with the processing of simultaneous requests from the same user. In 2.0 HTTPContext.Current.Session property is null because SignalR requests are handled before the session state module is initialized.

2- You don't need to duplicate this behavior anymore as its the default and only behavior for SignalR

for more troubleshooting SignalR issues, see this
http://www.asp.net/signalr/overview/signalr-20/troubleshooting-and-debugging/troubleshooting
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question