Images are not allowed in asp webapp (C #)

I am working on an asp web application that includes a user logging in about a person, including a person’s image. The part / image file name is stored in the SQL database with the image file name stored in the column NVARCHAR, instead of storing the actual image in the database.

I created the C: \ Images directory in which image files will be stored by the application. The application works correctly because it moves images to this place, but when I open the page on which the details / image will be displayed, the image is never displayed.

I circumvented this during development, having the image stored in a folder that was part of the project, but after the project went to the server, the application refuses to allow the image to be saved in any directories in C:\Inetpub\wwwroot\.

Therefore, I need to find out why the images will not be displayed when they are stored in folders that are not part of the project.

I checked the source of the HTML page, which also points to the correct location and file name:

img id="ctl00_MainContent_CandidateImage" src="C:\Images\applicant11.jpg" alt="Candidate Image" style="border-width:1px;border-style:solid;height:208px;width:208px;" 

Code by page displays the image in code below:

// CandidatePhoto filename retrieved from DB.

CandidateImage.ImageUrl = "C:\\Images\\" + CandidatePhoto;

Does anyone have any ideas?

Hooray!

+5
source share
6 answers

When this is displayed in the browser, you effectively tell it to look on the c: drive to display the image ...

, wwwroot, , , , , , URL .

+6

- /images/bob.jpg , , ... C:\ .

Images/ IIS/ C:\Images , URL- :

CandidateImage.ImageUrl = "~/Images/" + CandidatePhoto;

, .

+3

. , - , , .

+1

, , URL- . , URL- . , , - ,

+1

"c:\images", , . :

  • "/images" - "" , . imageUrl - : "/images/image01.jpg".

  • , , . - "ImageRender.aspx? ID = 123". "c:\images" . At you ImageURL "ImageRender.aspx? ID = [imageID]".

, .

+1

.

It turned out by adding the user SERVERNAME \ IUSER_SERVERNAME with read / write permissions to wwwroot / Images

Then using Server.MapPath ("~ / images") to save the images to a directory on the server

Then just Rendering images from ("~ / Images") + CandidatePhoto, as before.

Thanks again!

+1
source

All Articles