ASP.NET - Remote server returned a 403 forbidden error

Asked By abinav shankar on 15-Nov-11 12:59 AM

Hi
i used the following code to get the response i got the response for login service but cannot get the response from the url (http://localhost:8080/geonetwork/srv/en/xml.metadata.get) and i ended up getting the error 403 forbidden


protected void Page_Load(object sender, EventArgs e)

{

string RequestXML = "<Request>" +

"<username>admin</username>" +

"<password>admin</password></Request>";

string ServerURL = "http://localhost:8080/geonetwork/srv/en/xml.user.login";

string ResponseXML = postRequest(RequestXML, ServerURL);

//= ResponseXML.ToString();

string ServerURL1 = "http://localhost:8080/geonetwork/srv/en/xml.metadata.get";

string RequestXML1 = "<request>" +

"<uuid>5915639e-777c-4339-93ad-c4037f2eeb77</uuid>" +

"</request>";

string ResponseXML1 = postRequest(RequestXML1, ServerURL1);

Label1.Text = ResponseXML1.ToString();

}


private string postRequest(String RequestXML, string ServerURL)

{

int timeout = 90000;

int connectionLimit = 10;

string responseXML = string.Empty;

try

{

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(ServerURL);

webRequest.Timeout = timeout;

webRequest.KeepAlive =

true;

webRequest.ServicePoint.ConnectionLimit = connectionLimit;

webRequest.Method = "POST";

webRequest.ContentType =

"text/xml";

byte[] byteArray = Encoding.UTF8.GetBytes(RequestXML);

Stream strm = webRequest.GetRequestStream();

strm.Write(byteArray, 0, byteArray.Length);

strm.Close();

HttpWebResponse webResponse =(HttpWebResponse)webRequest.GetResponse();

Encoding enc = Encoding.GetEncoding("utf-8");

StreamReader reader = new StreamReader(webResponse.GetResponseStream(), enc);

responseXML = reader.ReadToEnd();

reader.Close();

webResponse.Close();


}


catch (Exception ex)

{

throw (ex);

}


return responseXML;

}
 
here is the code i used pl correct me where i went worng

Jitendra Faye replied to abinav shankar on 15-Nov-11 01:07 AM

Cause

The 403 Forbidden error is an http://pcsupport.about.com/od/termshm/g/httpstatuscode.htm that means that accessing the page or resource you were trying to reach is absolutely forbidden for some reason.

Resolution

  1. http://pcsupport.about.com/od/findtheproblem/ht/wrongurl.htm and make sure the actual web page is specified. The most common reason for a web site to return the 403 Forbidden error is if the http://pcsupport.about.com/od/termsu/g/termurl.htm is pointing to a directory instead of a web page.

  2. If you're sure the page you're trying to reach is correct, the 403 Forbidden error message may be a mistake. At this point it's probably in your best interest to contact the webmaster or other website contact and inform them of the problem.

    The webmaster of most Internet sites can be reached via email at webmaster@website.com, replacing website.com with the actual website name.
Anoop S replied to abinav shankar on 15-Nov-11 02:07 AM
403 error saying "Forbidden: You don't have permission to access http://localhost:8080/geonetwork/srv/en/xml.metadata.get on this server".

Click the Windows "Start" button and select "Settings." From the menu, click "Control Panel."

Double-click the "Administrative Tools" icon. In this list of consoles, double-click the "Internet Information Services" icon. This opens the IIS settings console.

Right-click the directory from which web browsers are receiving the 403 error. Click the "Properties" entry in the menu.

Click the "Directory Security" tab in the Properties window. Click the first button that is labeled "Edit" in the "Anonymous Access" section. In this window, check the box that says "Anonymous Access." Click "OK" to return to the Properties window.

Click the "Directory" tab in the Properties window. Ensure that no other check boxes except "Read" are checked in the "Permissions" section. This allows users to read and browse website pages. Click the "OK" button.

Verify the changes by opening your web browser and entering the website domain in the address bar.



dipa ahuja replied to abinav shankar on 15-Nov-11 03:07 AM
SOLUTION: The problem stems from the fact that IIS 5.1 does not recognize ASP.NET default pages, since it predates ASP.NET. To fix the problem, open the IIS Administrative Tool (Windows XP Start > Control Panel > Administrative Tools > Internet Information Services). Navigate to the Default Web Site in the tree in the left pane. Right-click the Default Web Site and select Properties from the context menu. When the Default Web Site Properties box opens, select the Documents tab. Add the following to the list:

Default.aspx
index.aspx

Click OK to save the additions. You should no longer get a 403 error.