Check the URI kind to be Absolute only then.
The method is treating the path you passed as relative path, that's why it can be validated without problem.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
Why below validation return valid for invalid URLs?
if (!Uri.IsWellFormedUriString("microsoft", UriKind.RelativeOrAbsolute))
{
Console.WriteLine("Invalid URL");
}
else
{
Console.WriteLine("Valid URL");
}
I want only the following to be valid:
Thanks,
Jassim
Check the URI kind to be Absolute only then.
The method is treating the path you passed as relative path, that's why it can be validated without problem.
This is a valid relative path, in fact, even if you just enter a few letters randomly, it will return the same result.
In html, we might use code like this:
<a href="microsoft"">link text</a>
When you click it, it will open the file named "microsoft" in the same folder. It is no problem to name the file "microsoft".
This should be stipulated by a certain specification of the Web, and c# is following these specifications.
Uri.IsWellFormedUriString(String, UriKind) Method
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.