Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, March 25, 2011

Getting Access to the Response Object from a Regular C# Class (and NOT a code-behind)

When I attempt to call Response.Write() or Response.Redirect() from a genuine C# class (NOT a code-behind), I get an interesting error:

"Response is not available in this context."

However, call it this way and it should work fine:

HttpContext.Current.Response.Write("Hello, World!");

Thursday, March 10, 2011

Html/Meta Object in C#

Don't forget to import System.Web.UI.HtmlControls;

//Waits for 10 seconds and then forwards to Google.com
HtmlMeta meta = new HtmlMeta();
meta.HttpEquiv = "Refresh";
meta.Content = "10; URL=http://www.google.com";
Page.Header.Controls.Add(meta);