Results 1 to 3 of 3

Thread: MVC 3: Page Authorization based on Role

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818

    MVC 3: Page Authorization based on Role

    Hi All,

    let say i have this Page and Role required to access it

    Home: PublicRole
    About: PublicRole
    Invoice: PurchasingRole

    i have navigation menu that populate based on user's Role that logon but it doesn't prevent if user type the URL manually..user still can access that Page eventhough user don't have permission to access it

    using AuthorizationAttribute is something that i want to prevent because Admin have the ability to set the Menu based on Role

    authorization article that i found is required user to Logon first before attempt to access the Page, it already done in my scenario

    any insight?
    thx,
    erick

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

  2. #2
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: MVC 3: Page Authorization based on Role

    You can just check the user's roles as the first thing inside each Action method, and redirect if the user is not in the required roles.

    C# Code:
    1. // User object below comes from HttpContext.Current.User
    2. if (!User.IsInRole("PurchasingRole")) {
    3.     return RedirectToAction("Index");
    4. }
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818

    Re: MVC 3: Page Authorization based on Role

    thx tr333

    that will be my last attempt because i will be coding the same code for each page and of course the role won't be hardcoded because the authorization is dynamic..

    arrghhh...

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width