priore

ASP.NET [C#] Redirect with post data

Oct 23rd, 2013
184
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Collections.Specialized;
  6. using System.Text;
  7.  
  8. // ASP.NET [C#] REDIRECT WITH POST DATA
  9. public static class WebExtensions
  10. {
  11.         public static void RedirectWithData(NameValueCollection data, string url)
  12.         {
  13.             HttpResponse response = HttpContext.Current.Response;
  14.             response.Clear();
  15.  
  16.             StringBuilder s = new StringBuilder();
  17.             s.Append("<html>");
  18.             s.AppendFormat("<body onload='document.forms[\"form\"].submit()'>");
  19.             s.AppendFormat("<form name='form' action='{0}' method='post'>", url);
  20.             foreach (string key in data)
  21.             {
  22.                 s.AppendFormat("<input type='hidden' name='{0}' value='{1}' />", key, data[key]);
  23.             }
  24.             s.Append("</form></body></html>");
  25.             response.Write(s.ToString());
  26.             response.End();
  27.         }
  28. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×