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 8764309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:00:14+00:00 2026-06-13T16:00:14+00:00

What options/solutions are there for securing data using Entity Framework? I do not talk

  • 0

What options/solutions are there for securing data using Entity Framework?

I do not talk about forms login and such here, just assume that the users are authenticated or not.

To illustrate, i attached one of my web api controllers and i wonder if this is the way to do it. The reason why i ask is that i wonder if there are easier ways to do this than writing all this logic to what data to expose in all my controllers.

Also, when looking into a system like breezejs and odata where i can add $expand=TrafficImages to my queries, i would not want users to be able to get my hole database.

So to summarize, what ways are there to securing the data exposed such the users cant download sensible data.

[AllowAnonymous]
public object GetTheoryTests()
{
    var identity = ((ClaimsIdentity)((ClaimsPrincipal)HttpContext.Current.User).Identity);
    //if (HttpContext.Current.User.Identity.IsAuthenticated)


   if (!identity.IsAuthenticated)
     return db.TheoryTests.Include(t=>t.TrafficImages).Where(t=>t.PublicAvalible)
            .Select(t => new { Id = t.Id, Title = t.Title, Images = t.TrafficImages }).AsEnumerable();

   if (User.IsInRole("WebAdmins"))
       return db.TheoryTests.AsEnumerable();

    var key = identity.GetProvider();

    var member = db.Members.Include(m=>m.PayedTheoryTests).SingleOrDefault(m=>m.Identities.Any(
        i=>i.identityprovider == key.provider &&
        i.nameidentifier == key.id));
        if(member!=null)
            return db.TheoryTests.Include(t => t.TrafficImages).Where(t => t.PublicAvalible).Select(t => new { Id = t.Id, Title = t.Title, Images = t.TrafficImages }).AsEnumerable();
        else
            return db.TheoryTests.Include(t => t.TrafficImages).Where(t => t.PublicAvalible)
                .Union(member.PayedTheoryTests).Select(t => new { Id = t.Id, Title = t.Title, Images = t.TrafficImages }).AsEnumerable();



}

When thinking about it, what i miss is something like a viewmodel untop of my database depending on the state of the user. Would it be a solution to create two entity frameworks ontop of the same database, one for limited data display and one for more advanced operations?

  • 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-06-13T16:00:16+00:00Added an answer on June 13, 2026 at 4:00 pm

    Meanwhile, until QueryInterceptors arrive, you should take other steps. First, you should look into the techniques for securing a Web API controller or method, a subject beyond the scope of this answer.

    Second, w/r/t $expand, you are quite right to be wary of that feature. You may want to inspect which expansions are requested for some controller methods and/or disallow it altogether for others.

    Fortunately, this is relatively easy to do. You have access to the request query string. You can detect the presence of “$expand” in that string and analyze it if you want to allow certain expansions and forbid others.

    Breeze will add helpers for this in future. You’ll have to process the string until then.

    You may want to create your own action filter for this purpose if you’re up to it.

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

Sidebar

Related Questions

from my research it looks like there are basically 3 options. 1: Using COM
There's X-Frame-Options: SAMEORIGIN header preventing the Apps Script from rendering in a page not
sometimes after logging out and in again, my settings in Tools/Options/Projects and Solutions/VC++ Directories
What options are there for localizing an app on Google App Engine? How do
What options are there to achieve low-latency communication between two wars running in the
It seems most apps are writing custom logic to sync/replicate cloud data, or using
Currently I have 4 solutions that are independent projects, however there is quite a
I'm looking for some cost-effective solutions and/or open source options for generating reports in
Edit: Two options shown below. If you're just using the functionality that an IDisposable
I would like to ask for 3 information here: There is no integrated solution

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.