[Free] Get all latest Microsoft 70-515 Actual Tests 101-110

Ensurepass

QUESTION 101

You are developing an ASP.NET MVC 2 application. A view contains a form that allows users to submit their first name. You need to display the value that is submitted, and you must ensure that your code avoids cross-site scripting. Which code segment should you use?

 

A.

<%: Model.FirstName %>

B.

<%= Model.FirstName %>

C.

<% Response.Write(Model.FirstName); %>

D.

<% Response.Write(HttpUtility.HtmlDecode(Model.FirstName)); %>

 

Correct Answer: A

Explanation:

CHAPTER 14 Creating Websites with ASP.NET MVC 2

Lesson 2: Creating Models, Views, and Controllers Creating Views – Creating Strongly Typed Views (page 859)

 

 

QUESTION 102

You are developing an ASP.NET Web page.

 

You add the following markup to the page.

 

<asp:FileUpload id=”FileUpload1″ runat=”server” />

 

<asp:Button id=”btnUpload” Text=”Upload selected file”

 

OnClick=”btnUpload_Click” runat=”server” />

 

<asp:Label id=”lblFeedback” runat=”server” />

 

You add the following code segment to the code-behind. (Line numbers are included for reference only.)

 

01 protected void btnUpload_Click(object sender,

 

EventArgs e)

 

02 {

 

03 if ()

 

04 {

 

05 string saveName = Path.Combine(@”c:uploadedfiles”,

 

FileUpload1.FileName);

 

06

 

07 lblFeedback.Text = “File successfully uploaded.”;

 

08 }

 

09 else

 

10 {

 

11 lblFeedback.Text = “File upload failed.”;

 

12 }

 

13 }

 

You need to save the uploaded file and display a message to the user that indicates that the upload either succeeded or failed.

 

Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

 

A.

Replace line 03 with the following code segment.

if (FileUpload1.HasFile)

B.

Replace line 03 with the following code segment.

if (FileUpload1.FileContent.Length > 0)

C.

Insert the following code segment at line 06.

FileUpload1.SaveAs(saveName);

D.

Insert the following code segment at line 06. FileUpload1.FileContent.CopyTo(new FileStream(saveName, FileMode.Open));

 

Correct Answer: AC

Explanation:

CHAPTER 4 Using Server Controls

Lesson 2: Exploring Specialized Server Controls

The FileUpload Control (page 202-204)

 

 

QUESTION 103

You are implementing a Web page that allows users to upload files to a Web server. The page includes a form that has a Submit button. You need to reject files larger than 1 MB.

What should you do?

 

A.

Add an HTML input type= file control. Add an onSubmit handler to the form to check the file size and cancel the form submission if the file size is too large.

B.

Add an HTML input type= file control. Add an onChange handler to the input control to check the file size and cancel the upload if the file size is too large.

C.

Add an ASP.NET FileUpload control and configure it to run on the server. Add a server- side OnClick handler to the form’s Submit button to save the file only if the file size is allowed.

D.

Add an ASP.NET FileUpload control and configure it to run on the server. Add a server- side OnDataBinding handler that saves the file only if the file size is allowed.

 

Correct Answer: C

 

 

QUESTION 104

You create a Web page named TestPage.aspx and a user control named TestUserControl.ascx. TestPage.aspx uses TestUserControl.ascx as shown in the following line of code.

 

<uc:TestUserControl ID=”testControl” runat=”server”/>

 

On TestUserControl.ascx, you need to add a read-only member named CityName to return the value “New York”. You also must add code to TestPage.aspx to read this value.

 

Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

 

A.

Add the following line of code to the TestUserControl.ascx.cs code-behind file.

public string CityName {

get { return “New York” ; }

}

B.

Add the following line of code to the TestUserControl.ascx.cs code-behind file.

protected readonly string CityName = “New York” ;

C.

Add the following code segment to the TestPage.aspx.cs code-behind file.

protected void Page_Load(object sender, EventArgs e) {

strings = testControl.CityName;

}

D.

Add the following code segment to the TestPage.aspx.cs code-behind file.

protected void Page_Load(object sender, EventArgs e)

{

string s = testControl.Attributes[“CityName”];

}

 

Correct Answer: AC

Explanation:

CHAPTER 7 Creating Custom Web Controls

Lesson 1: Creating User Controls

Defining Properties in User Controls (page 337-339)

 

 

QUESTION 105

You use the following declaration to add a Web user control named TestUserControl.ascx to an ASP.NET page named TestPage.aspx.

 

<uc:TestUserControl ID=”testControl” runat=”server”/>

 

You add the following code to the code-behind file of TestPage.aspx.

 

private void TestMethod()

 

{

 

 

}

 

You define the following delegate.

 

public delegate void MyEventHandler();

 

You need to add an event of type MyEventHandler named MyEvent to TestUserControl.ascx and attach the page’s TestMethod method to the event.

 

Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

 

A.

Add the following line of code to TestUserControl.ascx.cs.

public event MyEventHandler MyEvent;

B.

Add the following line of code to TestUserControl.ascx.cs.

public MyEventHandler MyEvent;

C.

Replace the TestUserControl.ascx reference in TestPage.aspx with the following declaration.

<uc:TestUserControl ID=”testControl” runat=”server” OnMyEvent=”TestMethod”/>

D.

Replace the TestUserControl.ascx reference in TestPage.aspx with the following declaration.

<uc:TestUserControl ID=”testControl” runat=”server” MyEvent=”TestMethod”/>

 

Correct Answer: AC

Explanation:

