I have the following code:
public static string FormatHostAndUrl(this HttpSessionStateBase session)
{
var a = session["CurrentHost"];
var b = session["CurrentUrl"];
var c = string.Format("http://{0}{1}", session["CurrentHost"], new Uri((string)session["currentUrl"]).PathAndQuery);
return string.Format("http://{0}{1}", session["CurrentHost"], new Uri((string)session["currentUrl"]).PathAndQuery);
}
I use this to get the exact URL including Port. With the azure system I am using this seems to be the only combination of code that gives the correct URL.
I get the session variables
Session["CurrentUrl"] = Request.Url.ToString();
Session["CurrentHost"] = Request.Headers["Host"];
What I would like to do is to extend the Request object so I can do something like this:
Session["TheRealURLI Need"] = Request.RealURL();
Is it possible to do this with an extension method? Some method that does the functionality of the FormatHostAndUrl method?
Edit: The point here is you extend classes, even sealed ones. How you get the
HttpRequestobject is irrelevant, whether it’s via aRequestproperty or by any other means. You extend the type. The property will follow suit.