Sunday, June 19, 2011

Get Url - Protocol/Schema, Domain and (if applicable) Port

From goo.gl/WfuVV and goo.gl/AYp9v


Request.Url.GetLeftPart(UriPartial.Authority)

It will return a string like the following

"http://localhost:51528"

Requesr.Url properties and sample values:

Request.Url
{http://localhost:51528/Account/SendForgotPasswordEmail?email=jon@connor.com}
AbsolutePath: "/Account/SendForgotPasswordEmail"
AbsoluteUri: "http://localhost:51528/Account/SendForgotPasswordEmail?email=jon@connor.com"
Authority: "localhost:51528"
DnsSafeHost: "localhost"
Fragment: ""
Host: "localhost"
HostNameType: Dns
IsAbsoluteUri: true
IsDefaultPort: false
IsFile: false
IsLoopback: true
IsUnc: false
LocalPath: "/Account/SendForgotPasswordEmail"
OriginalString: "http://localhost:51528/Account/SendForgotPasswordEmail?email=jon@connor.com"
PathAndQuery: "/Account/SendForgotPasswordEmail?email=jon@connor.com"
Port: 51528
Query: "?email=jon@connor.com"
Scheme: "http"
Segments: {string[3]}
UserEscaped: false
UserInfo: ""

No comments: