Search code examples
c#asp.net-web-apiasp.net-identity

Return a string instead of a view when unauthorized asp.net identity


I'm using ASP.net identity, it allows me to configure to return a view if unauthorized, but now I want to return string instead, so what i need to do ?

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                Provider = new CookieAuthenticationProvider
                {                   
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                },
                ExpireTimeSpan = TimeSpan.FromMinutes(1),
            });

Solution

  • Creates a controller that will return string and place it in LoginPath