MCTS ASP.NET Web Applications 3 — Questions and Answers
Question 1: In ASP.NET MVC, which filter type runs before and after controller action methods and can short-circuit the pipeline?
- Exception filters
- Result filters
- Action filters (Correct answer)
- Authorization filters
Correct answer: Action filters
Action filters implement IActionFilter and provide OnActionExecuting and OnActionExecuted hooks that wrap action method execution and can cancel the request.
Question 2: Which ASP.NET configuration element is used to define custom error pages for specific HTTP status codes?
- <httpErrors> in system.webServer
- <customErrors> in system.web (Correct answer)
- <errorPages> in system.web
- <statusCodes> in system.webServer
Correct answer: <customErrors> in system.web
The <customErrors> element in system.web allows you to specify redirect URLs for specific HTTP error status codes such as 404 or 500.
Question 3: What does the ValidateAntiForgeryToken attribute protect against in ASP.NET MVC?
- SQL injection attacks in form submissions
- Cross-site request forgery (CSRF) attacks (Correct answer)
- Cross-site scripting (XSS) in view output
- Session fixation attacks
Correct answer: Cross-site request forgery (CSRF) attacks
ValidateAntiForgeryToken verifies a hidden token in form submissions matches a cookie token, preventing malicious third-party sites from submitting forms on behalf of authenticated users.
Question 4: Which ASP.NET class provides access to the current user's identity and roles within a request?
- HttpContext.User (Correct answer)
- Session["CurrentUser"]
- Request.ServerVariables["AUTH_USER"]
- Thread.CurrentPrincipal
Correct answer: HttpContext.User
HttpContext.User exposes an IPrincipal object containing the current user's IIdentity and role memberships as set by the authentication module.
Question 5: In ASP.NET Web Forms, which event in the page lifecycle fires last before the HTML is rendered to the browser?
- Page_Load
- Page_PreRender (Correct answer)
- Page_Init
- Page_Render
Correct answer: Page_PreRender
PreRender is the last event before rendering where you can make final changes to the page or controls before their HTML output is generated.
Question 6: Which method on the UpdatePanel control's AsyncPostBackTrigger allows you to specify which control event initiates a partial-page update?
- ControlID and EventName properties (Correct answer)
- TriggerSource and TriggerEvent properties
- AsyncTrigger and EventHandler properties
- SourceControl and TriggeredEvent properties
Correct answer: ControlID and EventName properties
AsyncPostBackTrigger uses the ControlID property to identify the triggering control and EventName to specify which event on that control initiates the async postback.
Question 7: What is the purpose of the RouteConfig class in an ASP.NET MVC application?
- It defines database connection routing between multiple SQL servers
- It registers URL routing rules that map URLs to controller actions (Correct answer)
- It configures load balancing between multiple web servers
- It maps HTTP verbs to controller method names automatically
Correct answer: It registers URL routing rules that map URLs to controller actions
RouteConfig.RegisterRoutes() is called at application startup to define URL patterns and their mappings to controller and action names in the route table.
In ASP.NET MVC, which filter type runs before and after controller action methods and can short-circuit the pipeline?