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 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/

For example, this test string always throws an exception when trying to get 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; }}   

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>

patherror So it does not work for the relative path.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -