For Programmers: Free Programming Magazines  


Home > Archive > ASP > March 2008 > URL for server page









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author URL for server page
Neil B

2008-03-31, 7:04 pm

I'm developing a Web App using C#. I want a page in the app to refer to
another page in the app. I tried to create a web request with the page
address below:

pageAddress = "http://~/clientDBQuery.aspx";
WebRequest request = WebRequest.Create (pageAddress);

and got the following error:

Exception Details: System.UriFormatException: Invalid URI: The hostname
could not be parsed.

What is the syntax for referring to a page on the current site so I don't
have to change it when it's published?


When I used the following page address:

pageAddress = "http://clientDBQuery.aspx";

I didn't get the parsing error but the debugger didn't stop on a break point
I set in the LoadPage method. This seems to occurr because it goes to a page
on my ISP which doesn't exist.

What's the right way to handle this situation?

Thanks, Neil

Anthony Jones

2008-03-31, 7:04 pm


"Neil B" <NeilB@discussions.microsoft.com> wrote in message
news:8AA4174F-4CBE-400C-9506-22D9DFD7C0D0@microsoft.com...
> I'm developing a Web App using C#. I want a page in the app to refer to
> another page in the app. I tried to create a web request with the page
> address below:
>
> pageAddress = "http://~/clientDBQuery.aspx";
> WebRequest request = WebRequest.Create (pageAddress);
>


You use the Pages ResolveURL() method to resolve a URL that begins with ~/.

You cannot preceed the ~/ with a protocol or servername, IOW ~/ always has
to be at the beginning of the URL.


> and got the following error:
>
> Exception Details: System.UriFormatException: Invalid URI: The hostname
> could not be parsed.
>
> What is the syntax for referring to a page on the current site so I don't
> have to change it when it's published?
>
>
> When I used the following page address:
>
> pageAddress = "http://clientDBQuery.aspx";
>


That doesn't define the server name so that isn't going to work either.

> I didn't get the parsing error but the debugger didn't stop on a break

point
> I set in the LoadPage method. This seems to occurr because it goes to a

page
> on my ISP which doesn't exist.
>
> What's the right way to handle this situation?
>


The right way is to take the code you want to execute from
clientDBQuery.aspx and place it in a seperate class in a .cs file placed in
the App_Code folder. Then use that class from both clientDBQuery and the
page you are trying ot write. Its best to avoid having code on the server
make requests to itself.

Note this NG is for classic ASP. Feel free to add supplementary questions
to this thread but for future thread use
microsoft.public.dotnet.framework.aspnet.


--
Anthony Jones - MVP ASP/ASP.NET


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com