Link to home
Start Free TrialLog in
Avatar of brynstar
brynstarFlag for United States of America

asked on

ASP.net images not displaying

Hello All

I am testing some local ASP.net pages, I have never worked with it before as I am a PHP junkie but I thought I  would play around with it.

I have created a new site in Dreamweaver on my workstation pc. I have connected successfully to a SQL server database which sits on my Small business server and I have a page which displays a dataset of company employees.

My problem is the images, I have referenced the images correctly, source code looks fine when I view the page in firefox. I thought it must be something i'm doing wrong so I created a new .aspx page and then dragged an image onto the page statically. When I preview this page, the static image also does not appear, is there something glaringly obvious i'm missing here?

Best Regards
Bryn
Avatar of brynstar
brynstar
Flag of United States of America image

ASKER

Hello again

Its actually a problem with images..period. If i create a HTML page and insert an image, when I preview it in localhost nothing appears.

I am using windows XP iis

Strange, never encountered this before
Avatar of Ted Bouskill
ASP.NET websites have to be configured as a 'web application' which assigns an application pool to the website to run the .NET DLLs.  Right click on the website or folder in IIS then select properties and the 'Home Directory' tab.  On that tab you can "Create" a web application.

As a tip with .NET use standard HTML tags by default and only use ASP.NET server controls when you have to.  Don't add overhead if you don't have to.

Also, don't try to imprint PHP techniques onto .NET.  You'll set yourself up for failure.

Work through the samples on www.asp.net to learn more.  Specifically the QuickStart tutorials.
Avatar of AmarIs26
AmarIs26

With VS 2008 and i think 2005 also you get a development server. So you dont really need IIS to test your pages. IF you ceate a project of type "Website" and it is located on filesystem rather than iis then it will by default run your development server.
Anyways, to correctly reference images, the best way is to start from the root and then find your image.
Even html controls in asp.net can be referenced in code.
So if you are using html image then do the following
<img id="myimage" runat="server" src="~/images/myimage.jpg" alt=""/>
The ~ tilde is important, if your control is runing as a server control then tilde will tell the runtime to assign the root path where the tilde apears.
This way you virtual directory can be anything and your paths will always be valid.
Hello

As i stated the images will not work on a standard HTML page when previewing the page via

localhost/site/page.htm

I originally thought the ASP.net pages were not correctly displaying the images however, as per my second comment I stated standard html pages were not displaying images.

In dreamweaver you can see the image the page but when you preview it, nothing appears. This is not a path problem, and nothing to do with ASP.net pages, just images themselves when using localhost.

any ideas?
I thought it must be something i'm doing wrong so I created a new .aspx page and then dragged an image onto the page statically. When I preview this page, the static image also does not appear, is there something glaringly obvious i'm missing here?

Well your original question mentioned ASPX pages. Anyways, if you are testing it with html pages then you should try the following
localhost/site/page.htm
<img src="images/testimage.jpg" />
this means that in the folder that the "page.htm" is located you must have a folder called images and in the images folder an image called testimage.jpg.
If you have the images folder located in the site folder then you can do this
<img src="../images/testimage.jpg"/>
finally (not advisable) you can always assume your site will be deployed in the same manner so you can use the rooted path
<img src="/site/images/testimage.jpg"/>
Hello Again

Sorry I should probably explain myself more clearly. I have been Web developing for many years, so I know the image tag!

Let me give you an example of my problem

in Firefox
http://localhost/mysite/mypage.htm - no image
file:///C:/Inetpub/wwwroot/mysite/mypage.htm - images show ok
Can you post the source code when the image shows and does not show.
sure

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<img src="pictures/Aaron.linton.gif" alt="" />

</body>
</html>
sorry, previous code when doesnt show. This is when it does

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<img src="pictures/Aaron.linton.gif" alt="" />

</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of AmarIs26
AmarIs26

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are a gentleman and a scholar! Thank you very much!
Thanks again my friend!
You are welcome, i take it that resetting the permissions worked ;)
Indeed it did. Thanks again