Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6646289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:23:54+00:00 2026-05-26T00:23:54+00:00

I have an MVC application which has the (simplified) structure as below (left-to-right) UI

  • 0

I have an MVC application which has the (simplified) structure as below (left-to-right)

UI -> CONTROLLERS -> SERVICES -> REPOSITORIES -> DATABASE

We’ve attempted to keep each layer decoupled from the next. We’re using .NET Membership to manage security, and we have a permissions based function, let’s say “Show me all documents for my user type”.

Should:

  1. The Services layer have no awareness of our .NET Membership provider? We’d then have Service layer methods which looked like “GetDocumentsByUserType(int UserTypeId){ .. }”?

  2. The GetDocumentsByUserType() method be aware that we’re using .NET Membership, use Membership methods to get the current user type, and return the relevant documents?

Also:

  • Does #1 make my Services layer less secure, as my controller layer
    could pass in anything it wanted as a UserType?
  • Does #2 make my Services layer too dependent on a specific technology, namely .NET
    Membership? Is there another way to consider here?

Hope I’ve provided enough details. Please shout if not and I’ll add.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:23:55+00:00Added an answer on May 26, 2026 at 12:23 am

    You should keep all membership stuff inside the presentation (controller) layer. Suppose you ever want to add another presentation layer (or make changes to your existing layer), you’ll have a hard time fixing this. Besides, you are duplicating code between your presentation layer and your services layer, which is never a good idea.

    Having said this, there is no reason not to perform security checks inside your services layer but you can do this without needing to use the membership classes. First of all, the currently authenticated user is available from Thread.CurrentPrincipal (inside your service layer methods). You can use this IPrincipal to perform security checks.

    Second, you can use the PrincipalPermissionAttribute to enforce security rules on your service layer methods or classes. For example:

    [PrincipalPermission(SecurityAction.Demand, Role="Administrator")]
    public void MySecureServiceLayerMethod()
    {
        var p = Thread.CurrentPrincipal;
        ....
    }
    

    For the role stuff to work, you’d also have to use a RoleProvider implementation.

    UPDATE: As Wyatt Barnett explains in a comment, using PrincipalPermission has some disadvantages. First of all, testing your code becomes more difficult. Another (larger) disadvantage is that you hard-code role names into your code. These names are usually not owned by the developer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic ASP.Net MVC 3 application which has a number of controllers
I have this simple MVC 3 application which simply has two controllers(Home and Edit),
I have an MVC application which has a set of fields for contact details
in my MVC application I have a controller (ProjectController) which has an action (create).
I have an ASP.MVC application which has a silverlight app inside. I want to
I have an ASP.NET MVC 2 application, which has an Application_Error event handler in
I have a ASP.NET MVC application which has a view populated with a model
I have a MVC application which has a Controller that has a recursive method
I have an MVC application, which has two areas - Administrator, and User. What
I have downloaded a sample mvc application which has a fair bit of code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.