I think everyone should use ResolveUrl and ResolveClientUrl. This document is not described here. If you have never used it, click here.
In MSDN, The ResolveUrl and ResolveClientUrl under. NET Framework 4 and. NET Framework 3.5 are the same, but are they true?
Of course, the answer is different. If they are the same, there will be no such essay.
Run the following code:
Code
Private void TestUrl ()
{
RelativeUrl = @"~ \ 11 \ 22. aspx ";
ParseUrlResult (relativeUrl );
RelativeUrl = @"~ /11/22. aspx ";
ParseUrlResult (relativeUrl );
RelativeUrl = @"~ \ 11 \ 22. aspx? 1 = 1 ";
ParseUrlResult (relativeUrl );
RelativeUrl = @"~ \ 11 \ 22. aspx? Http://contoso.com ";
ParseUrlResult (relativeUrl );
RelativeUrl = @"~ /11/22. aspx? Http://contoso.com ";
ParseUrlResult (relativeUrl );
RelativeUrl = @ "... \ 11 \ 22. aspx? ";
ParseUrlResult (relativeUrl );
RelativeUrl = @ "... \ 11 \ 22. aspx? ";
ParseUrlResult (relativeUrl );
RelativeUrl = @ "http://www.cnblogs.com/../11/22.aspx? ";
ParseUrlResult (relativeUrl );
RelativeUrl = @ "http://contoso.com ";
ParseUrlResult (relativeUrl );
}
Private void ParseUrlResult (string relativeUrl)
{
Response. Write (string. Format ("raw URL: {0}", relativeurl ));
Response. Write ("<br/> ");
Try
{
Response. Write (string. Format ("resolveurl: {0}", this. resolveurl (relativeurl )));
}
Catch (exception ex)
{
Response. Write (string. Format ("<font color = 'red'> ResolveUrl: {0} </font>", ex. Message ));
}
Response. Write ("<br/> ");
Try
{
Response. Write (string. Format ("ResolveClientUrl: {0}", this. ResolveClientUrl (relativeUrl )));
}
Catch (exception ex)
{
Response. Write (string. Format ("<font color = 'red'> resolveclienturl: {0} </font>", Ex. Message ));
}
Response. Write ("<br/> ");
Response. Write ("<br/> ");
}
The following are the results under. NET Framework 4: The results under. NET Framework 3.5 are as follows:
In the comparison, it is different. Obviously in. NET Framework 4, ResolveClientUrl can be used to input parameters with absolute addresses. The ResolveUrl can also be used to input parameters containing absolute addresses, but the forward and backward slashes are distinguished.
Obviously, the program was changed, but only. NET Framework 4 was added to MSDN. The specific content was not changed.