5

I'm using OWIN to authenticate with Facebook per: http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on

I want to be able to redirect to a specific login page when a user attempts to visit a page while they are unauthenticated.

As it stands, when I decorate an action with [Authorize], I get a 401 error from IIS.

If I was using Forms authentication, I would have this in my web.config:

<authentication>
  <forms loginUrl="~/Account/Login" timeout="2880" />      
</authentication>

Is there something similar I can do with OWIN, or do I need to create a custom Authorize attribute?

1 Answer 1

5

You can configure the login page when you are configuring the cookie authentication:

        app.UseCookieAuthentication(new CookieAuthenticationOptions {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.