1

I work on this asp.net mvc 3 project and till now we used local resources to simulate real life data. Now due to the progress the project made all resources (images as far as this questions is concerned) are moved to a directory on a remove server.

So until now i had this code in my razor view to display an image on the screen :

<img src= "@Url.Content("~/Content/" + Model[i].FieldValue)" alt="Logo" />

Now I have to use the new directory the path to which you can see in my attempt to renew my code and keep it working with the new set up

<img src= "@Url.Content("\\\\85.53.1.107\\East\\upload\\"+Model[i].FieldValue)" alt="Logo" />

So the actual address is \\85.53.1.107\East\upload\. What is the proper way to change my code to keep displaying the picture? Like now I only see the name of the image without it's extension.

1 Answer 1

2

I think you should use an http request for the url with a web server like

"http://85.53.1.107/East/upload/"

And i would also put this path in the webconfig file so i would not have to repeat this every time i have to use an image, maybe with a custom url extension so the call looks like :

<img src="@Url.ImagePath(Model[i].FieldValue)" />

with this extension :

public static class UrlExtensions
{
  public static string ImagePath(this UrlHelper helper, string imageFileName)
  {
    return helper.Content(string.Format("{0}/{1}", ConfigurationManager.AppSettings["ImagesBasePath"],  imageFileName));
  }
}

and the key in webconfig file :

<configuration>
    <appSettings>
        ...
        <add  key="ImagesBasePath" value="http://85.53.1.107/East/upload/" />
    </appSettings>
</configuration>

And if your application has the rights to access the 85.53.1.107 server, you could set your key with the name of the server :

    <add  key="ImagesBasePath" value="\\NAME_OF_SERVER\East\upload\" />
Sign up to request clarification or add additional context in comments.

1 Comment

In fact the path is the web.config even now but I thought to solve the problem in two steps. You save me time. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.