Oggetto Uri in C#
Un esempio di cosa restituiscono le proprietà e i metodi dell'oggetto Uri di C# con la seguente url:
risultato
questo è il codice C# 3.5 per generare l'output precedente:
Text
http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29%2Dd959%2D4a11%2Db5d2%2D604b72bea813&ID=2
risultato
DOS / Batch file
AbsolutePath: /HD/_layouts/HelpDesk/EditHardwareRequest.aspx
AbsoluteUri: http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29%2Dd959%2D4a11%2Db5d2%2D604b72bea813&ID=2
Authority: sharepoint.sgart.local
DnsSafeHost: sharepoint.sgart.local
Fragment:
Host: sharepoint.sgart.local
HostNameType: Dns
IsAbsoluteUri: True
IsDefaultPort: True
IsFile: False
IsLoopback: False
IsUnc: False
LocalPath: /HD/_layouts/HelpDesk/EditHardwareRequest.aspx
OriginalString: http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29%2Dd959%2D4a11%2Db5d2%2D604b72bea813&ID=2
PathAndQuery: /HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29%2Dd959%2D4a11%2Db5d2%2D604b72bea813&ID=2
Port: 80
Query: ?List=fcf64d29%2Dd959%2D4a11%2Db5d2%2D604b72bea813&ID=2
Scheme: http
Segments:
segments[0] = /
segments[1] = HD/
segments[2] = _layouts/
segments[3] = HelpDesk/
segments[4] = EditHardwareRequest.aspx
UserEscaped: False
UserInfo:
-------------
UriPartial.Authority: http://sharepoint.sgart.local
UriPartial.Path: http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx
UriPartial.Query: http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29%2Dd959%2D4a11%2Db5d2%2D604b72bea813&ID=2
UriPartial.Scheme: http://
-------------
UriComponents.AbsoluteUri: http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29-d959-4a11-b5d2-604b72bea813&ID=2
UriComponents.Fragment:
UriComponents.Host: sharepoint.sgart.local
UriComponents.HostAndPort: sharepoint.sgart.local:80
UriComponents.HttpRequestUrl: http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29-d959-4a11-b5d2-604b72bea813&ID=2
UriComponents.KeepDelimiter:
UriComponents.Path: HD/_layouts/HelpDesk/EditHardwareRequest.aspx
UriComponents.PathAndQuery: /HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29-d959-4a11-b5d2-604b72bea813&ID=2
UriComponents.Port:
UriComponents.Query: List=fcf64d29-d959-4a11-b5d2-604b72bea813&ID=2
UriComponents.Scheme: http
UriComponents.SchemeAndServer: http://sharepoint.sgart.local
UriComponents.SerializationInfoString: http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29-d959-4a11-b5d2-604b72bea813&ID=2
UriComponents.StrongAuthority: sharepoint.sgart.local:80
UriComponents.StrongPort: 80
UriComponents.UserInfo:
-------------
UriComponents.SerializationInfoString, UriFormat.SafeUnescaped: http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29-d959-4a11-b5d2-604b72bea813&ID=2
UriComponents.SerializationInfoString, UriFormat.Unescaped: http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29-d959-4a11-b5d2-604b72bea813&ID=2
UriComponents.SerializationInfoString, UriFormat.UriEscaped: http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29%2Dd959%2D4a11%2Db5d2%2D604b72bea813&ID=2
questo è il codice C# 3.5 per generare l'output precedente:
C#
string url = "http://sharepoint.sgart.local/HD/_layouts/HelpDesk/EditHardwareRequest.aspx?List=fcf64d29%2Dd959%2D4a11%2Db5d2%2D604b72bea813&ID=2";
Uri tmpUrl = new Uri(url);
Console.WriteLine("AbsolutePath: " + tmpUrl.AbsolutePath);
Console.WriteLine("AbsoluteUri: " + tmpUrl.AbsoluteUri);
Console.WriteLine("Authority: " + tmpUrl.Authority);
Console.WriteLine("DnsSafeHost: " + tmpUrl.DnsSafeHost);
Console.WriteLine("Fragment: " + tmpUrl.Fragment);
Console.WriteLine("Host: " + tmpUrl.Host);
Console.WriteLine("HostNameType: " + tmpUrl.HostNameType);
Console.WriteLine("IsAbsoluteUri: " + tmpUrl.IsAbsoluteUri);
Console.WriteLine("IsDefaultPort: " + tmpUrl.IsDefaultPort);
Console.WriteLine("IsFile: " + tmpUrl.IsFile);
Console.WriteLine("IsLoopback: " + tmpUrl.IsLoopback);
Console.WriteLine("IsUnc: " + tmpUrl.IsUnc);
Console.WriteLine("LocalPath: " + tmpUrl.LocalPath);
Console.WriteLine("OriginalString: " + tmpUrl.OriginalString);
Console.WriteLine("PathAndQuery: " + tmpUrl.PathAndQuery);
Console.WriteLine("Port: " + tmpUrl.Port);
Console.WriteLine("Query: " + tmpUrl.Query);
Console.WriteLine("Scheme: " + tmpUrl.Scheme);
Console.WriteLine("Segments: ");
for (int i = 0; i < tmpUrl.Segments.Length; i++)
{
var s = tmpUrl.Segments[i];
Console.WriteLine(string.Format(" segments[{0}] = {1}" ,i, s));
}
Console.WriteLine("UserEscaped: " + tmpUrl.UserEscaped);
Console.WriteLine("UserInfo: " + tmpUrl.UserInfo);
Console.WriteLine("-------------");
Console.WriteLine("UriPartial.Authority: " + tmpUrl.GetLeftPart(UriPartial.Authority));
Console.WriteLine("UriPartial.Path: " + tmpUrl.GetLeftPart(UriPartial.Path));
Console.WriteLine("UriPartial.Query: " + tmpUrl.GetLeftPart(UriPartial.Query));
Console.WriteLine("UriPartial.Scheme: " + tmpUrl.GetLeftPart(UriPartial.Scheme));
Console.WriteLine("-------------");
Console.WriteLine("UriComponents.AbsoluteUri: " + tmpUrl.GetComponents(UriComponents.AbsoluteUri, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.Fragment: " + tmpUrl.GetComponents(UriComponents.Fragment, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.Host: " + tmpUrl.GetComponents(UriComponents.Host, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.HostAndPort: " + tmpUrl.GetComponents(UriComponents.HostAndPort, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.HttpRequestUrl: " + tmpUrl.GetComponents(UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.KeepDelimiter: " + tmpUrl.GetComponents(UriComponents.KeepDelimiter, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.Path: " + tmpUrl.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.PathAndQuery: " + tmpUrl.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.Port: " + tmpUrl.GetComponents(UriComponents.Port, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.Query: " + tmpUrl.GetComponents(UriComponents.Query, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.Scheme: " + tmpUrl.GetComponents(UriComponents.Scheme, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.SchemeAndServer: " + tmpUrl.GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.SerializationInfoString: " + tmpUrl.GetComponents(UriComponents.SerializationInfoString, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.StrongAuthority: " + tmpUrl.GetComponents(UriComponents.StrongAuthority, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.StrongPort: " + tmpUrl.GetComponents(UriComponents.StrongPort, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.UserInfo: " + tmpUrl.GetComponents(UriComponents.UserInfo, UriFormat.SafeUnescaped));
Console.WriteLine("-------------");
Console.WriteLine("UriComponents.SerializationInfoString, UriFormat.SafeUnescaped: " + tmpUrl.GetComponents(UriComponents.SerializationInfoString, UriFormat.SafeUnescaped));
Console.WriteLine("UriComponents.SerializationInfoString, UriFormat.Unescaped: " + tmpUrl.GetComponents(UriComponents.SerializationInfoString, UriFormat.Unescaped));
Console.WriteLine("UriComponents.SerializationInfoString, UriFormat.UriEscaped: " + tmpUrl.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped));
Console.ReadLine();