Global FIlter in MVC 5 is not working

2

Hello. I'm following the tutorial below with the intention of better understanding the .net Identity authentication process with OWIN.

link

When accessing Home, it should redirect to the auth / login and this is not happening. It's as if you're ignoring AuthorizeAttribute ().

Follow my codes.

Startup.cs

using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using Microsoft.Owin.Security.Cookies;

[assembly: OwinStartup(typeof(DotNetIdentidade.Startup))]

namespace DotNetIdentidade
    {
        public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "ApplicationCookie",
                LoginPath = new PathString("/auth/login")
            });
        }
    }
}

FilterConfig.cs

using System.Web.Mvc;
namespace DotNetIdentidade
{
    public class FilterConfig
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
            filters.Add(new AuthorizeAttribute());
        }
    }
}

Global.asax.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace DotNetIdentidade
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);  
        }
    }
}

Thank you.

    
asked by anonymous 22.09.2014 / 22:39

1 answer

2

After restarting the pc, the code worked as expected. I believe it has something to do with restarting IIS Express as there have been changes to Global.asax after the first run.

    
24.09.2014 / 00:34