create controller with methods Get and Post in web form in asp.net and hit the postman
Loading
create controller with methods Get and Post in web form in asp.net and hit the postman
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted Mar 16, 2023, 5:34 AM
Hi Tarun,
Please refer webform with API,
https://www.c-sharpcorner.com/article/using-web-api-with-asp-net-web-forms-part-seven/
https://learn.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/using-web-api-with-aspnet-web-forms
Test API using Postman,
https://www.c-sharpcorner.com/article/how-to-use-postman-with-asp-net-core-web-api-testing/
https://dotnettutorials.net/lesson/how-to-use-postman-to-test-web-api/
Vishal YelvePosted Mar 15, 2023, 6:57 PM
Hi Tarun,
Please refer below link, hope this is what you are looking.
https://www.c-sharpcorner.com/article/using-web-api-with-asp-net-web-forms-part-seven/
TarunPosted Mar 15, 2023, 9:28 AM
Without Using MVC like I am Using Webforms in WebApi Controller
Tuhin PaulPosted Mar 15, 2023, 9:12 AM
Hi Tarun,
Follow these steps:Step1: In your ASP.NET Web Form application, right-click on the project in the Solution Explorer and select "Add" > "Controller...".
Step2: In the "Add Controller" dialog, select "MVC 5 Controller - Empty" and give the controller a name (e.g. "SampleController").
Step3: Click "Add" to create the controller.
Step4: In the "SampleController.cs" file that was created, add the following code:
This code defines a controller called "SampleController" with two methods: "Index()" and "Index(FormCollection collection)". The first method is a GET method that returns a view, and the second method is a POST method that processes form data.
Step5: To test the controller with Postman, open Postman and create a new request.
Step6: In the request URL field, enter the URL of your ASP.NET Web Form application followed by "/Sample" (e.g. "http://localhost:12345/Sample").
Step7: Select the HTTP method "POST" and go to the "Body" tab.
Step8: Select "x-www-form-urlencoded" as the body type and enter some form data in the "Key" and "Value" fields.
Step9: Click "Send" to send the request to your ASP.NET Web Form application.
Step10: In the SampleController.cs file, set a breakpoint in the POST method to verify that it is being called.
Step11: Run the application and send the request again. The breakpoint should be hit, allowing you to debug the POST method and verify that the form data is being processed correctly.