Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Path to one image works but to the other doesn't

I wonder if this is because of IIS and how the site is setup

1. My coworker set up an IIS site like this

User generated image
2. You see there's a path assets-->pages-->img-->login the images in this path aren't showing up. I've tried
/assets/pages/img/login/bg1.jpg,
../assets/pages/img/login/bg1.jpg
~/assets/pages/img/login/bg1.jpg

3. Images under this folder show up "img". This is in the root folder of that "Demo" site. In the image above, I've marked the folder with XX. I have it like this ~/img/CSI-logo.png

When I look at Chrome's console, that path is translated to this (has "demo" in the beginning of it)
User generated image
4. If I hard code the "demo" root folder, then the image shows up /Demo/assets/pages/img/login/bg1.jpg

Why is this?  I don't want to hardcode /Demo/ How can I fix this? what path do I need to use?
Avatar of it_saige
it_saige
Flag of United States of America image

Where is the page you are trying to reference the login image at in the above folder structure?

-saige-
Avatar of Camillia

ASKER

It's under "Views" folder, Index.cshtml

If I have to hardcode ,  I will, but I know that's not the correct solution.

User generated image
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

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
I will soon. It's a simple project. I'll upload it. There's no database behind it.
I uploaded the code here

https://drive.google.com/drive/folders/1EzoyYPCZ8aBT8QWUtwkQoJIufuEaOHAb?usp=sharing

It's an empty MVC code I created and has 2 pages. Login and the main page. It's the images on the main page and one image inside that don't show up.  It's VS2017. The images show up locally when I run the code in VS.

My manager says maybe it's because we're hosting other sites but don't think so. Here's the IIS structure

User generated image
I renamed the "asset" folder as "assets1" but that didn't fix it either.

Maybe my manager is right...maybe this is happening because this site's folder is not in it's separate folder. Maybe some other project in this folder is conflicting. This is how my coworker set it up. Screenshot below.

I can just move it under "img" folder since I know that works but would be good to know why this happening...for my own understanding

 User generated image
@it_sage You asked if there are other webconfigs. In the screenshot above, I see another webconfig and this is in it

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.htm" />
                <add value="index.html" />
                <add value="default.html" />
                <add value="default.aspx" />
                <add value="Default.htm" />
                <add value="Default.asp" />
                <add value="iisstart.htm" />
            </files>
        </defaultDocument>
    </system.webServer>
    <system.web>
        <authentication mode="Forms">
            <forms loginUrl="~/Account/LogOn" />
        </authentication>
        <identity impersonate="false" />
    </system.web>
</configuration>

Open in new window

I moved the entire "assets" folder under "img" folder and that didn't work either. The paths have to have /Demo/ in the beginning of them. Don't know why.

This link https://weblogs.asp.net/fmarguerie/avoiding-problems-with-relative-and-absolute-urls-in-asp-net
to use <%=Request.ApplicationPath%>

but how would do I it in JavaScript?  the path is in login-5.min.js too
This worked but I'll open a new question. I want to know why this worked

~/../assets