Custom error pages .Net [modified]
-
Hi all, I have a custom 404 error page for my site, it is an aspx page as it uses the master template to retain site navigation etc. I have configured the web.config file, and so all un-found pages redirect to my 404 page just fine, but for directories not found it doesn't work, which I get just fine. What I have done then is to change the error page that IIS serves up, telling it to point to my 404 page relative to the site root. This too works fine, but only for urls such as : www.mysite.co.uk/afakedir but for: www.mysite.co.uk/afakedir/ it screws up my links to js files and stylesheets etc. obviously because these are set to be relative to the path, which is changed when a trailing / is added. How do I get round this without putting in absolute links to my js and css files etc? They need to be relative as I don't want to be making changes between my development and live site and obviously the paths would be different. I'm sure i'm not the only person to have this problem, or have tried this, I just can't seem to find a solution that works all round. Any help would be appreciated, even just pointing me in the right direction :) --- What I forgot to mention is that I initially need this to work on iis6, but will need it to work on iis 7.5 also.. Many thanks.. Mark
modified on Tuesday, April 6, 2010 5:02 AM
-
Hi all, I have a custom 404 error page for my site, it is an aspx page as it uses the master template to retain site navigation etc. I have configured the web.config file, and so all un-found pages redirect to my 404 page just fine, but for directories not found it doesn't work, which I get just fine. What I have done then is to change the error page that IIS serves up, telling it to point to my 404 page relative to the site root. This too works fine, but only for urls such as : www.mysite.co.uk/afakedir but for: www.mysite.co.uk/afakedir/ it screws up my links to js files and stylesheets etc. obviously because these are set to be relative to the path, which is changed when a trailing / is added. How do I get round this without putting in absolute links to my js and css files etc? They need to be relative as I don't want to be making changes between my development and live site and obviously the paths would be different. I'm sure i'm not the only person to have this problem, or have tried this, I just can't seem to find a solution that works all round. Any help would be appreciated, even just pointing me in the right direction :) --- What I forgot to mention is that I initially need this to work on iis6, but will need it to work on iis 7.5 also.. Many thanks.. Mark
modified on Tuesday, April 6, 2010 5:02 AM
-
Make all of your links relative to the root. Instead of things like ../styles/style.css use /styles/style.css.
Hi ya, I have made them relative, but when the trailing / is on the end it thinks it's in a directory above where it is, and so the links fail. I even tried making the links server-side so that I can use href="~/Styles/StyleSheet.css" but the website thinks it is at root level, because that's where the 404 page is. When I view the source code for the page, the links appear as www.mysite.co.uk/afakedir/Styles/stylesheet.css it turns out it's not just the css and js files, but all other links have the fake directory appended to the beginning of it. (I hope that made sense...) It's left me very confused, I thought it was going to be very simple. Thanks for the advice :) Mark