images not showing on dev-machine

J

Jurjen de Groot

I'm developping a web-app using VS2008 (Pro edition) on a Vista Ultimate
machine
..
For some reason images aren't shown, the only thing shown is the little
square with the circel, triangle and square in it.

Even if I set the ImageURL property in my Page_Load and set it to the
absolute path of the image, it doesn't show.
I have also tried using '~/Images/58.jpg' '/Images/58.jpg' 'Images/58.jpg'
but still the same result.

It's real annoying if something this simple just won't work.

Has anyone encountered this and maybe have some sort of solution for it ?

TIA,
Jurjen.
 
G

Guest

I'm developping a web-app using VS2008 (Pro edition) on a Vista Ultimate
machine
.
For some reason images aren't shown, the only thing shown is the little
square with the circel, triangle and square in it.

Even if I set the ImageURL property in my Page_Load and set it to the
absolute path of the image, it doesn't show.
I have also tried using '~/Images/58.jpg' '/Images/58.jpg' 'Images/58.jpg'
but still the same result.

It's real annoying if something this simple just won't work.

Has anyone encountered this and maybe have some sort of solution for it ?

TIA,
Jurjen.

Ensure that images are appropriately stored and accessible when you
type the full url in the address bar, e.g.

http://localhost/Images/58.jpg (if site is located under root)

if images are there but you can't see them, it could be a permissions
issue, or a format problem
 
J

Juan T. Llibre

Does the account ASP.NET runs as have file permissions to access the images ?
 
J

Juan T. Llibre

re:
!> I thought that since it is visible in vs2008 and not in IE that it might be
!> a security problem, but I've given read rights to the image folder to
!> 'Everyone' so that shouldn't be it.

Giving permissions to 'Everyone' is not enough.
Permissions must be given to the account ASP.NET runs as.

Unless you're impersonating, under XP the right account is the MachineName\ASPNET account.

If you don't know which account ASP.NET runs as, save the following as "identity.aspx" and run it:

identity.aspx:
--------------------
<%@ Page Language="VB" %>
<%@ Import NameSpace = System.Security.Principal %>
<script runat="server">
Sub Page_Load()
Dim tmp As String = WindowsIdentity.GetCurrent.Name()
Label1.Text = "ASP.NET is running as the account : " & tmp
End Sub
</script>
<html>
<head>
<title>What account is ASP.NET running as ?</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" Runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
 
J

Jurjen de Groot

I have taken your advice and found out that my ASPNET account is actually NT
AUTHORITY\NETWORK SERVICE. I have granted this user rights for the Image
folder, but the pictures aren't shown. I've granted this user rights from
the root level of my development folder but still the pictures don't show up
in the page.

I've also tried accessing Image-files through System.IO and reading the
content into a string and that works just fine, so I guess access-rights are
configured ok.

I'm a little lost as to what to do next.


Jurjen.
 
J

Juan T. Llibre

If the ASP.NET account has the necessary permissions,
it's likely that you have a problem in your code.

Can you post the code you use to access the image files ?
 
G

George Ter-Saakov

1. It's wrong to use "~" in urls (or src) if you do not have runat=server.
The reason is that only for HTML tags marked as runat=server src is
processed with .NET and ~ is replaced.

2. "/Image/58.jpg" is called absolute address cause it starts with "/". "/"
means root of the webserver not a root of the project. So most likely you
should have "/ProjectName/Iamge/58.jpg"

3. "Images/58.jpg" is called relative address. Browser resolves it to
absolute address based on where page is.
If page's URL is http://localhost/project/myfolder/mypage.aspx then
"Images/58.jpg" will be resolved to
http://localhost/project/myfolder/Images/58.jpg

So most likely solution to your problem is to specify correct absolute
address for your images
like "/ProjectName/Iamge/58.jpg"

George.
 
J

Jurjen de Groot

Juan,

It's just a very straightforward simple test-page so here it comes. There's
no code in the code-behind.
The weird thing is that the first and second image don't show in the
(vs2008) Designer, but the other 5 do show just fine. When running the page
they are not visible.

Here's the code I used to access an image file, just to make sure that the
'ASPNET' could :

String FileName = MapPath("~/Images/58.jpg");
System.IO.StreamReader sr = new
System.IO.StreamReader(FileName );
String Content = sr.ReadToEnd();
sr.Close();

thanks for your effort,
Jurjen.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs"
Inherits="<namespace>.WebApplication.TestPage" %>
<!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 runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Text="BZP" />&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
<br />
<br />

<asp:Button ID="Button2" runat="server" Text="WebServiceTEst" Visible="True"
onclick="Button2_Click" />
</div>
<img src="/Images/58.jpg" alt="Test " />
<img src="~/Images/58.jpg" alt="Test 2" />
<img src="Images/58.jpg" alt="Test 3" />
<img src="Images/57.gif" alt="Test 4" />
<img src="C:\<ProjectLocation>\Images\57.gif" alt="Test 5" />
<asp:Image ID="test" runat="server" ImageUrl="~/Images/58.jpg" />
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/57.gif" />
</form>
</body>
</html>
 
G

Guest

I've also tried accessing Image-files through System.IO and reading the
content into a string and that works just fine...

Binary read is working.


the first and second image don't show in the
(vs2008) Designer, but the other 5 do show just fine. When running the page
they are not visible.

But browsing in the web browser is not working.

Right?

If the format of the file is correct (it's not a text, or any other
file saved with the .jpg extension) and you can open it in Paint, or
Photoshop, but not in the browser, then it could be a format problem.
There are some situations when browsers (at least IE and FF) cannot
show some jpeg files, if I'm not wrong, in CMYK encoding. In this case
you can save file in RGB to see if this helps.
 
J

Jurjen de Groot

Now that the app is running in test in the field, the images are shown just
fine. It's just really strange that when running local there's problem with
this.
Thanks for all your help on this.


Jurjen
 
J

John Kotuby

Try going into IIS Manager and for your Default Web Site set the Home
Directory to the path on disk where your website resides. For me it is
C:\Development\Project23.net (my current web project).

That will upset some other programs that do web demos on your local machine,
like some 3rd party controls that demonstrate their stuff using the local
web server and expect C:\inetpub\wwwroot to be your home directory, but you
can change it back and forth as needed.

It works well for me and allows me to test and debug my projects as if they
were on the production server.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top