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 8592159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:41:25+00:00 2026-06-11T23:41:25+00:00

I am validating a regular URL as follows: private static bool IsUrlAvailable(string url) {

  • 0

I am validating a regular URL as follows:

private static bool IsUrlAvailable(string url)
    {

        if ((string.IsNullOrEmpty(url.Trim()) == true) ||
            (url.Trim().ToLower().Equals("http://")) ||
            (url.Trim().ToLower().Equals("https://")))
        {
            return false;
        }
        if (!url.ToLower().StartsWith("http://") && !url.ToLower().StartsWith("https://"))
        {
            url = "http://" + url;
        }
        try
        {
            var req = (HttpWebRequest)WebRequest.Create(url);
            req.Timeout = 15000;
            req.Method = "HEAD";
            using (var rsp = (HttpWebResponse)req.GetResponse())
            {
                if (rsp.StatusCode == HttpStatusCode.OK)
                {
                    return true;
                }
            }
        }
        catch (Exception ex)
        {
            // Eat it because all we want to do is return false 
        }

        // Otherwise 
        return false;
    }

But since I am using a WebRequest.Create, authenticated SharePoint urls on the intranet are failing validation because of permission denied (404) error. Now I know we can validate it using SPSite.Exists or OpenWeb but these are only available in microsoft.sharepoint.dll and I was wondering if there is a way of doing this without using this DLL?

  • 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-06-11T23:41:26+00:00Added an answer on June 11, 2026 at 11:41 pm

    404 is not permission denied… but file-not-found. So you may indeed hit non-existing Url.

    You need to pass credentials with your request

    WebRequest request = WebRequest.Create ("http://www.contoso.com/default.html");
    // If required by the server, set the credentials.
    request.Credentials = CredentialCache.DefaultCredentials;
    // Get the response.
    HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
    

    Side note: please do not “eat all exceptions” – there is very small set of exceptions that are interesting in case of making WebRequests which you can find in article about HttpWebRequest.GetResponse (you likley should only handle WebException).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a basic regular expression for validating a url, such that: Both http://
I need a regular expression or module for validating the website URL using Perl.
At present I am using: /^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\? \,\'\/\\\+&%\$#_]*)?$/ as my regular expression for validating URL.
I am validating a string whether it is hexadecimal or not using regular expression.
While validating my CSS on http://jigsaw.w3.org/css-validator/ I am getting following errors: 1.Property zoom doesn't
I have seen many regular expressions for Url validation. In my case I want
Possible Duplicate: jQuery Youtube URL Validation with regex YouTube url id Regex http://www.youtube.com/watch?v=SCS7SIeF30E http://www.youtube.com/watch?v=SCS7SIeF30E&feature=relmfu
I am looking for help in creating a Regular Expression that validates a URL
What is the regular expression for validating a month with the leading zero? Passes
I use this regular expression for validating some of my textbox : Regex re

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.