0

In web.config we can set authorization option individually for locations:

<location path="request.ashx">
      <system.web>
          <authorization>
              <allow users="*" />
          </authorization>
      </system.web>
  </location>

How to get this option from code?

Konstantin Zadiran
  • 1,485
  • 2
  • 22
  • 35

2 Answers2

0

Better than using Authorize attribute, i think that using an if condition would be far better.

If(User.Identity.IsAuthenticated)
{
    If(User.Identity.IsInRole=="admin")
    {
        return view("Secret");
    }
    else
    {
            return view("NotAllowed")
    }
}
else
{
    return View("NeedAuth");
}

If user is suddenly redirected to loginpage as in attribute, he may think it as an error in website, but this way you would be able to clearly tell the user that he needs to Authenticate.

It's a trap
  • 1,333
  • 17
  • 39
0

Try This :

public void ProcessRequest(HttpContext context)
    {
        if (HttpContext.Current.User.Identity.IsAuthenticated == false)
        {
            context.Response.Redirect("Your Path");
        }
    }
yousef sami
  • 263
  • 1
  • 11