I know this question has been answered a lot of times, but I am still having issues with posting values from winform to aspx page. I always get a value of null.
Following is my winform code:
string formContent = "FormValue1=" + contact.Country;
var dataBytes = System.Text.Encoding.UTF8.GetBytes(formContent);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:52262/Default.aspx");
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.ContentLength = dataBytes.Length;
httpWebRequest.Method = WebRequestMethods.Http.Post;
Stream dataStream = httpWebRequest.GetRequestStream();
dataStream.Write(dataBytes, 0, dataBytes.Length);
dataStream.Close();
//dataStream.Flush();
HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
//lblShow.Text = ((HttpWebResponse)response).StatusDescription;
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream);
string responseFromServer = streamReader.ReadToEnd();
streamReader.Close();
response.Close();
Following is my Default.aspx page code:
protected void Page_Load(object sender, EventArgs e)
{
ClaimsPrincipal claimsPrincipal = Page.User as ClaimsPrincipal;
if (claimsPrincipal != null)
{
this.ClaimsGridView.DataSource = claimsPrincipal.Claims;
this.ClaimsGridView.DataBind();
}
Session["Name"] = Request.Form["FormValue1"];
}
The Request Form values always have null values. The same code works in MVC, but in webforms it always fails.
Any help or guidance would be great.
Thanks In Advance!!!..