Improve SiteExistsAnywhere in Tenant Extensions. #1071
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
In the Tenant Extensions class within Microsoft.SharePointOnline.CSOM, the method
GetSitePropertiesByUrl
andGetDeletedSitePropertiesByUrl
, currently does not handle URIs with periods correctly, as illustrated below:Method Summary: SiteExistsAnywhere
Initial Connection Attempt:
ClientContext
to clone the tenant context with the specified site URI.Site
object and executes a query.SiteExistence.Yes
.Error Handling:
SiteExistence.Yes
.HTTP Request for Verification:
HttpClient
.SiteExistence.No
, indicating the site does not exist.SiteExistence.Recycled
.Final Checks:
SiteExistence.No
.SiteExistence.Yes
.To ensure the correctness and reliability of the
SiteExistsAnywhere
method, a unit test has been created.