c# - Validate that string is relative url not working -
I am trying to validate that the string representing the URL is relative, but it seems that the For example, this test string always throws an exception when trying to get Example Input / Output: Input: /something/else.aspx ==> Output: /something/else.aspx Input: www.domain.com/something/else.aspx == & gt; Output: /something/else.aspx Input: ==> Ouput: string.Empty Looking at the relative path of a URL, how can I validate that it is actually relative and the path and query Receive domain path by << / p> Uri.TryCreate () will accept any URL without the relation of the protocol (i.e.: www.domain.com/something/else.aspx). But I only need /something/else.aspx/
uri.PathAndQuery on the line Be there Even if
TryCreate () return is correct.
string test = "/something/else.aspx"; Bool isValid; Var url = getPathAndQuery (test is out, isalid); Private string getPathAndQuery (string url is valid outside bool) {Uri uri; IsValid = Uri.TryCreate (URL, Uricund. Relative, Out Yuri); Try {return isValid? Uri.PathAndQuery: string.Empty; } Hold (exception e) {isValid = false; Return string Empty; }}
patherror So it does not work for the relative path.
Comments
Post a Comment