Search code examples
c#asp-classichttpwebrequesturi

Creating Uri to virtual directory


I created a simple console application in C# to connect to a classic asp file on a web server. I am receiving a 500 - internal server error and I think it is because I am creating the Uri using the physical path of the file and not the virtual directory path. The web server is 2003 and using IIS 6.0

Say the physicial path is: C:\inetpub\wwwroot\HV1\App2\Pa3\ASP\Service.asp The web site: HV_Site The virtual directory is: App1 The virtual directory physical path is: C:\inetpub\wwwroot\HV1.

I create an Uri for the HttpWebRequest using the physical path:

Uri aspUri = new Uri("http://<serverName>:<port>/HV1/App2/Pa3/ASP/Service.asp?<parameters>");
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(aspPagingServiceUri);
httpWebRequest.Method = "GET";               
                var response = httpWebRequest.GetResponse();

At the response line I get a 500 error. I believe it is because I need to incorporate the virtual directory into the request. I tried creating the Uri like this: Uri aspUri = new Uri("http://<servername>:<port>/App1/App2/Pa3/ASP/Service.asp?<parameters>")

I get a 404 error when I do that.

How do I create the Uri using a virtual directory?

Thanks.


Solution

  • I went back to basics...I created a simple 'Hello World' asp page and put it on the web server in the directory I need to be in. It is display. I can also get it to display in my console application. I will build the page from this simple page.

    Thanks for all of the help.