0

When using Cookie Authentication in Dotvvm, I get a Null user exception thrown.

I used the following code in the dotvvm configuration:

    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login")
    });
renanj
  • 21
  • 2

2 Answers2

0

The following Authentication code MUST be in the first line of the Configuration(IAppBuilder app) function and that will get rid of the null user exception:

    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login")
    });
renanj
  • 21
  • 2
0

It is recommended to also set up the Provider property and handle the OnRedirect, otherwise the redirects made by OWIN Security library won't be applied correctly.

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/login"),
    Provider = new CookieAuthenticationProvider()
    {
        OnApplyRedirect = e => DotvvmAuthenticationHelper.ApplyRedirectResponse(e.OwinContext, e.RedirectUri)
    }
});
Tomáš Herceg
  • 1,595
  • 1
  • 13
  • 18