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

    Custom authentication and authorization in mvc 5 application

    Hi,

    I have 2 tables in my database. 1)EMP(Id,Name,Password,RoleID)
    2)Roles(Id,Description). I have 3 records in my emp tables who is having the roles ADMIN,SemiAdmin,User.

    I have 3 links like page1,page2, page3 in home page. I want to show 3 links( page1,page2, page3) for Admin,2 links(page2, page3) for SemiAdmin and 1 link(page3) for user.

    Any one suggest me how to implement authentication and authorization in mvc 5 application.

    Regards,
    KotiReddy
  • #766277
    Hi
    Created Table Structure follow this

    Employee Table


    Create Table EMP
    (
    Id primary key identity(1,1),
    Name varchar(50),
    Password varchar(50),
    RoleID INT
    )


    Roles Table Script


    Create Table Roles(
    Id primary key identity(1,1),
    Description varchar(20)
    )


    after then CREATE EDMX corresponding table then retrieve data and restricted them.

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

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

  • #766304
    Hi,

    In one of my article I explore how to perform Form Authentication in MVC architectural pattern. I share you that knowledge with you, may be this will helpful to you.

    1) Create AuthenticationController and Login action method
    2) Create Model & View,
    3) Enable Forms Authentication

    <system.web>
    <authentication mode="Forms" >
    <forms loginUrl="Authentication/Login"></forms>
    </authentication>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    </system.web>


    4) Make Action method secured

    [Authorize]
    public ActionResult Index()
    {
    //your action here
    }


    These are the basic steps to create Authentication and apply the same in your Action, refer below link for more details about the same.

    http://www.dotnetspider.com/resources/46249-Forms-Authentication-in-ASPnet-MVC-with-sample-Application.aspx

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments