Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7031347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:47:30+00:00 2026-05-28T00:47:30+00:00

I have this method which tries to catch an exception that might be thrown

  • 0

I have this method which tries to catch an exception that might be thrown when supplied with invalid credentials when connecting through SSL. The credentials are supplied through SNMP. But I am not always able to interpret the exception as invalid credentials, as you can see I am only trying to read the message of exception thrown which differs from a device to device.

Is what am I doing correct? Are there any foolproof ways to check if the credentials needed to make the connection is valid? I am totally lost here as the exception message thrown changes from device to device.

Thanks for any pointers.

try
{
    string ipSSL = string.Format(URL_CWIS_HELPSTRING, "s", SecurityBindingProxy.Destination.Address.Value.Host, "/");
    System.Net.WebRequest https = System.Net.HttpWebRequest.Create(ipSSL);
    System.Net.ServicePointManager.ServerCertificateValidationCallback = WsdlClient.ServiceRequirements.WsdlServiceRequirements.SSLCheckCallback;
    https.Credentials = new System.Net.NetworkCredential(SNMP.ConnectionInfo.Instance.Username, SNMP.ConnectionInfo.Instance.Password); ;
    System.Net.HttpWebResponse responseSSL = (System.Net.HttpWebResponse)https.GetResponse();
    responseSSL.Close();
}
catch (Exception ex)
{
    if (ex.Message.Contains("Unauthorized")
        || ex.Message.Contains("401"))
    {
        return -2;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:47:30+00:00Added an answer on May 28, 2026 at 12:47 am

    You want to be catching a more specific type of exception rather than parsing exception messages. If you look at the docs for GetResponse you’ll see documented the types of exceptions thrown. If you catch a WebException then this will allow you to find out the HTTP status without parsing strings manually e.g.:

    catch (System.Net.WebException ex)
    {
        var errorResponse = (System.Net.HttpWebResponse)ex.Response;
        if (errorResponse.StatusCode == System.Net.HttpStatusCode.Unauthorized)
        {
            //...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this recursive method which deletes empty folders: private void DeleteEmpty(DirectoryInfo directory) {
I have this method Verify_X which is called during databind for a listbox selected
I have this code: s(x => x.Open()); s is a method which calls one
I have a method which runs this: Track* track = [[Track alloc] init:[obj objectForKey:@PersistentID]
I have a method, which uses random samples to approximate a calculation. This method
I have an interface called Dictionary which has a method insert() . This interface
I have a Jtable on which I called the method table1.setAutoCreateRowSorter(true); . So this
Example: I have a selector like this, which I give to another method as
Ok so I have a number of methods that look like this:- which sorts
I have a method which instantiates an object, some of the properties of this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.