Owin Middleware

152 views Asked by At

I have written a custom owin middleware for two factor authentication, but sometimes it happens HttpContext.Current.Session throws an exception of object reference is not set to an instance of an object, when it checks for new session.

I checked HttpContext.Current is null, it always works on Chrome, sometimes in IE, but not on Mozilla

2

There are 2 answers

0
Shyam Sa On BEST ANSWER

You can refer the following link-http://vegetarianprogrammer.blogspot.in/2012/12/understanding-synchronizationcontext-in.html

You can add the following key in your config.

<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
0
Anubhav Agrawal On
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />

After investigation I found the solution, so that context wouldn't be null. This will not make the context null when using async method.