ASPNET Program Based 2
ASPNET Program Based 2
// Missing line
Response.Cookies.Add(cookie);
• A) cookie.Expires = DateTime.Now.AddHours(1);
• B) cookie.Path = "/";
• C) cookie.Secure = true;
• D) cookie.HttpOnly = true;
• Answer: A) cookie.Expires = DateTime.Now.AddHours(1);
// Missing line
// Missing line
Response.Cookies.Add(cookie);
• cookie.Expires = DateTime.Now.AddDays(-1);
• B) cookie.Path = "/";
• C) cookie.Secure = true;
• D) cookie.HttpOnly = true;
• Answer: A) cookie.Expires = DateTime.Now.AddDays(-1);
What is the missing line of code to check if a cookie exists in ASP.NET?
// Missing line
if (cookie != null)
What is the missing line of code to set a secure flag for a cookie in ASP.NET?
// Missing line
Response.Cookies.Add(cookie);
• A) cookie.Expires = DateTime.Now.AddHours(1);
• B) cookie.Path = "/";
• C) cookie.Secure = true;
• D) cookie.HttpOnly = true;
• Answer: C) cookie.Secure = true;
What is the missing line of code to bind a form field to a model property in a Razor Page in ASP.NET?
<form method="post">
// Missing line
<button type="submit">Submit</button>
</form>
• A) asp-for="name"
• B) asp-route="name"
• C) asp-validation-for="name"
• D) asp-items="name"
• Answer: A) asp-for="name"
What is the missing line of code to display a model property value in a Razor Page in ASP.NET?
<h1>Message: @Model.Message</h1>
// Missing line
• A) @{ ViewData["Message"] = Model.Message; }
• B) @{ ViewBag.Message = Model.Message; }
• C) @{ TempData["Message"] = Model.Message; }
• D) @{ Html.DisplayFor(m => m.Message); }
• Answer: A) @{ ViewData["Message"] = Model.Message; }
Which component in MVC is responsible for interacting with the database and
managing application data?
• A) Model
• B) View
• C) Controller
• D) ViewModel
• Answer: A) Model
What is the missing line of code to redirect the user after successful login
authentication in an ASP.NET Web Forms login page?
if (IsValid)
// Missing line
• A) Response.Redirect("~/Home.aspx");
• B) Server.Transfer("~/Home.aspx");
• C) Response.RedirectToRoute("Home");
• D) Server.TransferRequest("~/Home.aspx");
• Answer: A) Response.Redirect("~/Home.aspx");
What happens when a user successfully logs in using the provided ASP.NET
login program?
• A) The user's username and password are stored in a database
• B) The user is redirected to a specific homepage based on their credentials
• C) The user's session ID is invalidated
• D) The user's password is encrypted and stored in a cookie
• Answer: B) The user is redirected to a specific homepage based on their
credentials
What does the Session["username"] != null condition check for in the provided
ASP.NET login program?
• A) Whether the user's session has expired
• B) Whether the user's username is not empty
• C) Whether the user is currently logged in
• D) Whether the user's password is correct
• Answer: C) Whether the user is currently logged in
What is the missing line of code to clear the session after a user logs out?
// Missing line
• A) Session.Clear();
• B) Session.Abandon();
• C) Session.Remove("username");
• D) Session.RemoveAll();
• Answer: B) Session.Abandon();
What is the missing line of code to prevent unauthorized access to the user's
homepage by directly entering the URL without logging in?
// Missing line
if (Session["username"] == null)
}
}
• A) CheckUserAuthorization();
• B) CheckLoggedIn();
• C) CheckSession();
• D) CheckLoginStatus();
• Answer: C) CheckSession();