WebPages Objects
ASP.NET WebPages provides built-in objects that help you interact with the server, manage requests, and store data. These objects include Request
, Response
, Session
, and Application
.
Key Topics
Request Object
Example
@{
var userInput = Request["input"];
}
<form method="get">
<input type="text" name="input" placeholder="Enter something" />
<button type="submit">Submit</button>
</form>
<p>You entered: @userInput</p>
Explanation: The Request
object retrieves data sent via GET or POST methods. Here, it fetches the value of the input
field.
Additional Example
@{
var queryParam = Request.QueryString["id"];
}
<p>Query Parameter: @queryParam</p>
Explanation: The Request.QueryString
property accesses query string parameters sent in the URL.
Response Object
Example
@{
Response.Redirect("/Home");
}
Explanation: The Response.Redirect
method sends the user to a different page.
Session Object
Example
@{
Session["Username"] = "JohnDoe";
}
<p>Welcome, @Session["Username"]!</p>
Explanation: The Session
object stores user-specific data that persists across pages during a user session.
Key Takeaways
- The
Request
object retrieves user input and query string data. - The
Response
object manages server responses and redirections. - The
Session
object allows for temporary storage of user-specific data.