What is Authorization filter in asp.net MVC?
What is Authorization filter in asp.net MVC?
The information provided here is part of Export Import Training online After the exploration of information technology, the world is on our finger tips to get any piece of information. However when I went through different subjects on the web, I realized, like every thing in society, internet also carries the good and the bad. I was surprised to note that, I could not find any good quality free tutorial program to enter in a good business especially in
Steilla Mitchel
10-Mar-2022Authorization Filter in asp.net MVC :
ASP.NET MVC Authentication filter is runs before other filters or actin methods. Authentication filter is to confirm that the is valid or invalid. These filter implements the interface 'IAuthenticationFilter' and base class 'ActionFilterAttribute'. asp.net mvc filters are used to add extra logic validation at the different level in mvc framework request processing. Authorization filter is used to implement the authentication and authorization for controller action.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Security; namespace Mindstick.Filters { public class Myfilter : FilterAttribute, IAuthorizationFilter { public void OnAuthorization(AuthorizationContext filterContext) { if (filterContext.HttpContext.Request.IsAuthenticated) { if (!Roles.IsUserInRole('Admin')) { ViewResult result = new ViewResult(); result.ViewName = 'Error'; result.ViewBag.ErrorMessage = 'Invalid User Type'; filterContext.Result = result; } } } } }