Problems with [Authorize] custom

1

I have a% custom [Authorize] that extends from AuthorizeCore in which I do a validation to return a true or false , until there all right, if I enter my page and I'm not logged in, it redirects me to my default page.

But when doing a post of some form this does not work, it simply does not do anything, it was debugging the code and it effectively enters the validation and returns what should return but does not redirect to where it should, but it does not do anything.

Who knows why this happens or am I wrongly applying [Authorize] ?

public class MyAuthorization : AuthorizeAttribute
{
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        bool isNotValid = true;
        if (isNotValid )
            return false;

        return true;
    }
}
    
asked by vcasas 26.06.2018 в 16:24
source

2 answers

0

[Authorize] is an attribute that is included within the namespace System.Web.Mvc , if you want to use a custom attribute and you can use it where you want it should be as annotation in a controller.

For example, if your authorization attribute is called MyAuthorization :

public class HomeController : Controller
{
    [MyAuthorization ]
    public ActionResult Index()
    {
        return View();
    }
}

In this way, when entering the action Index() , the class MyAuthorization will be called first.

    
answered by 27.06.2018 в 18:35
-1

have you applied the authorize in the views?

<a href="<%=  @Url.Action("Home","Home") %>">


                        </div>

                        <% if (HttpContext.Current.User.IsInRole("Usuario comun o admin"))
                            { %>
                        <div class="collapse navbar-collapse " id="bs-example-navbar-collapse-1">


                            <ul id="navegacion" class="nav navbar-nav ">
    
answered by 27.06.2018 в 17:07