URL for server page

N

Neil B

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
 
A

Anthony Jones

Neil B said:
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.
 

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
474,079
Messages
2,570,574
Members
47,207
Latest member
HelenaCani

Latest Threads

Top