Page and Images not found on Localhost

J

John Kotuby

Hi all,

Maybe this is a simple problem found in ASP.NET 2.0 course 101, but I must
have missed it. When I create a page in Visual Web Developer and use URLs
like "/images/picture.gif " or a link like <a
href="../../Search/page.aspx">,
everything works fine as long as I publish the site to a root web like
http://localhost.

However, I am developing on my local C drive in c:\development\project. I
have created a virtual web site from that folder in IIS. To access it I type
in http://localhost/project.

Here's the problem. When I try to either run the website in IE7 using
http://localhost/project or debug the website from within VS2005, either on
the "default site" or the selected site http://localhost/project, I lose all
my images, stylesheets and even end up with broken links. But on a Root
website evrything is fine.

For example I get 404 File not found http://localhost/search/page.aspx, when
the resource is actually at http://localhost/project/search/page.aspx.

I have tried using "~/images/picture.gif" and that doesn't work either...
same with the URL paths.

Somebody said I had to create a virtual Domain out of the
c:\development\project folder, but I don't know what he meant. Also, it
takes forever to "publish' the website to the root server. It would be so
much faster if I could just debug in the development folder right after
making and compiling a change.

Thanks to all....
 
M

Mark Fitzpatrick

Keep in mind, a virtual directory doesn't make it the root of a site. You
have to ensure that your directory is marked as an application. To do this
go into the management control console (MMC) for IIS. Find the directory,
right-click on it and select properties. Make sure that under the Home
Directory there is an application created in the Application Settings area.
If not, click the create application button.

ASP.Net doesn't care what the directory is, but if it's not marked as an
application it looks to the root application or the one immediately above it
for URL references as well as the bin directory.
 
J

Juan T. Llibre

re:
"/images/picture.gif"
I have tried using "~/images/picture.gif" and that doesn't work either...

"~/images/picture.gif" does work...

That will resolve to the right directory whether you're in the root app or in a subdirectory,
provided the directory exists within the application, of course.

You cannot use the root directory's images directory for virtual apps.

Each app should have its own images directory, and using "~/images/picture.gif"
will resolve the correct path to the application's images directory.

The same is valid for other application directories as well.
 
J

John Kotuby

Mark,

Thanks again...

I created an application in IIS manager for the c:\Development\Project
virtual web folder and the application name came back as "Project".

I still need to reference http://localhost/project to get to the default
page, it appears. And still the links are broken.

Should I be able to access the site now without using "localhost" in the
URL, or does creating an application set the Root of the site as the
"Project" folder?

It seems that VS2005 is still looking at //localhost as the Root folder.
Driving me nuts... but I can continue to work by publishing the site to the
root of another IIS server in the office.

.... John
 
G

George Ter-Saakov

Yep, This is such problem.

When you developing your application it's usually a subfolder on your local
IIS. But when you move to production it usually works of the root of the
IIS.

I have developed an ISAPI dll that helps me with that problem

basically what it does is maps your project name to the folder. So when you
hit
http://myproject/mypage.aspx it hits in reality
http://localhost/mypoject/mypage.aspx
You will need to make some changes to your windows HOSTS file so the name
myproject becomes available.

Read more and get that DLL from
http://www.codeproject.com/aspnet/Multisite.asp

You will need to invest a bit time into reading the article on how to setup
DLL correctly but in the end it works like a charm.


George.
 
G

George Ter-Saakov

Yep, There is such problem.

When you developing your application it's usually a subfolder on your local
IIS. But when you move to production it usually works of the root of the
IIS.

I have developed an ISAPI dll that helps me with that problem

basically what it does is maps your project name to the folder. So when you
hit
http://myproject/mypage.aspx it hits in reality
http://localhost/mypoject/mypage.aspx
You will need to make some changes to your windows HOSTS file so the name
myproject becomes available.

Read more and get that DLL from
http://www.codeproject.com/aspnet/Multisite.asp

You will need to invest a bit time into reading the article on how to setup
DLL correctly but in the end it works like a charm.


George.
 
G

George Ter-Saakov

Yep, There is such problem.

When you developing your application it's usually a subfolder on your local
IIS. But when you move to production it usually works of the root of the
IIS.

I have developed an ISAPI dll that helps me with that problem

