Need to restrict AD users - Windows Authentication in ASP.NET

I have a website which uses Windows Authentication. I need to restrict access to only a few users, who are present in a local database. How can I achieve it? Example DB has "domain\user1", only user1 should be allowed. "domain\user2" should not be allowed.

Thanks in advance

Answers


in your controller class, you can use the [Authorize] attribute to restrict access.

If you use it by itself, then you restrict the entire controller to only authenticated users.

If you want specific users to access a controller, you can add parameters to the Authorize attribute, such as:

[Authorize(Roles ="Administrators")]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

In the example above, I'm restricting the use of the homecontroller to administrators only, I can also give access only to specific users:

[Authorize(Users = "user1")]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

You can also apply this to specific methods in your controller


Need Your Help

Skipped Code causing program to end early

java block volume calculator

I am currently trying to create a volume, Area, Surface Area, and perimeter calculator but I have run into little problem

Access to a different Controller

php symfony controller

I want to access to my TestControler in DefaultController. So I've create a new instance, but the container is null. If I want to call a method, symfony throws a FatalErrorException: