I am using a global filter in order to determine if a user is allowed to access a certain page/controller. I haven’t been able to get a lot of tread of this as I’m not able to do a simple session variable creation. Here is my simplified code:
public class MyActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext context)
{
context.HttpContext.Session.Add("asdfasdf", 1234);
//Check if user is authorized in db
//...
base.OnActionExecuted(context);
}
}
Error:
System.Web.HttpException: Failed to login to session state SQL server for user '<USERNAME>'.
If I comment out Session.Add the application works fine. It’s strange because the error given is completely unrelated (I think). How do I get my session variable to work in this case? Better question, is this the correct way to go about user authentication?
It seems that your application is configured to use SQL Server
session statepersistence. And you have a problem with the connection string in your web.config.If you want to use SQL Server session state persistence make sure that you have
correctly configuredyour database and specified correct connection string to it:If you don’t want to use SQL Server to persist your sessions you could switch back to InProc mode: