/ Published in: C#
Useful when creating multiple instances of field with same name on client-side, but since the user can enter a comma, referencing Request["myvar"] will get you a comma delimited list that isn't reliable (the commas aren't escaped). So use StreamReader to read the raw http stream and parse it yourself.
Expand |
Embed | Plain Text
/// <summary> /// Save the FAQs posted from traditional html inputs created via jquery. /// Since the form inputs all have the same name, they'd be comma delimited in Request.Form /// which is a problem if someone types a comma, so just parsing the raw http post to get /// what we need via Request.InputStream. Would be nice if .Net offered something like Request("ids").item(i) /// but no such luck. /// </summary> private void GetFAQsFromPost() { { string[] postedValues = sr.ReadLine().Split('&'); foreach (string postedValue in postedValues) { if (postedValue.StartsWith("question=")) { string urlEncodedQuestion = postedValue.Replace("question=", ""); Questions.Add(HttpUtility.UrlDecode(urlEncodedQuestion)); } else if (postedValue.StartsWith("answer=")) { string urlEncodedAnswer = postedValue.Replace("answer=", ""); Answers.Add(HttpUtility.UrlDecode(urlEncodedAnswer)); } } } }
You need to login to post a comment.
