[c#] Get POST data in C#/ASP.NET

I am trying to get POST data, but I'm having no luck. My code is below. When I click the form button nothing happens.

I expected at least my IDE to snap at A.Ret(), but nothing happens whatsoever.

File Test.cs

using System.Web;
public class A
{
    public static string ret() {
        var c = HttpContext.Current;
        var v = c.Request.QueryString; // <-- I can see get data in this
        return c.Request.UserAgent.ToString();
        return c.Request.UserHostAddress.ToString();
        return "woot";
    }
}

File Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="aspnetCSone._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>

    <body>
        <form id="form1" runat="server" method="post" action="Default.aspx">
            <input type=hidden name="AP" value="99" />
            <input type=button value="Submit" />
            <div>
                <a id="aa">a</a>
                <% = A.ret() %>
            </div>
        </form>
    </body>
</html>

This question is related to c# asp.net

The answer is


Try using:

string ap = c.Request["AP"];

That reads from the cookies, form, query string or server variables.

Alternatively:

string ap = c.Request.Form["AP"];

to just read from the form's data.


Similar questions with c# tag:

Similar questions with asp.net tag: