Confused about Response.StatusCode

  • Thread starter Thread starter Shane
  • Start date Start date
S

Shane

I want the function in Code Snippet #1 below to return a
string of "200" by making a web request for
the vbprogram.aspx that contains the PageLoad function in
Code Snippet #2 below. Instead, I am getting a StatusCode
of "OK" instead of 200. What should I change here? Thanks
in advance for any help anyone may be able to give.


Code Snippet #1 (The function that does the web request.)
(from a C# program I wrote.)

public string sendToXMLGateWay()
{
string valueToReturn = "";
string lcUrl = "http://mywebsite.com/vbprogram.aspx";
HttpWebRequest webreq = (HttpWebRequest) WebRequest.Create
(lcUrl);

HttpWebResponse loWebResponse = (HttpWebResponse)
webreq.GetResponse();
valueToReturn = loWebResponse.StatusCode.ToString();
loWebResponse.Close();
return (valueToReturn);
}

Code Snippet #2 (From the vbprogram that should reply with
Status Code of 200.)


Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Response.StatusCode = "200"
End Sub
 
Shane,

Response.StatusCode is of type Integer, so you could just try using
CType(Response.StatusCode, String) to see if that works.

I've not had a chance to look it up, but it could be that the .ToString
method of Response.StatusCode transforms the numeric StatusCode into the
text equivalent - so if the code were 404, it would respond with "File Not
Found".

Hopefully this method will work.

Regards,
Anthony
 
Back
Top