C# E Mvc

20 Questions | Attempts: 135
Share

SettingsSettingsSettings
Visual Basic Quizzes & Trivia

This is your description.


Questions and Answers
  • 1. 

    You are creating an MVC application for a retail store website. You are defining a route that users can access to find stores in the United States that have a specific ZIP Code. You expect users to request URLs that include the five-digit ZIP Code, such as http://contoso.com/Store/Find/06385. You define the route as shown in the following code example. routes.MapRoute(    "StoreFind",    "Store/Find/{zipCode}",    new { controller = "Store", action = "Find" } ); You need to modify the route so that the application returns an "HTTP Error 404 - File Not Found" error message when a user enters an invalid URL. Which code segment should you use?

    • A.

      routes.MapRoute(     "StoreFind",     "Store/Find/{zipCode}",     new { controller = "Store", action = "Find" },     new { zipCode = (int > 10000 && int < 100000) });

    • B.

      routes.MapRoute(     "StoreFind",     "Store/Find/{zipCode}",     new { controller = "Store", action = "Find" },     new { zipCode = @"^\d{5}$" } );

    • C.

      routes.MapRoute(     "StoreFind",     "Store/Find/{zipCode}",     new { controller = "Store", action = "Find" },     where ( zipCode = (int > 10000 && int < 100000) ) } );

    • D.

      routes.MapRoute(     "StoreFind",     "Store/Find/{zipCode}",     new { controller = "Store", action = "Find" },     where ( zipCode == @"^\d{5}$" ) } );

    Correct Answer
    B. routes.MapRoute(     "StoreFind",     "Store/Find/{zipCode}",     new { controller = "Store", action = "Find" },     new { zipCode = @"^\d{5}$" } );
  • 2. 

    You are creating an MVC application for a retail website. The routing is shown in the following code example. public static void RegisterRoutes(RouteCollection routes) {    routes.MapRoute(        "Search",        "Store/Search/{product}",        new { controller = "Store", action = "Search", id = "" }    ); } You need to configure MVC to ignore requests for files that have the file name extension .js. Which code segment should you add to the beginning of the RegisterRoutes method?

    • A.

      Routes.Remove("{resource}.axd/{*pathInfo}");

    • B.

      Routes.IgnoreRoute("{resource}.js/{*pathInfo}");

    • C.

      Routes.IgnoreRoute(routes.GetVirtualPath("*.js"));

    • D.

      Routes.Remove(routes.GetVirtualPath("*.js");

    Correct Answer
    B. Routes.IgnoreRoute("{resource}.js/{*pathInfo}");
  • 3. 

    You are creating an MVC application. You need to create a route restraint to verify that part of the requested URL is contained within a database. Which action should you perform?

    • A.

      Create a Boolean static method that returns True when a provided value is contained within the database, and create a constraint by using the static method.

    • B.

      Create a regular expression constraint that uses LINQ syntax to query the database for the requested value.

    • C.

      Create a custom class that derives from the IRouteConstraint interface, implement the Match() method, and create a constraint by using the custom class.

    • D.

      Load all possible values from the database into a collection. Create a regular expression constraint that searches the collection for the value.

    Correct Answer
    C. Create a custom class that derives from the IRouteConstraint interface, implement the Match() method, and create a constraint by using the custom class.
  • 4. 

    You are updating an MVC application. You need to change the default route so that a different controller handles requests that don't match other routes. Which file should you edit?

    • A.

      Web.config

    • B.

      DefaultController.cs

    • C.

      FallbackController.cs

    • D.

      Global.asax.cs

    Correct Answer
    D. Global.asax.cs
  • 5. 

    You are updating the routing in an MVC application. The route definitions are shown in the following code example. public static void RegisterRoutes(RouteCollection routes) {    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");    routes.MapRoute(        "Default", // Route name        "{controller}/{action}/{id}", // URL with parameters        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults    ); } When a user submits a request for the URL http://<hostname>/Hello/World/15, which method will MVC attempt to run?

    • A.

      HelloController.World(15)

    • B.

      WorldController.Hello(15)

    • C.

      HelloWorld(15)

    • D.

      HelloController.WorldAction(15)

    Correct Answer
    A. HelloController.World(15)
  • 6. 

    You are creating a custom MVC action filter to cache action results. Which virtual method should you override?

    • A.

      ActionFilterAttribute.OnResultExecuted()

    • B.

      ActionFilterAttribute.OnResultExecuting()

    • C.

      ActionFilterAttribute.OnActionExecuting()

    • D.

      ActionFilterAttribute.OnActionExecuted()

    Correct Answer
    B. ActionFilterAttribute.OnResultExecuting()
  • 7. 

    You are updating the routing in an MVC application. The route definitions are as shown in the following code example. public static void RegisterRoutes(RouteCollection routes) {    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");    routes.MapRoute(        "Default", // Route name        "{controller}/{action}/{id}",        new { controller = "Home", action = "Index", id = UrlParameter.Optional }    ); } When a user submits a request for the website's root page, which action will MVC perform?

    • A.

      Return an "HTTP Error 501 - Not Implemented" error message.

    • B.

      Call the HomeController.Home() method.

    • C.

      Return an "HTTP Error 404 - File Not Found" error message.

    • D.

      Call the HomeController.Index() method.

    Correct Answer
    D. Call the HomeController.Index() method.
  • 8. 

    You are reviewing an MVC application that contains the route definitions shown in the following code example. public static void RegisterRoutes(RouteCollection routes) {    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");    routes.MapRoute(        "Default", // Route name        "{controller}/{action}/{id}",        new { controller = "Home", action = "Index", id = UrlParameter.Optional }    ); } The Home controller is defined as: [HandleError] public class HomeController : Controller {    public ActionResult Index(int id)    {        return View();    } } Which action will occur when a user submits a request for http://<host>/Home/?

    • A.

      ASP.NET automatically generates a Web form that prompts the user for an ID.

    • B.

      ASP.NET returns an "HTTP Error 404 - File Not Found" error message.

    • C.

      ASP.NET throws an exception.

    • D.

      ASP.NET successfully processes the Index action of the Home controller.

    Correct Answer
    C. ASP.NET throws an exception.
  • 9. 

    You are creating an action for the MVC Home controller. The controller will be called only by an AJAX JavaScript script, which will dynamically place the server time inside a Label control. You define the action as shown in the following code example. public ActionResult AJAXResponder() {    // TODO: Return value } You need to return only a string, without any HTML. Which return parameter should you use?

    • A.

      Return Content(DateTime.Now.ToString())

    • B.

      Return DateTime.Now

    • C.

      Return View(DateTime.Now.ToString())

    • D.

      Return JavaScriptResult(DateTime.Now.ToString())

    Correct Answer
    A. Return Content(DateTime.Now.ToString())
  • 10. 

    You are creating an MVC action that binds to an HTML form. The action will be called when a user clicks a link that matches the link's server-side MVC route. When the user completes the form and clicks the Submit button, the action will be called again with the form data by using an HTTP POST request. You need to configure the action methods so that GET and POST requests for the same page are processed by different methods. What are two possible ways to achieve this goal? (Each correct answer presents a complete solution. Choose two.)

    • A.

      Decorate both action methods with the AcceptVerbs attribute. Set the AcceptVerbs values to HttpVerbs.Get and HttpVerbs.Post.

    • B.

      When processing the route, examine the HttpRequest object. Route the request based on whether the request is a GET request or a POST request.

    • C.

      Create separate route maps, and use the HttpMethodConstraints route constraint to limit requests to different actions for GET and POST requests.

    • D.

      Decorate both action methods with the Authorize attribute. Set the RequestType property for the Authorize attribute to Get or Post.

    Correct Answer(s)
    A. Decorate both action methods with the AcceptVerbs attribute. Set the AcceptVerbs values to HttpVerbs.Get and HttpVerbs.Post.
    C. Create separate route maps, and use the HttpMethodConstraints route constraint to limit requests to different actions for GET and POST requests.
  • 11. 

    You are updating an MVC application. You move models, views, and controllers to different areas of the application. After you move the files, you discover that ActionLinks between views in different areas no longer work. One of the ActionLinks is shown in the following code example. <%= Html.ActionLink("Browse Products", "BrowseProducts", "Browse") %> You need to update the ActionLink to reference a view that is located in an area named Store. Which code segment should you use?

    • A.

    • B.

    • C.

    • D.

    Correct Answer
    B.
  • 12. 

    You are a creating a strongly typed view for an MVC application. The view is typed by using an Address class. The Address class contains properties for Street, City, and State. You need to render a text box containing the value of the Address.Street property. What are two possible ways to achieve this goal? (Each correct answer presents a complete solution. Choose two.)

    • A.

    • B.

      model.Street) %>

    • C.

    • D.

    • E.

    Correct Answer(s)
    B. model.Street) %>
    E.
  • 13. 

    You are implementing an ASP. NET MVC Web application. You add a controller named CompanyController. You need to modify the application to handle the URL path /company/info. Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

    • A.

      Add the following method to the CompanyController class. public ActionResult Info () { return View(); }

    • B.

      Add the following method to the CompanyController class. public ActionResult Company_Info() { return View(); }

    • C.

      Right-click the Views folder, and select View from the Add submenu to create the view for the action.

    • D.

      Right-click inside the action method in the CompanyController class, and select Add View to create a view for the action.

    Correct Answer(s)
    A. Add the following method to the CompanyController class. public ActionResult Info () { return View(); }
    D. Right-click inside the action method in the CompanyController class, and select Add View to create a view for the action.
  • 14. 

    Which .NET collection class allows elements to be accessed using a unique key? 

    • A.

      ListDictionary

    • B.

      Stack

    • C.

      Hashtable

    • D.

      ArrayList

    • E.

      StringCollection

    Correct Answer
    C. Hashtable
  • 15. 

    Will the finally block get executed if an exception has not occurred?

    • A.

      Yes

    • B.

      No

    Correct Answer
    A. Yes
  • 16. 

    Can multiple catch blocks be executed for a single try statement?

    • A.

      Yes

    • B.

      No

    Correct Answer
    B. No
  • 17. 

    Which common design pattern is shown below?   public class A  {     private A instance;     private A() { }     public static A Instance      {       get       {         if(instance == null)           instance = new A();         return instance;       }     } }

    • A.

      Factory

    • B.

      Abstract Factory

    • C.

      Singleton

    • D.

      Builder

    Correct Answer
    C. Singleton
  • 18. 

    Can you change the value of a variable while debugging a C# application?

    • A.

      Yes

    • B.

      No

    Correct Answer
    A. Yes
  • 19. 

    Check all statements that are true.

    • A.

      Every process runs in a thread

    • B.

      Every thread runs in a process

    • C.

      A process can have multiple threads

    • D.

      A thread can have multiple processes

    • E.

      All threads run in the same process

    Correct Answer(s)
    A. Every process runs in a thread
    B. Every thread runs in a process
    C. A process can have multiple threads
  • 20. 

    You are troubleshooting an ASP.NET Web application. System administrators have recently expanded your web farm from one to two servers. Users are periodically reporting an error message about invalid view state. You need to fix the problem. What should you do?

    • A.

      Set viewStateEncryptionMode to Auto in web.config on both servers.

    • B.

      Set the machineKey in machine.config to the same value on both servers.

    • C.

      Change the session state mode to SQLServer on both servers and ensure both servers use the same connection string.

    • D.

      Override the SavePageStateToPersistenceMedium and LoadPageStateFromPersistenceMedium methods in the page base class to serialize the view state to a local web server file.

    Correct Answer
    B. Set the machineKey in machine.config to the same value on both servers.

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Aug 15, 2013
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 15, 2013
    Quiz Created by
    Rafaelberto
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.