1
votes

I'm developing an ASP.NET MVC application (targetFramework 4.5) that provides user to login to the site using Custom Authentication as well as using their Twitter account. The following libraries have been referenced

  1. Microsoft.Owin
  2. Microsoft.Owin.Host.Security
  3. Microsoft.Owin.Security
  4. Microsoft.Owin.Security.Cookies
  5. Microsoft.Owin.Security.MicrosoftAccount
  6. Microsoft.Owin.Security.OAuth and
  7. Microsoft.Owin.Security.Twitter

When I click the twitter button in my web page, it takes to the twitter site, gets my credentials and back to my site. No issues here.

i 'm now integrating RedisSessionStateProvider.cs for managing session using Redis. I have added the provider file (RedisSessionStateProvider.cs) and I have updated the web.config file as follows:

<sessionState cookieless="false" customProvider="RedisSessionStateProvider" mode="Custom" timeout="20">
  <providers>
    <add name="RedisSessionStateProvider" port="6379" server="localhost" type="RedisProvider.SessionProvider.CustomServiceProvider" writeexceptionstoeventlog="true" />
  </providers>
</sessionState>

Redis server is running and is listening on port 6379. Now if I click the Twitter button, the site takes me to the twitter authentication page and after successfully authenticating from twitter, when the callback method

public async Task ExternalLoginCallback(string returnUrl)

is fired, the code

await AuthenticationManager.GetExternalLoginInfoAsync();

is returning null.

If I comment out the sessionstate node from the config file, everything is working fine i.e. the GetExternalLoginInfoAsync() is returning the loginInfo correctly.

I'm not able to identify the root cause of this issue. Can anyone please guide me in addressing this issue?

Thanks, Hemant.

1

1 Answers

1
votes

I have same issue. I think there is a bug in RedisSessionStateProvider implementation. For now, i have a temp resolution:

[AllowAnonymous]
public ActionResult Login(string returnUrl)
{            
    // TODO: RedisSessionState provider will not works if remove it.
    Session["hook-init-redis"] = DateTime.Now.ToString();

    ViewBag.ReturnUrl = returnUrl;
    return View();
}

So, you should write shomething to Session, before external login will be called.