tags:

views:

316

answers:

3

I'm actually following a tutorial about creating a login page etc for a web project. It all works and now I am working on layout. I have added an image tag to my login page, as simple as , the src is correct, the image is definitely there, but the image will not show up on the page, why??

The image works if I copy and paste the tag into one of the other pages in the project, but not the Login.aspx page!

I must be suffering from 'lack of brains friday' syndrome because this has got me stumped! Maybe I should see if I can get a half-day and go home...

Thanks.

Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="sm_development.Login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;

<head runat="server">
<title>Login Page</title>
</head>
<body>

<form id="form1" runat="server">
<div>
    <img src="images/redflag.png" style="width: 1024px; height: 893px; border: none;
        padding: 0px;" alt="alt" />
    username<br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <br />
    password<br />
    <asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
    <br />
    <asp:Button ID="Button1" OnClick="Button1_Click" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>

So, I added the following to my web.config file under the file, which according to the docs should grant anybody access to the images folder whether they have logged in or not:

<!-- This section gives the unauthenticated user access to all of the files that are stored in the images folder.  -->
    <location path="images">
    <system.web>
        <authorization>
            <allow users ="*" />
        </authorization>
    </system.web>
</location>

I'm actually going to change this in future and reorganize it so that only those images required by pages such as the login etc. are available to all and the rest are protected. Interesting lesson for today!

Thanks for all the replies.

+1  A: 

I can't say for 100% sure without seeing any code or more examples but have you checked permissions?

I was trying to create a custom denied page for a while and couldn't work out why no assets were loading (images, style sheets e.t.c.) and then I realised that I stupidly had the assets in the protected folder and they needed to be on a separate accessible site.

Wil
Which permissions do i need to check? The folder containing the images is in the root of the site development folder and I can access the images from the other pages using the same tag, just not this page.
flavour404
Thanks Wil, I realize what you were alluding to now :)
flavour404
Im new here, don't really understand everything yet but thanks for the teacher status thing :S I will try and explain a bit better in the future!
Wil
+3  A: 

Verify that the image is not in a location that is locked down. You say you can get it to work on other pages, but do you need to login to get to those pages? If so then the fact that you logged in is giving those pages the ability to show the image. When your at the login screen, you are not logged in of course, so the images directory might be secured and therefore not viewable.

Your web.config has probably secured everything from the root so your 'images' directory might require you to be logged in to have access to it.

Have you login.aspx in the root and move all your secured code into a sub directory. Make sure you setup your web.config files correctly.

Kelsey
Yeah, that makes sense and I think this is what Wil was getting at as well. From the <authroization... tag in the web.config file can't I set permissions for certain folders rather than designate a whole new web.config file in the images dir?
flavour404
Found a fix, see above.
flavour404
+1 to your question for updating it with what you did :)
Kelsey
+2  A: 

Do you deny anonymous access to all pages?

You could drop a simple web.config into your images directory to give access to anonymous users, allowing them to view the images before they actually log in.

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"&gt;
    <system.web>
        <authorization>
            <allow users="?" />
        </authorization>
    </system.web>
</configuration>
aprescott
I've had this exact same problem and this was my solution. The only difference was that I wrote <allow users="*" />. "?" means allow unauthorized users whereas "*" means allow all users (unauthorized or authorized). Either way should work fine, though.
Michael La Voie