You must Sign In to post a response.
  • Category: ASP.Net MVC

    Role based authorization in mvc 5

    Hi All,

    I have roles in my employee table like Admin, HR, User, Manager.. I need to implement the MVC 5 web application with authorization in controller as well method level for those roles.

    Any one suggest me how implement this or share me the best links for this.

    Regards,
    KotiReddy.
  • #766205
    Hi,
    Please find 2 best articles on 'role based authorization with ASP.NET MVC 5' with whole code from this URL's:
    http://www.codeproject.com/Articles/799571/ASP-NET-MVC-Extending-ASP-NET-Identity-Roles
    http://www.dotnetcurry.com/aspnet-mvc/1102/aspnet-mvc-role-based-security
    You must have to use the 'Identity 2.0 Framework', if you are going to follow code given on above URL's.

  • #766213
    for role based authentication you need to create a view for creating Roles for the application, To do so, in the Controllers' folder add a new Empty MVC controller of name RoleController, In the Models folder of the project, add an IdentityModel.cs class file. This contains ApplicationDbContext class which is used to connect to the database where the Users and Roles Table will be created. The class file AccountViewModels.cs contains classes for Login, Register, etc.
    for more details switch to below link
    http://www.dotnetcurry.com/aspnet-mvc/1102/aspnet-mvc-role-based-security

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #766216
    Hi
    shashi & PRasad

    I refer this url
    http://www.dotnetcurry.com/aspnet-mvc/1102/aspnet-mvc-role-based-security

    But this source build not properly. So can you fixed them


    This is error
    ==================
    1.Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'IAppBuilder' could not be found (are you missing a using directive or an assembly reference?)


    2.Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'BundleCollection' could not be found (are you missing a using directive or an assembly reference?)


    3.Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'StyleBundle' could not be found (are you missing a using directive or an assembly reference?)

    I tried Restore Nuget Package same Issue Came.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766242
    Hi,
    You are facing these errors because you don't have references of libraries 'Microsoft.Owin' and 'System.Web.Optimization' to your solution.

    For Error 1:
    A) Run the following command in the Visual Studio Tools==> Library Package Manager==> Package Manager Console
    PM>Install-Package Microsoft.Owin /*For new installation*/
    OR
    PM>Update-Package Owin -Reinstall /*For updation*/
    B) Inside code add these references:
    using Microsoft.Owin;
    using Owin;

    For Error 2 & 3:
    A) To install Microsoft ASP.NET Web Optimization Framework, run the following command in the Visual Studio Tools==> Library Package Manager==> Package Manager Console
    PM> Install-Package Microsoft.AspNet.Web.Optimization /*For new installation*/
    OR
    PM> Update-Package Microsoft.AspNet.Web.Optimization -Reinstall /*For updation*/
    B) Inside code add this reference:
    using System.Web.Optimization;

  • #766244
    hi

    shashi

    can you fixed this again one error come


    HTTP Error 500.23 - Internal Server Error
    An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

    Most likely causes:
    This application defines configuration in the system.web/httpHandlers section.

    Things you can try:
    Migrate the configuration to the system.webServer/handlers section. You can do so manually or by using AppCmd from the command line. For example, from the IIS Express install directory, run appcmd migrate config "Default Web Site/". Using AppCmd to migrate your application will enable it to work in Integrated mode. It will continue to work in Classic mode and on previous versions of IIS.
    If you are certain that it is OK to ignore this error, it can be disabled by setting system.webServer/validation@validateIntegratedModeConfiguration to false.
    Alternatively, switch the application to a Classic mode application pool. For example, from the IIS Express install directory, run appcmd set app "Default Web Site/" /applicationPool:"Clr4ClassicAppPool". Only do this if you are unable to migrate your application.

    Detailed Error Information:
    Module ConfigurationValidationModule
    Notification BeginRequest
    Handler ExtensionlessUrl-Integrated-4.0
    Error Code 0x80070032
    Requested URL http://localhost:62439/
    Physical Path E:\Test\88\role-security-mvc5-master\A11_RBS
    Logon Method Not yet determined
    Logon User Not yet determined
    Request Tracing Directory

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766260
    Hi,
    Add these keys in your web.config:

    <configuration>
    <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>
    </configuration>

    If still problem exist then:
    Click on your Website Project in visual studio.
    Then Click on Property pane.
    You will find 'Managed Pipeline Mode' option==> change its value from 'Integrated' to 'Classic'

    If still problem exist then:
    1. Open IIS==> Select the Server==> Applocation Pools
    2. Select the application pool that your asp.net website is running under==> Click on 'Advanced Settings' from the right hand pane.
    3. Inside Advanced Settings==> General==> Managed Pipeline Mode, select "Classic"
    4. Restart IIS.


Sign In to post your comments