Skip to content

Conversation

@vascoazevedo08
Copy link
Contributor

@vascoazevedo08 vascoazevedo08 commented Oct 12, 2024

Overview
This pull request addresses an issue with validating the existence of a site collection in SharePoint Online. Currently, when a tenant administrator attempts to validate a site collection's existence using its URI, it may result in errors due to reserved characters, specifically periods (.) in the URI.

Background
In SharePoint, the following restrictions apply to site collection URIs:

  • Allowed characters: underscores (_), dashes (-), single quotes ('), and periods (.).
  • Restrictions: URIs cannot start or end with a period.

132e9ff6-1caf-46e2-9275-76dad0c84d08

In the Tenant Extensions class within Microsoft.SharePointOnline.CSOM, the method GetSitePropertiesByUrl and GetDeletedSitePropertiesByUrl, currently does not handle URIs with periods correctly, as illustrated below:

a49f45e2-f975-4bd5-ae29-dc69b0943107

Method Summary: SiteExistsAnywhere

  1. Initial Connection Attempt:

    • Uses a ClientContext to clone the tenant context with the specified site URI.
    • Loads the Site object and executes a query.
    • If successful, returns SiteExistence.Yes.
  2. Error Handling:

    • If an exception occurs:
      • Unauthorized Access: If the exception indicates unauthorized access, the site collection is considered to exist, returning SiteExistence.Yes.
  3. HTTP Request for Verification:

    • Sends an HTTP GET request to the site URL using an HttpClient.
    • If the response indicates a 404 status:
      • 404 FILE NOT FOUND: Returns SiteExistence.No, indicating the site does not exist.
      • CONNECTION: CLOSE: Indicates the site is in the recycle bin, returning SiteExistence.Recycled.
  4. Final Checks:

    • If the original exception indicates that the site was not found, returns SiteExistence.No.
    • If no definitive status can be determined, defaults to returning SiteExistence.Yes.

To ensure the correctness and reliability of the SiteExistsAnywhere method, a unit test has been created.

- Change logic to validate if site exists.
- Added unit tests to ensure the functionality works as intended, covering various scenarios.
@vascoazevedo08 vascoazevedo08 marked this pull request as ready for review October 12, 2024 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant