1.
You are implementing an ASP.NET application. You add the following code segment.
public List GetNonSecretUsers()
{
string[] secretUsers = {"@secretUser", "@admin", "@root"}; List allpeople = GetAllPeople();
... }
You need to add code to return a list of all Person objects except those with a UserId that is contained in the secretUsers list. The resulting list must not contain duplicates.
Which code segment should you use?
2.
You are implementing a WCF service library.
You add a new code file that contains the following code segment.
namespace ContosoWCF
{
[ServiceContract]
public interface IRateService
{
[OperationContract]
decimal GetCurrentRate();
}
public partial class RateService : IRateService
{
public decimal GetCurrentRate()
{
decimal currentRate = GetRateFromDatabase();
return currentRate;
}
}
}
You build the service library and deploy its assembly to an IIS application. You need to ensure that the
GetCurrentRate method can be called from JavaScript.
What should you do?
3.
You are implementing an ASP.NET Dynamic Data Web site.
The Web site includes a data context that enables automatic scaffolding for all tables in the data model. The
Global.asax.cs file contains the following code segment. public static void RegisterRoutes(RouteCollection
routes) { {
routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") {
Action = PageAction.List,
ViewName = "ListDetails",
Model = DefaultModel
});
routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") {
Action = PageAction.Details,
ViewName = "ListDetails",
Model = DefaultModel
});
}
You need to display the items in a table named Products by using a custom layout.
What should you do?
4.
You create a new ASP.NET MVC 2 Web application. The following default routes are created in the
Global.asax.cs file. (Line numbers are included for reference only.) 01 public static void RegisterRoutes
(RouteCollection routes) 02 {
03 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
05 routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
06 }
You implement a controller named HomeController that includes methods with the following signatures.
public ActionResult About()
public ActionResult Index()
public ActionResult Details(int id)
You need to ensure that the About action is invoked when the root URL of the site is accessed.
What should you do?
5.
You create a new ASP.NET MVC 2 Web application. The following default routes are created in the
Global.asax.cs file. (Line numbers are included for reference only.) 01 public static void RegisterRoutes
(RouteCollection routes) 02 {
03 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
05 routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
06 }
You implement a controller named HomeController that includes methods with the following signatures.
public ActionResult Index()
public ActionResult Details(int id)
public ActionResult DetailsByUsername(string username)
You need to add a route to meet the following requirements. ?The details for a user must to be displayed when
a user name is entered as the path by invoking the DetailsByUsername action.
?User names can contain alphanumeric characters and underscores, and can be between 3 and 20 characters long.
What should you do?
6.
You are implementing an ASP.NET MVC 2 Web application.
The URL with path /Home/Details/{country} will return a page that provides information about the named country.
You need to ensure that requests for this URL that contain an unrecognized country value will not be processed by the Details action of HomeController.
What should you do?
7.
You create an ASP.NET MVC 2 Web application. You implement a single project area in the application. In the Areas folder, you add a subfolder named Test. You add files named TestController.cs and Details.aspx to the appropriate subfolders.
You register the area's route, setting the route name to test_default and the area name to test. You create a view named Info.aspx that is outside the test area. You need to add a link to Info.aspx that points to Details.aspx.
Which code segment should you use?
8.
You are implementing an ASP.NET MVC 2 application. In the Areas folder, you add a subfolder named Product to create a single project area.
You add files named ProductController.cs and Index.aspx to the appropriate subfolders. You then add a file named Route.cs to the Product folder that contains the following code. (Line numbers are included for reference only.)
01 public class Routes : AreaRegistration
02 {
03 public override string AreaName
04 {
05 get { return "product"; }
06 }
08 public override void RegisterArea(AreaRegistrationContext context)
09 {
10 context.MapRoute("product_default",
"product/{controller}/{action}/{id}",
new { controller = "Product", action = "Index",
id = "" });
11 }
12 }
When you load the URL http:///product, you discover that the correct page is not returned.
You need to ensure that the correct page is returned.
What should you do?
9.
You are implementing an ASP.NET MVC 2 Web application.
You create a shared user control named MenuBar.ascx that contains the application's menu.
You need to use the menu bar in all application views.
What should you do?
10.
You are implementing an ASP.NET MVC 2 Web application that contains several folders. The Views/Shared/
DisplayTemplates folder contains a templated helper named Score.ascx that performs custom formatting of integer values.
The Models folder contains a class named Player with the following definition.
public class Player
{
public String Name { get; set; }
public int LastScore { get; set; }
public int HighScore { get; set; }
}
You need to ensure that the custom formatting is applied to LastScore values when the
HtmlHelper.DisplayForModel method is called for any view in the application that has a model of type Player.
What should you do?