0

There is a WebAPI based service that is returning 403 forbidden error when the service is hit from a client application(C#). Is it possible to retrieve the substatus code from the client application?

Naren
  • 735
  • 1
  • 9
  • 19

2 Answers2

0

Enclose the code that makes web request in client in try block and do something like this

            catch (WebException ex)
            {
                StreamReader dataReader = new StreamReader(ex.Response.GetResponseStream());
                string data = dataReader.ReadToEnd();
            }
Saurav
  • 592
  • 4
  • 21
  • I have a similar construct in my code, but it does not show the substatus code. Is there any way to retrieve that? – Naren Nov 19 '14 at 09:33
0

It is not possible to retrieve substatus codes from the server. This page (http://msdn.microsoft.com/en-us/library/system.web.httpresponse.substatuscode.aspx) clearly says that,

"The SubStatusCode property is only supported with the integrated pipeline mode in IIS 7.0 and at least the .NET Framework version 3.0. When you set the SubStatusCode property, the status is logged on IIS 7.0 if failed-request tracing is configured. Independent of whether tracing is configured, the code is never sent as part of the final response to the request."

Naren
  • 735
  • 1
  • 9
  • 19