Relative paths on Application Error page

M

MattC

I have the following in the Page_Error method of my base class for my aspx
pages.

public void Page_Error(Object sender, EventArgs e)
{
Server.Transfer(Request.ApplicationPath + "/Error.aspx");
}

This works fine, however Error.aspx has some images on it that are document
relative, but if a page causes an error that is not in the same path as
Error.aspx then the image urls are wrong as the Server Context takes the
path from the location of the path that threw the error. I cant make the
urls root relative as this still wont work as the path moves and I also cant
have the full path as when deployed the root virtual directory may have a
different name.

I was trying to do something like this:

<LINK href='<%#AppPath("styles/style.css")%>' type="text/css"
rel="stylesheet" >

protected string AppPath(string file)
{
return Request.ApplicationPath + "/" + file;
}

but the output is:
<LINK href="" type="text/css" rel="stylesheet" >

MattC
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top