-2

In php there is a $_POST variable for retrieving post data. I haven’t found the C# equivalent.

The html below is a very simple setup , not representative of the actual code. A user clicks on one of the buttons/input tag, the form launches Apost which retrieves the posted value.

If I use Apost.php rather than Apost a C# routine, then I can use $_POST. What C# interface can I use under Apache in Unix/MacOs world?

Thank you

<html>
<head>
<title>Apost Launcher</title></head>
Apost
 <form method="post" action="/cgi-bin/Apost" id="form1">

 <input id='yyyymm20232' name='yyyymm20232' type='submit' value='2023-F    ebruary&nbsp;&nbsp;(0.22)' class='WuRainMonth'/>

 <input id='yyyymm20231' name='yyyymm20231' type='submit' value='2023-January&nbsp;&nbsp;(0.91)' class='WuRainMonth'/>
 </form>

</body>
</html>

I’ve looked into Environment values. All googling shows WebRequst/WebResponse examples. Not useful!

This ought to be simple!

DanR
  • 9
  • 5
  • How are you currently making endpoints in your C# application? WebRequest is for _making_ requests, using the Endpoint middleware in ASP.Net is for handling requests. – gunr2171 Feb 22 '23 at 17:45

1 Answers1

0

Are you able to use ASP.Net with Razor Pages with your setup?

I have found an example on Microsoft Learn with Razor Pages.

Form.cshtml:

<!DOCTYPE html>
<html>
    <head>
        <title>Customer Form</title>
    </head>
    <body>
      <form method="post" >
        <fieldset>
          <legend>Add Customer</legend>
          <div>
            <label for="CompanyName">Company Name:</label>
            <input type="text" name="CompanyName" value="" />
          </div>
          <div>
            <label for="ContactName">Contact Name:</label>
            <input type="text" name="ContactName" value="" />
          </div>
          <div>
            <label for="Employees">Employee Count:</label>
            <input type="text" name="Employees" value="" />
          </div>
          <div>
            <label>&nbsp;</label>
            <input type="submit" value="Submit" class="submit" />
          </div>
        </fieldset>
      </form>
    </body>
</html>

HTML Form Image

Now you can add Razor Syntax above the html:

@{
    if (IsPost) {
        string companyname = Request.Form["companyname"];
        string contactname = Request.Form["contactname"];
        int employeecount = Request.Form["employees"].AsInt();

        <text>
          You entered: <br />
          Company Name: @companyname <br />
          Contact Name: @contactname <br />
          Employee Count: @employeecount <br />
        </text>
    }
}

IsPost would be the variable you search for. But I think its only valid in this context with the form.

In other scenarios you might want to use the ASP Net API Controllers? Or if its simply handling input from the user, I would recommend using Razor, so you can combine C# and HTML.

Guy
  • 16
  • 3
  • Thanks for the info. I don’t have a Asp.Net with Razor environment, that is tempting but a bit of a learning curve. I’ll probably give that a try. – DanR Feb 23 '23 at 22:23
  • I did try the Request.Form method in my environment and perhaps I don’t know the correct include, but the compiler doesn’t like it. Thanks again. – DanR Feb 23 '23 at 22:27