URL for server page

URL for server page

am 31.03.2008 14:49:01 von NeilB

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

Re: URL for server page

am 31.03.2008 22:34:43 von Anthony Jones

"Neil B" 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