basically what it does is maps your project name to the folder. So when you
hit
http://myproject/mypage.aspx it hits in reality
http://localhost/mypoject/mypage.aspx
You will need to make some changes to your windows HOSTS file so the name
myproject becomes available.

Read more and get that DLL from
http://www.codeproject.com/aspnet/Multisite.asp

You will need to invest a bit time into reading the article on how to setup
DLL correctly but in the end it works like a charm.


George.
 
R

Ray

Just remove the forward slash that you have there before
"images", so it goes based on the existing directory structure
instead of the root.
 
M

Mark Fitzpatrick

You'll always have to address it as localhost, that simply is the name of
the local loopback adapter and just represents the ip address 127.0.0.1.
When you set the project directory in IIS to be an application, then it is
the root for anything under it. In the scenario where projectA is an
application, but projectB isn't set as an application, the root of projectA
resolves to localhost/projectA. For projectB it would be localhost since the
root application is the first application in the hierarchy.

You shouldn't need to publish to the root if the links and images are
crafted correctly. For links you'll need to either use completely relative,
or use the ~/ to denote it as relative to the application root, but also you
must make sure that the runat="server" attribute is set. A URL such as
/images tells it to use the root from the domain name or IP address, not the
root from the application.
 
G

George Ter-Saakov

Well, there are 2 problems with this approach.

1. ~/ does not work for images (or any other HTML tag) if they are not
declared as server controls. And to make every image a server control is
simply an overkill.

2. If you are not using absolute path (means the one that starts with / )
then you going to have a problem with the user controls or Master pages that
are used in 2 pages in different subfolders. Which is usually a case for a
mid size project when you try to partition your pages into separate
subfolders.



George.
 
J

John Kotuby

Wow George,

You definitely see the problem I'm having. My project is built almost
entirely from User Controls and MasterPages in different folders. VS 2005
sometimes applies relative paths to images "..\..\images\picture.gif" in the
User Controls (separate folder) and other times "/images/picture.gif".
I didn't know that even images could be declared as server controls. But
here is where it gets sticky. If I use the Style attribute like in
style="backgound-image:url(/images/picture_bg_200.gif)", how do I declare
the image reference as a server control, even though the container might be
declared runat="server". Actually, come to think of it that particular code
is in a table cell, which may not have been declared as a server control.

Also there are Class attributes which contain the same type of CSS syntax.

I designated the "project" folder as an application in IIS. The Login screen
which is in "c:/development/project/accounts/" folder does not display the
images when they are declared as "~/images/picture.gif ", but does display
them as "/images/pipcture/gif".

You can see the source of my confusion.

Thanks.. I have yet to implement the DLL I got from you. I may do that this
morning.
 
G

George Ter-Saakov

Yep, as i said pretty much any mid size project going to have problems like
that. And i happened to work on couple like that.

Anyway fee free to hit my email if you have any question about my
multisite.dll.
My email [email protected] (remove dollar signs)


George
 
L

Larry Bud

You definitely see the problem I'm having. My project is built almost
entirely from User Controls and MasterPages in different folders. VS 2005
sometimes applies relative paths to images "..\..\images\picture.gif" in the
User Controls (separate folder) and other times "/images/picture.gif".
I didn't know that even images could be declared as server controls. But
here is where it gets sticky. If I use the Style attribute like in
style="backgound-image:url(/images/picture_bg_200.gif)", how do I declare
theimagereferenceas a server control, even though the container might be
declared runat="server". Actually, come to think of it that particular code
is in a table cell, which may not have been declared as a server control.


Here's what I do:

In my user control I write a simple function which returns the
application path and the location of the images:

Function GetAppPath() As String
Dim str As String
str = Request.ApplicationPath & "/images/"
Return str
End Function

Then, in the case of a background image for a table or table cell, I
declare that cell as a server control and give it an ID (obviously).

The page_load for that control, I set the CSS style

menubackground.Style.Value = "background-Image:url(" & GetAppPath() &
"menu_grad1.gif)"

Pain in the ass, yes, but you only have to write it once.

Microsoft really needs to fix this. It needs to be smart enough to
know that when you use a user control which is located in a different
folder from the web form, that the references to the images in the
user control change.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top