Practical-04
Problem Statement
Write a program to demonstrate Request, Response, and Server Object.
Solution
To solve this problem, we can use ASP.NET and C# to create a web form and demonstrate the usage of Request, Response, and Server objects.
- Create a new ASP.NET Web Application project in Visual Studio.
- In the Solution Explorer, right-click on the project name and select "Add New Item".
- Choose "Web Form" from the templates and name it "RequestResponseServer.aspx".
- Open the newly created "RequestResponseServer.aspx" file.
- In the HTML body section, add the following code:
<h1>Request, Response, and Server Object</h1>
<form method="post" action="RequestResponseServer.aspx">
<label for="name">Enter your name:</label>
<input type="text" id="name" name="name" required>
<br>
<input type="submit" value="Submit">
</form>
<%
if (Request.HttpMethod == "POST")
{
string name = Request.Form["name"];
Response.Write("Hello, " + name + "!<br>");
Response.Write("Server name: " + Server.MachineName + "<br>");
Response.Write("Server IP address: " + Request.ServerVariables["LOCAL_ADDR"] + "<br>");
}
%>
-
Save the file.
-
Build and run the project.
-
The web form will be displayed with a heading "Request, Response, and Server Object" and a form to enter your name.
-
Enter your name and click the "Submit" button.
-
The web form will display a greeting message with your name and information about the server, including the server name and IP address.
This completes the solution to the problem.
Summary
In this practical, we learned how to create a web form using ASP.NET and demonstrate the usage of Request, Response, and Server objects to interact with the client and server.