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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:55:00+00:00 2026-06-01T13:55:00+00:00

I have a image gallery like Google+ or Facebook and i want to avoid

  • 0

I have a image gallery like Google+ or Facebook and i want to avoid that a unauthorized person can show a image if he contact on other way the controller (../GetImage/test).

The image is saved on the file system and the path to the image in the database.

A user can only show a image, when the image is public or shared with the user. I want to avoid a SQL query (to check if the user can show the image) on a request to the controller (../GetImage/test), because i dont think, that is a good practice, when i want to load 500 images in one time.

Is there a better practice to check, if the user is authorized to show the image?

  • 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-01T13:55:02+00:00Added an answer on June 1, 2026 at 1:55 pm

    You need to build your data model so that your request for the image contains joins to your authorization system, this way you cannot access an image that you are not authorized to, and it happens in a single query.

    Since I don’t know how your data model is structured, I can only give you a basic exampl, and I assume you’re using Entity Framework for your data access.

    public string GetImage(int id) {
        using (var db = new DataEntities()) {
            return imagePath = (from i in db.Images 
                            where i.AuthorizedUsers
                            .Any(x => x.UserName == User.Current.Name)
                            && i.id == id
                            select i.ImagePath).FirstOrDefault();
        }
    }
    

    Of course this won’t prevent unauthorized users from getting the image if they have the URL to the image, so you would need to return the image directly, not just the path.

    So something like this:

    public ActionResult GetImage(string id) 
    { 
        // code from above
    
        var dir = Server.MapPath("imagePath"); 
        return base.File(path, "image/jpeg"); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what i want to do is that i have a nice image Gallery which
I have a simple image gallery that I've paginated, and I want to to
I would like to have a scrollable image gallery that takes up most of
I my working on the site that will have image gallery. Designer idea was
I have an image gallery that I created by reading the contents inside a
I have an image gallery app that has a slider to control the width
I have a table for image gallery with four columns like: foid | uid
I'd like to create a jQuery image gallery of showcased products. It will show
I have an image gallery that, at the moment, displays only images. I would
Is there any javascript, css, ajax product gallery (even paid) that would have image

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.