Ray February 2016

How to authorize using windows authentication in ASP.net 5

I am creating an application which is going to use windows authentication to allow access to page based on user and its roles. I have gone ahead and configured IIS to use windows authentication and disabled anonymous access. I am able to browse the application without any issue and I have successfully enabled windows authentication for the application.

Now I am trying to set access to controller level by using Authorize, but I am unable to figure it out how it works with ASP.net 5. I am completely new to ASP / C# programming platform but I did search online resources and I came across this and I used below example to give it a try but I get red squiggly line under users and I think ASP.NET 5 is unable to find users. I also made sure that I have added all the references at the top.

[Authorize(Users = @"CONTOSO\Rick, CONTOSO\Keith, CONTOSO\Mike")]

References:

using Microsoft.AspNet.Mvc;
using RMDAAutomation.Models.Repository;
using RMDAAutomation.Models.Entity;
using Microsoft.AspNet.Authorization;

Any suggestions is highly appreciated. :)

UPDATE 1:

TutorialsController.cs:

using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Authorization;

namespace RMDAAutomation.Controllers.Web
{
    public class TutorialsController : Controller
    {
        [Authorize(Roles = @"DOMAIN\GROUP")]
        public IActionResult Index()
        {
            return View();
        }
    }
}

Tutorial Index View:

<div class="container">
    <h1>Tutorials</h1>

</div>

Visual studio project settings: enter image description here

Answers


maltmann February 2016

using System.Web.Mvc;

This using solves the issue in my project

Post Status

Asked in February 2016
Viewed 2,581 times
Voted 14
Answered 1 times

Search




Leave an answer