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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:20:22+00:00 2026-06-18T09:20:22+00:00

I have this: [AllowAnonymous] public FilePathResult GetImage(string user) { var path = AppDomain.CurrentDomain.BaseDirectory +

  • 0

I have this:

[AllowAnonymous]
public FilePathResult GetImage(string user)
{
    var path = AppDomain.CurrentDomain.BaseDirectory + "files\\uploads\\users\\" + user + "\\avatar\\";
    var ext = this.GetImageExtension(path, user);
    return ext != null ? File(path + user + "." + ext, "image/" + ext, user + "." + ext) : File(AppDomain.CurrentDomain.BaseDirectory + "files\\commonFiles\\users\\avatar\\noavatar.png", "image/png", "noavatar.png");
}

And inside my views I have this:

<img src="/MyAccount/GetImage/?user=@User.Identity.Name" 
     alt="@User.Identity.Name" />

Now, whenever I use this inside my web developer server it works perfectly ok. But when I publish my site on my server, it is not even trying to hit that action. Why?

  • 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-18T09:20:23+00:00Added an answer on June 18, 2026 at 9:20 am

    Why?

    Because you have hardcoded the url to your controller action instead of using an url helper:

    <img src="@Url.Action("GetImage", "MyAccount", new { user = User.Identity.Name })" alt="@User.Identity.Name" />
    

    You should never hardcode urls in an ASP.NET MVC application but always use url helpers.

    Also passing the currently logged in user as query string parameter looks like a horrible security issue. There’s nothing preventing the user from passing whatever username he likes and consulting the images of that user. You should read the currently authenticated user in your controller action.

    So start by getting rid of this query string parameter:

    <img src="@Url.Action("GetImage", "MyAccount")" alt="@User.Identity.Name" />
    

    and then in your controller action you could always retrieve the currently logged in user with the User.Identity.Name property:

    [Authorize]
    public FilePathResult GetImage()
    {
        string user = User.Identity.Name;
        var path = Server.MapPath(
            string.Format("~/files/uploads/users/{0}/avatar/", user)
        );
        var ext = this.GetImageExtension(path, user);
        if (string.IsNullOrEmpty(ext))
        {
            return File(
                Server.MapPath("~/files/commonFiles/users/avatar/noavatar.png"), 
                "image/png", 
                "noavatar.png"
            );
        }
        var file = Path.ChangeExtension(Path.Combine(path, user), ext);
        return File(file, "image/" + ext, user + "." + ext);
    }
    

    I’ve also decorated this controller action with the [Authorize] attribute to make it accessible only to authenticated users. If this is not your case you could still keep the [AllowAnonymous] attribute but check for User.Identity.IsAuthenticated before attempting to access his username.

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

Sidebar

Related Questions

Have this scenario: public class Base { public string Name; } public Class ClassA
I have this function: public static string Join(this IEnumerable<string> strings, string separator) { return
I have this string 2012-06-27 16:17:06 and I want to convert it to GMT
I have this class: Class B { private String D; private String E; }
I have a User area and inside this I have the following registered: context.MapRoute(DefaultRedirect,
I have the following methods responsible for login authentication: [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult
I have set a global Authorize for this Windows-Integrated MVC4 web site: public static
Have this code: var gradient = ctx.createLinearGradient(0,0, 20, 0); gradient.addColorStop(0.8, rgb(250,250,0)); gradient.addColorStop(1, rgb(150,150,0)); ctx.fillStyle
I have this code for converting a byte[] to float[] . public float[] ConvertByteToFloat(byte[]
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt

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.