Created
October 25, 2013 23:32
-
-
Save priore/7163408 to your computer and use it in GitHub Desktop.
ASP.NET [C#] Redirect with post data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Collections.Specialized; | |
using System.Text; | |
// ASP.NET [C#] REDIRECT WITH POST DATA | |
public static class WebExtensions | |
{ | |
public static void RedirectWithData(NameValueCollection data, string url) | |
{ | |
HttpResponse response = HttpContext.Current.Response; | |
response.Clear(); | |
StringBuilder s = new StringBuilder(); | |
s.Append("<html>"); | |
s.AppendFormat("<body onload='document.forms[\"form\"].submit()'>"); | |
s.AppendFormat("<form name='form' action='{0}' method='post'>", url); | |
foreach (string key in data) | |
{ | |
s.AppendFormat("<input type='hidden' name='{0}' value='{1}' />", key, data[key]); | |
} | |
s.Append("</form></body></html>"); | |
response.Write(s.ToString()); | |
response.End(); | |
} | |
} |
Thank you
Please note that the "response.End()" at the end may be causing "thread was being aborted" exception. In that case replace it by "HttpContext.Current.ApplicationInstance.CompleteRequest()" as per the instructions in "https://support.microsoft.com/en-us/help/312629/prb-threadabortexception-occurs-if-you-use-response-end-response-redir"
It's not working in Asp.Net MVC
Very good, you made my day!
Regards!
@rockybalog did you later find a work around for this on .net core?
@fidelflorian pls what exactly did you do?
I did but I’d have to go back and find it. I’m heading out of town today and won’t be back for a while.
From: Samtoch <[email protected]>
Sent: Saturday, March 6, 2021 3:32 AM
To: priore <[email protected]>
Cc: Mike Balog <[email protected]>; Mention <[email protected]>
Subject: Re: priore/gist:7163408
@Samtoch commented on this gist.
…_____
@rockybalog <https://github.com/rockybalog> did you later find a work around for this on .net core?
@fidelflorian <https://github.com/fidelflorian> pls what exactly did you do?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <https://gist.github.com/7163408#gistcomment-3655603> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJHAS7QBV7VPMAYWJHVON3LTCHR6JANCNFSM4KG6GZUQ> . <https://github.com/notifications/beacon/AJHAS7XS7I2FA7DMBRKE56LTCHR6JA5CNFSM4KG6GZU2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAG7D3G.gif>
Good to know @rockybalog please help me when your find time. Thanks in advance
Thank you so much. I search this code from a month. Thanks a lot.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. It is 6 years old but helped me.