System.Web.HttpResponse.WriteSubstitution C# (CSharp) Method

WriteSubstitution() public method

public WriteSubstitution ( HttpResponseSubstitutionCallback callback ) : void
callback HttpResponseSubstitutionCallback
return void
		public void WriteSubstitution (HttpResponseSubstitutionCallback callback)
		{
			// Emulation of .NET behavior
			if (callback == null)
				throw new NullReferenceException ();

			object target = callback.Target;
			if (target != null && target.GetType () == typeof (Control))
				throw new ArgumentException ("callback");

			string s = callback (context);
			if (!IsCached) {
				Write (s);
				return;
			}

			Cache.Cacheability = HttpCacheability.Server;
			Flush ();
			if (WorkerRequest == null)
				Write (s); // better this than nothing
			else {
				byte[] bytes = WebEncoding.ResponseEncoding.GetBytes (s);
				WorkerRequest.SendResponseFromMemory (bytes, bytes.Length);
			}
			
			cached_response.SetData (callback);
		}

Usage Example

Example #1
0
		public void Methods_Deny_Unrestricted ()
		{
			HttpResponse response = new HttpResponse (writer);
			response.AddCacheItemDependencies (new ArrayList ());
			response.AddCacheItemDependency (String.Empty);
			response.AddFileDependencies (new ArrayList ());
			response.AddFileDependency (fname);
			response.AddCacheDependency (new CacheDependency[0]);
			response.AddCacheItemDependencies (new string [0]);
			response.AddFileDependencies (new string [0]);

			try {
				response.AppendCookie (new HttpCookie ("mono"));
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				Assert.IsNull (response.ApplyAppPathModifier (null), "ApplyAppPathModifier");
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				response.Clear ();
			}
			catch (NullReferenceException) {
				// ms 
			}
		
			try {
				response.ClearContent ();
			}
			catch (NullReferenceException) {
				// ms 
			}
		
			try {
				response.ClearHeaders ();
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				response.Redirect ("http://www.mono-project.com");
			}
			catch (NullReferenceException) {
				// ms 
			}
			try {
				response.Redirect ("http://www.mono-project.com", false);
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				response.SetCookie (new HttpCookie ("mono"));
			}
			catch (NullReferenceException) {
				// ms 
			}

			response.Write (String.Empty);
			response.Write (Char.MinValue);
			response.Write (new char[0], 0, 0);
			response.Write (this);
			response.WriteSubstitution (new HttpResponseSubstitutionCallback (Callback));

			response.Flush ();

			response.Close ();

			try {
				response.End ();
			}
			catch (NullReferenceException) {
				// ms 
			}
		}
All Usage Examples Of System.Web.HttpResponse::WriteSubstitution