Issue with IHttpHandler and relative URLs
Posted
by vtortola
on Stack Overflow
See other posts from Stack Overflow
or by vtortola
Published on 2010-05-27T18:48:55Z
Indexed on
2010/05/27
18:51 UTC
Read the original article
Hit count: 438
Hi,
I've developed a IHttpHandler
class and I've configured it as verb="*" path="*"
, so I'm handling all the request with it in an attempt of create my own REST implementation for a test web site that generates the html dynamically.
So, when a request for a .css file arrives, I've to do something like context.Response.WriteFile(Server.MapPath(url))
... same for pictures and so on, I have to response everything myself.
My main issue, is when I put relative URLs in the anchors; for example, I have main page with a link like this <a href="page1">Go to Page 1</a>
, and in Page 1 I have another link <a href="page2">Go to Page 2</a>
. Page 1 and 2 are supposed to be at the same level (http://host/page1
and http://host/page2
, but when I click in Go to Page 2, I got this url in the handler: ~/page1/~/page2
... what is a pain, because I have to do an url = url.SubString(url.LastIndexOf('~')) for clean it, although I feel that there is nothing wrong and this behavior is totally normal.
Right now, I can cope with it, but I think that in the future this is gonna bring me some headache. I've tried to set all the links with absolute URLs using the information of context.Request.Url
, but it's also a pain :D, so I'd like to know if there is a nicer way to do these kind of things.
Don't hesitate in giving me pretty obvious responses because I'm pretty new in web development and probably I'm skipping something basic about URLs, Http and so on.
Thanks in advance and kind regards.
© Stack Overflow or respective owner