Which two actions should you perform?
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.)
Which two actions should you perform?
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.)
Which two actions should you perform?
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.)
Which configuration should you add to the web.config file?
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.
•Class name: Task
•Namespace: DevControls
•Assembly: TestServerControl.dll
•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?
You need to add a route to meet the following requirements
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.
• The details for a user must 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?
Which two actions should you perform?
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.)
Which code segment should you use?
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?
You need to ensure that the custom formatting is applied to LastScore values…
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?
You need to ensure that the correct page is returned
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
andIndex.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 }
07
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://<applicationname>/product, you discover that the correct page is not
returned. You need to ensure that the correct page is returned. What should you do?
Which code segment should you use?
You are creating an ASP.NET Web site. The site is configured to use Membership and Role
management providers. You need to check whether the currently logged-on user is a member of a
role named Administrators. Which code segment should you use?