Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

Assembly Reference Missing - AddMvc() and Authorize - "Policy" attribute

$
0
0

Hi All,

I am trying to implement "Policy" based authorization in my application.  I am using VS 2017 Asp.net MVC and using template Asp.Net Web Application (.Net framework).

1. I am getting error message in Startup.cs file when i added "services.AddMvc()".   Error Message - Iservicecollection doesnot contain definition for AddMvc...  Are you missing a using directive or assembly reference?

Startup.cs
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
}

2. In controller I am adding authorize attribute [Authorize(Policy = "ProjectView")]  and getting error message in "Policy" as The type or namespace name Policy could not found.  Are you missing a using directive or assembly reference?

AccountsController.cs
        [Authorize(Policy = "ProjectView")]
        [HttpGet]
        public ActionResult WelcomeServerAuthorize()
        {

        }

I added Microsoft.Extensions.DependencyInjection and Microsoft.AspNetCore.Authorization assembly but it is still showing the missing assembly reference for AddMvc() and Authorize-Policy attribute.

I am new to Policy based authorization; could you please let me know which assembly I need to add to fix this issue?

Thanks

Selvakumar R


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>