web 2.0

Useful HttpResponse Extension Methods

Hi,

In this article a few useful Extension Methods for HttpResponse.

We often need to Write something to Response with New Line at the End or Switch Current Response to Ssl Mode.

Instread of using :

Response.Write("Something<br/>");

Response.WriteLine

public static void WriteLine(this HttpResponse response, Char o)
{
    response.Write(String.Concat(o, "<br/>"));
}
public static void WriteLine(this HttpResponse response, String o)
{
    response.Write(String.Concat(o, "<br/>"));
}
public static void WriteLine(this HttpResponse response, Object o)
{
    response.Write(String.Concat(o.ToString(), "<br/>"));
}

Response.SwitchToSsl

public static void SwitchToSsl(this HttpResponse response)
{
    String baseUrl = HttpContext.Current.Request.Url.OriginalString;
    Uri uri = new Uri(baseUrl);
    String url = baseUrl.Replace(uri.Scheme, Uri.UriSchemeHttps);
    response.Redirect(url, true);
}

Hope this help’s.



Views(1946)

kick it on DotNetKicks.com

Share/Save/Bookmark Subscribe

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

ASP.NET

Comments

Add comment


 

biuquote
Loading



Technorati Profile