Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
hi all,
 
how do i get error code from catch (Exception ex), say i got error "The request failed. The remote server returned an error: (401) Unauthorized."
 
i want error code 401 only.
 
thanks,
krunal
Posted 18-Nov-12 21:58pm
kk20141.8K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can try to catch WebException.
 
catch (WebException ex)
{
  HttpWebResponse resp = (HttpWebResponse)ex.Response;
  if (resp!= null)
  {
   int httpCode = (int)response.StatusCode;
  }
}
 
Hope that helps. if it does, mark it as answer/upvote.
 
Thanks
Milind
  Permalink  
Comments
kkakadiya at 19-Nov-12 4:36am
   
hi,
i am working on c# desktop application. it doesnt allow me response property of ex at HttpWebResponse resp = (HttpWebResponse)ex.Response;
Milind Thakkar at 19-Nov-12 4:43am
   
There is no reason why it won't allow it in desktop application. Check
http://msdn.microsoft.com/en-us/library/system.net.webexception.response(VS.90).aspx
 
There must be some other issue in the code. Pleas check or post code snippet you are trying.
-Milind
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
what is the authentication type you are using and what type of an application are you working on?
 
Thanks.
  Permalink  
Comments
Milind Thakkar at 19-Nov-12 4:03am
   
THis is a comment and not solution !!
kkakadiya at 19-Nov-12 4:34am
   
i am working on c# desktop application and if username and password donot match then i want that authentication error code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 330
1 Mathew Soji 309
2 Maciej Los 295
3 Afzaal Ahmad Zeeshan 257
4 DamithSL 225
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,045


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100