CHAPTER 7 Creating Custom Web Controls

Lesson 1: Creating User Controls

Defining User Control Events (page 333-337)

 

 

QUESTION 106

You are implementing an ASP.NET Web site that uses a custom server control named Task. Task is defined as shown in the following list.

 

clip_image002Class name: Task

clip_image002[1]Namespace: DevControls

clip_image002[2]Assembly: TestServerControl.dll

clip_image002[3]Base class: System.Web.UI.WebControls.WebControl

 

You copy TestServerControl.dll to the Web sites Bin folder.

 

You need to allow the Task control to be declaratively used on site pages that do not contain an explicit @ Register directive.

 

Which configuration should you add to the web.config file?

 

A.

<appSettings>

<add key=”Dev:Task”

value=”DevControls, DevControls.Task”/>

</appSettings>

B.

<compilation targetFramework=”4.0″ explicit=”false”> <assemblies>

<add assembly=”TestServerControl” />

</assemblies>

</compilation>

C.

<pages>

<controls>

<add assembly=”TestServerControl” namespace=”DevControls” tagPrefix=”Dev”/>

</controls>

</pages>

D.

<pages>

<tagMapping>

<add tagType=”System.Web.UI.WebControls.WebControl” mappedTagType=”DevControls.Task”/>

</tagMapping>

</pages>

 

Correct Answer: C

Explanation:

CHAPTER 7 Creating Custom Web Controls

Lesson 2: Creating Custom Web Server Controls

Registering Your Controls in Web.config (page 378-379)

 

 

QUESTION 107

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}”);

 

04

 

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:

 

clip_image002[4]The details for a user must be displayed when a user name is entered as the path by invoking the DetailsByUsername action.

clip_image002[5]User names can contain alphanumeric characters and underscores, and can be between 3 and 20 characters long.

 

What should you do?

 

A.

Replace line 05 with the following code segment.

routes.MapRoute(“Default”, “{controller}/{action}/{id}”, new {controller = “Home”, action = “DetailsByUsername”, id = “”});

B.

Replace line 05 with the following code segment.

routes.MapRoute(“Default”, “{controller}/{action}/{username}”, new {controller = “Home”, action = “DetailsByUsername”, username = “”}, new {username = @”w {3,20}”});

C.

At line 04, add the following code segment.

routes.MapRoute(“Details by Username”, “{username}”, new {controller = “Home”, action = “DetailsByUsername”}, new {username = @”w{3,20}”});

D.

At line 04, add the following code segment.

routes.MapRoute(“Details by Username”, “{id}”, new {controller = “Home”, action = “DetailsByUsername”}, new {id = @”w{3,20}”});

 

Correct Answer: C

 

 

QUESTION 108

You are implementing an ASP. NET MVC 2 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: AD

Explanation:

CHAPTER 14 Creating Websites with ASP.NET MVC 2

Lesson 2: Creating Models, Views, and Controllers Creating Controllers, Creating Views (page 851-857)

 

 

QUESTION 109

You are implementing an ASP.NET MVC 2 Web application that contains the following class.

 

public class DepartmentController : Controller

 

{

 

static List<Department> departments =

 

new List<Department>();

 

public ActionResult Index()

 

{

 

return View(departments);

 

}

 

public ActionResult Details(int id)

 

{

 

return View(departments.Find(x => x.ID==id));

 

}

 

public ActionResult ListEmployees(Department d)

 

{

 

List<Employee> employees = GetEmployees(d);

 

return View(employees);

 

}

 

}

 

You create a strongly typed view that displays details for a Department instance. You want the view to also include a listing of department employees.

 

You need to write a code segment that will call the ListEmployees action method and output the results in place.

 

Which code segment should you use?

 

A.

<%= Html.Action(“ListEmployees”, Model) %>

B.

<%= Html.ActionLink(“ListEmployees”, “Department”, “DepartmentController”) %>

C.

<% Html.RenderPartial(“ListEmployees”, Model); %>

D.

<%= Html.DisplayForModel(“ListEmployees”) %>

 

Correct Answer: A

Explanation:

Html.Action(string, object) invokes a child action method and returns the result as an HTML string.

ChildActionExtensions.Action Method

(http://msdn.microsoft.com/en-

s/library/system.web.mvc.html.childactionextensions.action.aspx) Html.DisplayForModel() Method returns HTML markup for each property in the model. Html.DisplayForModel(string, object) Method returns HTML markup for each property in the model, using the specified template and additional view data.

RenderPartialExtensions.RenderPartial Method

(http://msdn.microsoft.com/en-

us/library/system.web.mvc.html.renderpartialextensions.renderpartial.aspx) The ActionLink method renders an element that links to an action method.

LinkExtensions.ActionLink Method

(http://msdn.microsoft.com/en-

us/library/system.web.mvc.html.linkextensions.actionlink.aspx)

 

 

QUESTION 110

You are developing an ASP.NET MVC 2 Web application.

 

A page makes an AJAX request and expects a list of company names in the following format.

 

[“Adventure Works”,”Contoso”]

 

You need to write an action method that returns the response in the correct format.

 

Which type should you return from the action method?

 

A.

AjaxHelper

B.

XDocument

C.

JsonResult

D.

DataContractJsonSerializer

 

Correct Answer: C

 

Instant Access to Download Testing Software & PDF File for Microsoft 70-515 Real Exam

Instant Access to Try Microsoft 70-515 Free Demo

This entry was posted in 70-515 Actual Tests and tagged , , , , , . Bookmark the permalink.