You are on page 1of 35

Microsoft (70-562) TS: Microsoft .NET Framework 3.5 ASP.

NET Application Development (VB)


Questions and answers along with explanations

Question 1 You have created a Web application using ASP.NET 3.5. The application stores state using Session state. You are planning to deploy the application on a Web farm. The servers in the Web farm are described in the exhibit. All servers are configured with a Secure Sockets Layer (SSL) certificate. A session must be disconnected if it has been idle for more than 10 minutes. You need to configure Session state. What should you do?

A) Add the following element to Web.config: <sessionState mode="InProc" stateConnectionString="tcpip=192.168.10.20:443" timeout="10" /> B) Add the following element to Web.config: <sessionState mode="StateServer" stateConnectionString="tcpip=192.168.10.20:42424" timeout="10" /> C) Add the following element to Web.config: <sessionState mode="StateServer" stateConnectionString="tcpip=192.168.10.20:443" stateNetworkTimeout="10" /> D) Add the following element to Web.config: <sessionState mode="SqlServer" sqlConnectionString="data source=192.168.10.20;Integrated Security=SSPI" sqlConnectionTimeout="10" />

Answer B You should add the following element to Web.config: <sessionState mode="StateServer" stateConnectionString="tcpip=192.168.10.20:42424" timeout="10" /> One way to support Session state on a Web farm is to use the ASP.NET state service. To specify that Session state should be stored in the ASP.NET state service, you need to set the mode attribute to StateServer and specify a stateConnectionString that identifies the server running state service. State service always listens on port 42424. You set the timeout attribute to the number of minutes a session can be idle before it should be disconnected. You should not add the following element to Web.config: <sessionState mode="InProc" stateConnectionString="tcpip=192.168.10.20:443" timeout="10" /> When Session state is configured with the mode of InProc, servers on a farm cannot share session state. Also, you do not identify a stateConnectionString when the mode is set to InProc because each server stores session state locally. You should not add the following element to Web.config: <sessionState mode="SqlServer" sqlConnectionString="data source=192.168.10.20;Integrated Security=SSPI" sqlConnectionTimeout="10" /> You can use SQL Server to store session state on a Web farm. However, the sqlConnectionTimeout identifies the number of seconds to wait for a query to SQL Server, not the number of minutes to wait before disconnecting an idle session. You should not add the following element to Web.config: <sessionState mode="StateServer" stateConnectionString="tcpip=192.168.10.20:443" stateNetworkTimeout="10" /> StateServer always listens on port 42424, not port 443. Also, the stateNetworkTimeout is the number of seconds to wait for a network transmission between the Web server and the server running the state service, not the amount of time to wait before disconnecting an idle session.

Question 2 You create a custom control for a Microsoft ASP.NET 3.5 Web application. The control is implemented as follows: Public Class Circle Inherits Control Public Property Radius() As Double Get Dim radius As Object = ViewState("Radius") If radius Is Nothing Then radius = 0.0 End If Return CType(radius, Double) End Get Set (ByVal Value As Double) ViewState("Radius") = value End Set End Property End Class You need to extend this control so that its Radius property can be set from JavaScript. What should you do? A) Implement the IScriptControl interface. B) Add a method named GetRadius that returns the Radius property, and apply the ScriptMethod attribute to the method. C) Derive the class from ScriptControlDescriptor instead of Control. D) Apply the ScriptService attribute to the class.

Answer A You should implement the IScriptControl interface. This interface defines two methods named GetScriptDescriptors and GetScriptReferences. The GetScriptDescriptors method returns a collection of ScriptDescriptor instances that represent client components. The GetScriptReferences method returns a collection of ScriptReference instances that represent embedded script resources required by the control. You should not apply the ScriptService attribute to the class. This attribute marks a Web service as one that is accessible from ASP.NET Asynchronous JavaScript and XML (AJAX). This attribute allows the Web service to generate a JavaScript Object Notation (JSON) script that a JavaScript client application can use to call the Web service. You should not apply the ScriptMethod attribute to a method named GetRadius. This attribute allows you to control the response format of a Web method that is accessible from ASP.NET AJAX. You should not derive the class from ScriptControlDescriptor instead of Control. You should return instances of ScriptControlDescriptor from the GetScriptDescriptors method. ScriptControlDescriptor derives from ScriptDescriptor. ScriptControlDescriptor maps properties of a control to client-side properties.

Question 3 You are creating a Web application that calls a service that is defined as shown in the exhibit. The service is hosted on a Web server at www.stayandsleep.com. The service is named CalcStatsService.svc. You need to create the client code to call the service, passing the argument stored in a variable named values. What code should you use?

A) Dim addr As Uri = New Uri ("http://www.stayandsleep.com/CalcStatsService.svc") Dim binding As New WSHttpBinding() Dim fact As ChannelFactory = New ChannelFactory(binding, addr) Dim channel As ICalcStats= fact.Open() Dim result As Double result = channel.Average(values) B) Dim addr As EndpointAddress = New EndpointAddress("http://www.stayandsleep.com/CalcStatsService.svc") Dim binding As New WSHttpBinding() Dim fact As ChannelFactory(Of ICalcStats) = New ChannelFactory(Of ICalcStats) (binding, addr) Dim channel As ICalcStats= fact.CreateChannel() Dim result As Double result = channel.Average(values) C) Dim addr As EndpointAddress = New EndpointAddress("http://www.stayandsleep.com/CalcStatsService.svc") Dim fact As ChannelFactory= New ChannelFactory (addr) Dim channel As ICalcStats= fact.CreateChannel() Dim result As Double result = channel.Average(values) D) Dim addr As Uri = New Uri("http://www.stayandsleep.com/CalcStatsService.svc") Dim binding As New WSHttpBinding() Dim fact As ChannelFactory(Of ICalcStats) = New ChannelFactory(Of ICalcStats) (binding, addr) Dim channel As ICalcStats= fact.CreateChannel() Dim result As Double result = channel.Average(values)

Answer B You should use the following code: Dim addr As EndpointAddress = New EndpointAddress("http://www.stayandsleep.com/CalcStatsService.svc") Dim binding As New WSHttpBinding() Dim fact As ChannelFactory(Of ICalcStats) = New ChannelFactory(Of ICalcStats) (binding, addr) Dim channel As ICalcStats= fact.CreateChannel() Dim result As Double result = channel.Average(values) If you want to call a method on a Windows Communication Foundation (WCF) service programmatically, you must: 1. Create an endpoint that references the URL and service name of the service. 2. Create a binding. 3. Instantiate a channel factory using the contract type. 4. Create a communication channel by calling the CreateChannel method of the factory. 5. Call the method on the channel. You should not use the following code: Dim addr As EndpointAddress = New EndpointAddress("http://www.stayandsleep.com/CalcStatsService.svc") Dim fact As ChannelFactory= New ChannelFactory (addr) Dim channel As ICalcStats= fact.CreateChannel() Dim result As Double result = channel.Average(values) The ChannelFactory class is a generic class. You must identify the contract's type when you instantiate the class. Also, you must specify a binding or an endpoint when instantiating ChannelFactory. If a binding or endpoint has not been added to the Web.config file, you need to specify the binding and the address of the service. You should not use the following code: Dim addr As Uri = New Uri("http://www.stayandsleep.com/CalcStatsService.svc") Dim binding As New WSHttpBinding() Dim fact As ChannelFactory(Of ICalcStats) = New ChannelFactory(Of ICalcStats) (binding, addr) Dim channel As ICalcStats= fact.CreateChannel() Dim result As Double result = channel.Average(values) The address must be specified as an EndpointAddress, not as a Uri. You should not use the following code: Dim addr As Uri = New Uri ("http://www.stayandsleep.com/CalcStatsService.svc") Dim binding As New WSHttpBinding() Dim fact As ChannelFactory = New ChannelFactory(binding, addr) Dim channel As ICalcStats= fact.Open() Dim result As Double result = channel.Average(values) The address must be specified as an EndpointAddress, not as a Uri. Also, the ChannelFactory class is a generic class. You must identify the contract's type when you instantiate the class.

Question 4 You create a Web application by using Microsoft ASP.NET 3.5. You add a ScriptManager control to a page to enable partial rendering. The following code exists in the code-behind file of the page: Protected Sub Page_Error(ByVal sender As Object, ByVal e As EventArgs) Dim ex As Exception = Server.GetLastError() Trace.Warn("Exception", "An unhandled exception has occurred.", ex) End Sub You enable ASP.NET tracing for the page. When you visit the page for the first time, you can view the trace message in the page output if an unhandled exception occurs. However, you cannot view the trace message in the page output if an unhandled exception occurs during an asynchronous post back. You need to view the trace message when an unhandled exception occurs during an asynchronous post back. What should you do? A) Use the trace viewer tool (Trace.axd) to view the message. B) Set the ScriptMode property of the ScriptManager control to Debug. C) Add the following code to the end of the Page_Error event handler: Dim script As String = String.Format("Sys.Debug.trace('{0}')", Trace.ToString()) Page.ClientScript.RegisterStartupScript(Me.ClientID, script) D) Set the Debug attribute of the @Page directive to True.

Answer A You should use Trace.axd to view the message. When asynchronous post backs occur, only regions of a page are updated. The entire page is not reloaded. This means that the page output generated by the TraceContext class will not be updated during an asynchronous post back. However, the trace messages still get written to Trace.axd. You should not set the ScriptMode property of the ScriptManager control to Debug. This property determines whether the ScriptManager control should render release or debug versions of Asynchronous JavaScript and XML (AJAX) scripts. You should not call the RegisterStartupScript method of the ClientScriptManager class. After an asynchronous post back, the script would not be registered on the page because the entire page would not be reloaded. Also, the Sys.Debug.trace AJAX function does not implement ASP.NET tracing. It simply writes messages to a TextArea element that has an ID of TraceConsole. You should not set the Debug attribute of the @Page directive to True. This allows ASP.NET to compile the page with debug symbols. It has no effect on ASP.NET trace messages.

Question 5 You are creating a Web site using ASP.NET 3.5. You want the list of products on a Web page to update asynchronously when a product category or a product price range is chosen from the drop-down list. The product list should not be modified if a postback occurs for any other reason. What code should you use? A) <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional"> <ContentTemplate> <asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:DropDownList ID="ddlPriceRanges" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:GridView ID="grdProducts" runat="server"> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> B) <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always"> <ContentTemplate> <asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:DropDownList ID="ddlPriceRanges" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:GridView ID="grdProducts" runat="server"> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> C) <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" > <ContentTemplate> <asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:DropDownList ID="ddlPriceRanges" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:GridView ID="grdProducts" runat="server"> </asp:GridView> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlCategories" EventName="SelectedIndexChanged" /> <asp:AsyncPostBackTrigger ControlID="ddlPriceRange" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> D) <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="Always"> <ContentTemplate> <asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:DropDownList ID="ddlPriceRanges" runat="server" AutoPostBack="True">

</asp:DropDownList> <asp:GridView ID="grdProducts" runat="server"> </asp:GridView> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlCategories" EventName="SelectedIndexChanged" /> <asp:AsyncPostBackTrigger ControlID="ddlPriceRange" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel>

Answer A You should use the following code: <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional"> <ContentTemplate> <asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:DropDownList ID="ddlPriceRanges" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:GridView ID="grdProducts" runat="server"> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> An UpdatePanel allows you to group controls for asynchronous updates. When controls are asynchronously updated, only the controls within that panel are updated. The other elements on the page remain unchanged. You need to define which controls can trigger the panel to be updated. In this scenario, you need to update the panel when the SelectedIndexChanged event of either ddlCategories or ddlPriceRanges occurs. Because these are the only two child controls that initiate a postback, you can meet these requirements by setting the UpdateMode attribute to Conditional and the ChildrenAsTriggers attribute to True. You should not use the following code: <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="Always"> <ContentTemplate> <asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:DropDownList ID="ddlPriceRanges" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:GridView ID="grdProducts" runat="server"> </asp:GridView> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlCategories" EventName="SelectedIndexChanged" /> <asp:AsyncPostBackTrigger ControlID="ddlPriceRange" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> Or <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" > <ContentTemplate> <asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:DropDownList ID="ddlPriceRanges" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:GridView ID="grdProducts" runat="server"> </asp:GridView> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlCategories"

EventName="SelectedIndexChanged" /> <asp:AsyncPostBackTrigger ControlID="ddlPriceRange" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> You cannot set the UpdateMode to Always and the ChildrenAsTriggers attribute to false. Doing so causes an exception. The UpdateMode attribute is set to Always by default. The EnablePartialRendering attribute is set to true by default. You should not use the following code: <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always"> <ContentTemplate> <asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:DropDownList ID="ddlPriceRanges" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:GridView ID="grdProducts" runat="server"> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> If you set UpdateMode to Always, the UpdatePanel will be refreshed if a postback occurs for any reason.

Question 6 You are creating a Web application that will be accessed by mobile devices. You want to display a different graphic in an Image control depending on the screen resolution, preferred image type, and whether the mobile device supports color. You plan to use the device-specific choice element and custom filters. A portion of the Choice element is shown in the exhibit. You need to create the colorHighResJPG filter method. What code should you use?

A) Public Function colorHighResJPG(ByVal capabilities As System.Web.Mobile.MobileCapabilities, ByVal arg As String) As Boolean 'Code to check capabilities End Function B) Public Sub colorHighResJPG(ByVal capabilities As System.Web.Mobile.Device, ByRef applyFilter As Boolean) 'Code to check capabilities End Function C) Public Function colorHighResJPG(ByVal capabilities As System.Web.Mobile.MobileCapabilities) As String 'Code to check capabilities End Function D) Public Function colorHighResJPG(ByVal capabilities As System.Web.Mobile.BrowserCapabilities) As Boolean 'Code to check capabilities End Function

Answer A You should use the following code: Public Function colorHighResJPG(ByVal capabilities As System.Web.Mobile.MobileCapabilities, ByVal arg As String) As Boolean 'Code to check capabilities End Function The filter method must accept two arguments: a MobileCapabilities object and a String. It must return a Boolean value. If the filter method returns True, that choice will be displayed. You should not use the following code: Public Function colorHighResJPG(ByVal capabilities As System.Web.Mobile.BrowserCapabilities) As Boolean 'Code to check capabilities End Function The method must accept a MobileCapabilities object as its first argument and a String as its second object. You should not use the following code: Public Function colorHighResJPG(ByVal capabilities As System.Web.Mobile.MobileCapabilities) As String 'Code to check capabilities End Function The method must accept a String as its second argument and return a Boolean value. You should not use the following code: Public Sub colorHighResJPG(ByVal capabilities As System.Web.Mobile.Device, ByRef applyFilter As Boolean) 'Code to check capabilities End Function You must create a function that returns a Boolean value, not a Sub that has a Boolean argument passed by reference. Also, the function must accept a MobileCapabilities object and a String as arguments.

Question 7 You are creating a Web application using ASP.NET 3.5. You want requests to videos.aspx to asynchronously load playvideo.aspx and display the video that is identified in the query string of videos.aspx. You need to program the Page_Load event of videos.aspx to request playvideo.aspx without requiring another request from the browser. What code should you use? A) Server.TransferRequest("playvideo.aspx", True) B) Response.Redirect("playvideo.aspx", True) C) Server.MapPath("playvideo.aspx", True) D) Server.Transfer("playvideo.aspx", True)

Answer D You should use the following code: Server.TransferRequest("playvideo.aspx", True) The TransferRequest method of the Server object causes the page specified to be loaded asynchronously. Passing True as the second argument causes QueryString arguments and the Forms collection to be preserved. You should not use the following code: Server.Transfer("playvideo.aspx", True) The Transfer method causes the page specified to be loaded synchronously. It terminates loading the current page and initiates the execution of the newly requested URL. Passing True as the second argument causes QueryString arguments and the Forms collection to be preserved. You should not use the following code: Response.Redirect("playvideo.aspx", True) The Redirect method of the Response object causes the browser to request the specified page. The second parameter determines whether the current page should terminate execution. You should not use the following code: Server.MapPath("playvideo.aspx", True) The MapPath method is used to map the virtual path for saving or reading a file to the physical location of the virtual directory on the Web server. Also, there is no version of the MapPath method that has two parameters.

Question 8 You are using Visual Studio 2008 to modify a Web application that was created using Visual Studio 2005. You plan to use classes from the System.ServiceModel.Web namespace. You display the Add Reference dialog and notice that the System.ServiceModel.Web component is grayed out. You need to reference the component in your application. What should you do? A) Use mscorcfg.msc to add System.ServiceModel.Web.dll to the global assembly cache (GAC). B) Display the Add Web Reference dialog box to add a reference. C) Display project properties and change the target framework to 3.5. D) Use the Browse tab to locate System.ServiceModel.Web.dll.

Answer C You should display project properties and change the target framework to 3.5. The System.ServiceModel.Web component is a .NET Framework 3.5 component. Therefore, it is only available in projects that have a target framework of 3.5 (or higher). You should not display the Add Web Reference dialog box to add a reference. The Add Web Reference dialog box is used to add a reference to a Web service, not a .NET Framework component. You should not use the Browse tab to locate System.ServiceModel.Web.dll. The System.ServiceModel.Web component is a .NET Framework component. Therefore, it should be added through the .NET tab. You should not use mscorcfg.msc to add System.ServiceModel.Web.dll to the GAC. The component is already installed in the GAC. It is grayed out because the project is configured with an earlier target framework that does not include the System.ServiceModel.Web component.

Question 9 You create a Web application by using Microsoft ASP.NET 3.5. The following markup exists on a page: <asp:Wizard ID="_wizard" runat="server" ActiveStepIndex="0" OnNextButtonClick="OnNext"> <WizardSteps> <asp:WizardStep ID="_welcomeStep" runat="server" Title="Welcome"> This wizard helps you create a survey. </asp:WizardStep> <asp:WizardStep ID="_chooseQuestionsStep" runat="server" Title="Choose Your Questions"> <asp:GridView ID="_questionsGridView" runat="server"/> <asp:CheckBox ID="_checkBox" Checked="True" runat=server Text="Create Questions"/> </asp:WizardStep> <asp:WizardStep ID="_createQuestionsStep" runat="server" Title="Create Your Questions"> <cc:QuestionEditor ID="_question" runat="server"/><br> <asp:Button ID="_addQuestion" runat="server"/> </asp:WizardStep> <asp:WizardStep ID="_finishStep" runat="server" Title="Done"> </asp:WizardStep> </WizardSteps> </asp:Wizard> You need to implement the OnNext event handler so that the third step (Create Your Questions) is skipped if the user clears the Create Questions check box option. Which code segment should you use? A) Protected Sub OnNext(ByVal sender As Object, _

ByVal e As WizardNavigationEventArgs) If e.CurrentStepIndex = _wizard.WizardSteps.IndexOf(_chooseQuestionsStep) AndAlso Not _checkBox.Checked Then _wizard.MoveTo(_finishStep) Else e.Cancel = True End If End Sub ByVal e As WizardNavigationEventArgs) If e.CurrentStepIndex = _wizard.WizardSteps.IndexOf(_chooseQuestionsStep) AndAlso !_checkBox.Checked Then _wizard.MoveTo(_finishStep) e.Cancel = True End If End Sub ByVal e As WizardNavigationEventArgs) If e.CurrentStepIndex = _wizard.WizardSteps.IndexOf(_chooseQuestionsStep) AndAlso Not _checkBox.Checked Then _wizard.MoveTo(_finishStep) End If End Sub ByVal e As WizardNavigationEventArgs) If e.CurrentStepIndex = _wizard.WizardSteps.IndexOf(_chooseQuestionsStep) AndAlso _checkBox.Checked Then e.Cancel = False End If End Sub

B) Protected Sub OnNext(ByVal sender As Object, _

C) Protected Sub OnNext(ByVal sender As Object, _

D) Protected Sub OnNext(ByVal sender As Object, _

Answer C You should implement the event handler to call the MoveTo method of the Wizard class if the current step is the Choose Your Questions step and the Checked property of the _checkBox control is False. The NextButtonClick event is raised whenever a user clicks the Next button of the Wizard control. This event defines a WizardNavigationEventArgs parameter that specifies the current step and the next defined step, as indicated by the CurrentStepIndex and NextStepIndex properties of the WizardNavigationEventArgs class. This class also defines a Cancel property that allows you to cancel automatic or manual navigation. You can perform manual navigation by calling the MoveTo method of the Wizard class. The MoveTo method changes the ActiveStepIndex property of the Wizard control. If the ActiveStepIndex property is not changed, the Wizard automatically navigates to the next defined step unless WizardNavigationEventArgs.Cancel is set to True. You should not set the Cancel property of the WizardNavigationEventArgs class to True after calling the MoveTo method of the Wizard class. This would cancel manual navigation. You must call the MoveTo method if the Checked property of the _checkBox control is False. Otherwise, the Wizard control will automatically navigate to the next defined step. You should not set the Cancel property of the WizardNavigationEventArgs class to True if the current step is not the Choose Your Questions step. Because the event handler handles the NextButtonClick event for all steps, this would prevent navigation from all other steps.

Question 10

You create a Web site by using Microsoft ASP.NET 3.5. The following code exists in the App_Code folder: Public Class ObjectParameter Inherits Parameter Private _objectTypeName As String Private _propertyName As String Public Property ObjectTypeName() As String Get Return _objectTypeName End Get Set _objectTypeName = value End Set End Property Public Property PropertyName() As String Get Return _propertyName End Get Set _propertyName = value End Set End Property Protected Overrides Function Evaluate(ByVal context As HttpContext, _ ByVal control As Control) As Object If String.IsNullOrEmpty(ObjectTypeName) Then Throw New InvalidOperationException("ObjectTypeName is not set") End If If String.IsNullOrEmpty(PropertyName) Then Throw New InvalidOperationException("PropertyName is not set") End If Dim type As Type = System.Type.GetType(ObjectTypeName) Dim flags As BindingFlags = BindingFlags.Public Or BindingFlags.Static Or _ BindingFlags.GetProperty Dim value As Object = type.InvokeMember(flags,Nothing,Nothing,Nothing) Return value End Function End Class Public Class Security Public Shared ReadOnly Property UserID() As String Get Return Session("UserID") End Get End Property End Class The following stored procedure exists in a Microsoft SQL Server 2008 database: CREATE PROCEDURE GetStoresByUser @UserID INT AS SELECT StoreID, StoreName FROM Store where UserID=@UserID

The connection string to the database is stored in the connectionStrings section and has the name SupplyChain. You need to use a data source control to call this stored procedure and pass the Security.UserID value to it as a parameter. Which declaration should you use? A) <SqlDataSource ID="_dataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SupplyChain%>" SelectCommand="GetStoresByUser" SelectCommandType="Text"> <SelectParameters> <cust:ObjectParameter Name="Security.UserID"/> </SqlDataSource> B) <ObjectDataSource ID="_dataSource" runat="server" DataObjectTypeName="StoredProcedure" TypeName="ConnectionStrings.SupplyChain" SelectMethod="GetStoresByUser"> <SelectParameters> <cust:ObjectParameter Name="Security.UserID"/> </SelectParameters> </ObjectDataSource> C) <ObjectDataSource ID="_dataSource" runat="server" DataObjectTypeName="<%$ ConnectionStrings:SupplyChain%>" TypeName="StoredProcedure" SelectMethod="GetStoresByUser"> <SelectParameters> <cust:ObjectParameter Name="UserID" ObjectTypeName="Security" PropertyName="UserID"/> </SelectParameters> </ObjectDataSource> D) <SqlDataSource ID="_dataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SupplyChain%>" SelectCommand="GetStoresByUser" SelectCommandType="StoredProcedure"> <SelectParameters> <cust:ObjectParameter Name="UserID" ObjectTypeName="Security" PropertyName="UserID"/> </SelectParameters> </SqlDataSource>

Answer D You should use the following declaration: <SqlDataSource ID="_dataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SupplyChain%>" SelectCommand="GetStoresByUser" SelectCommandType="StoredProcedure"> <SelectParameters> <cust:ObjectParameter Name="UserID" ObjectTypeName="Security" PropertyName="UserID"/> </SelectParameters> </SqlDataSource> This declares a SqlDataSource control that connects to the database. The SelectCommand property specifies the SQL command or stored procedure to execute. In this scenario, the SelectCommandType property is set to StoredProcedure, so the value specified in the SelectCommand property is a stored procedure. The SelectParameters property defines the parameters to pass to the stored procedure. In this scenario, the stored procedure accepts a single String parameter. To pass the value of Security.UserID as a parameter, you should use the ObjectParameter class and set its properties appropriately. The ObjectTypeName property specifies the name of the class, and the PropertyName property specifies the property of that class. In this scenario, the name of the class is Security, and the name of the property of that class is UserID. You should not use the ObjectDataSource control. This control allows you to bind to business or data objects. The TypeName property of this control should specify the common language runtime (CLR) type of the object to query. The SelectMethod property should specify a method of that type that is used to query data. The DataObjectTypeName property should specify a CLR type that can be used for a parameter in an insert, update, or delete operation. You should not use the following declaration: <SqlDataSource ID="_dataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SupplyChain%>" SelectCommand="GetStoresByUser" SelectCommandType="Text"> <SelectParameters> <cust:ObjectParameter Name="Security.UserID"/> </SqlDataSource> This code sets the SelectCommandType property to Text, which indicates that the SelectCommand property value is a SQL statement. Also, the ObjectParameter property does not set the ObjectTypeName and PropertyName properties, but instead sets the Name property to Security.UserID. You must set the Name property to the name of a parameter expected by the stored procedure. Also, in this scenario, if you do not set the ObjectTypeName and PropertyName properties, the ObjectParameter class throws an exception.

Question 11 You create a Web application by using Microsoft ASP.NET 3.5. The following code exists in the application: Public Class Account Private _balance As Double Public Property Balance() As Double Get Return _balance End Get Set _balance = value End Set End Property Public Sub Deposit(ByVal amount As Double) Balance = Balance + amount End Sub Public Sub Withdraw(ByVal amount As Double) System.Diagnostics.Trace.WriteLineIf(amount > Balance, "Potential Overdraft.") If amount <= Balance Then Balance = Balance - amount End If End Sub End Class This code writes a trace message if there is potential for an overdraft. You need to configure the Web.config file to write the trace message to the trace viewer tool (Trace.axd). Which configurations should you use? (Each correct answer presents part of the solution. Choose two.) A) <trace enabled="true"/> B) <system.diagnostics> <trace> <listeners> <add name="WebPageTraceListener" type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> </listeners> </trace> </system.diagnostics> C) <system.diagnostics> <switches> <add name="PageOutput" value="Trace.axd"/> </switches> </system.diagnostics> D) <trace enabled="false" writeToDiagnosticsTrace="true"/> E) <trace enabled="false" writeToDiagnosticsTrace="true" pageOutput="false"/>

Answer A and B You should use the following configuration: <system.diagnostics> <trace> <listeners> <add name="WebPageTraceListener" type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> </listeners> </trace> </system.diagnostics> This adds a new trace listener to the Listeners collection of the System.Diagnostics.Trace class. The WebPageTraceListener class is implemented to write diagnostic trace messages to the ASP.NET tracing subsystem. Whenever you write a trace message by using the System.Diagnostics.Trace class, that message is also written to the ASP.NET tracing subsystem. You can view messages written to the ASP.NET tracing subsystem by accessing Trace.axd in the current Web application. You should also use the following configuration: <trace enabled="true"/> This configuration enables ASP.NET tracing. If you do not enable ASP.NET tracing, nothing will be written to the ASP.NET tracing subsystem. Note that you must add this configuration in the <system.web> section. You should not use the following configuration: <trace enabled="false" writeToDiagnosticsTrace="true"/> This configuration disables ASP.NET tracing. The writeToDiagnosticsTrace attribute specifies whether ASP.NET trace messages should be written to listeners defined for diagnostic tracing. However, in this scenario, you need to write diagnostic trace messages to the ASP.NET tracing subsystem. You should not use the following configuration: <trace enabled="false" writeToDiagnosticsTrace="true" pageOutput="false"/> This configuration disables ASP.NET tracing. The writeToDiagnosticsTrace attribute specifies whether ASP.NET trace messages should be written to listeners defined for diagnostic tracing. However, in this scenario, you need to write diagnostic trace messages to the ASP.NET tracing subsystem. The pageOutput attribute specifies whether ASP.NET trace messages can be viewed by requesting pages in addition to Trace.axd. You should not use the following configuration: <system.diagnostics> <switches> <add name="PageOutput" value="Trace.axd"/> </switches> </system.diagnostics> This configuration defines a trace switch named PageOutput that is set to the value Trace.axd. Trace switches allow you to write conditional diagnostic trace messages in an application based on the value of the switch.

Question 12 You are creating a Web site using ASP.NET and AJAX. The site uses a control that relies on an embedded script stored in a file named ProductScripts.js. The control contains resources translated to various languages. The control's assembly is named ProductDisplay. You need to register the script. Your solution must ensure that the control displays resources in the appropriate language. What code should you use? A) <asp:ScriptManager ID="ScriptManager1" EnableScriptGlobalization="true" runat="server"> <Scripts> <asp:ScriptReference Assembly="ProductDisplay" Name=" ProductScripts.js" /> </Scripts> </asp:ScriptManager> B) <asp:ClientScriptManager ID="ClientScriptManager1" EnableScriptLocalization="true" runat="server"> <Scripts> <asp:ScriptReference Assembly="ProductDisplay" Name="ProductScripts.js" /> </Scripts> </asp:ScriptManager> C) <asp:ClientScriptManager ID="ClientScriptManager1" EnableScriptGlobalization="true" runat="server"> <Scripts> <asp:ScriptReference Assembly="ProductDisplay" Name="ProductDisplay.ProductScripts.js" /> </Scripts> </asp:ScriptManager> D) <asp:ScriptManager ID="ScriptManager1" EnableScriptLocalization="true" runat="server"> <Scripts> <asp:ScriptReference Assembly="ProductDisplay" Name="ProductDisplay.ProductScripts.js" /> </Scripts> </asp:ScriptManager>

Answer D You should use the following code: <asp:ScriptManager ID="ScriptManager1" EnableScriptLocalization="true" runat="server"> <Scripts> <asp:ScriptReference Assembly="ProductDisplay" Name="ProductDisplay.ProductScripts.js" /> </Scripts> </asp:ScriptManager> The ScriptManager control can be used to register scripts that are stored in external files or embedded in an assembly. To load a script that is embedded in an assembly, you need to identify the assembly and the name of the script in a ScriptReference control inside the <Scripts> block. To cause the control to use the localized resource strings, you need to set EnableScriptLocalization to True. You should not use the code: <asp:ScriptManager ID="ScriptManager1" EnableScriptGlobalization="true" runat="server"> <Scripts> <asp:ScriptReference Assembly="ProductDisplay" Name=" ProductScripts.js" /> </Scripts> </asp:ScriptManager> The EnableScriptGlobalization attribute affects whether the control should respect locale settings when displaying currency and date information. It does not affect language resource usage. You should not use the code: <asp:ClientScriptManager ID="ClientScriptManager1" EnableScriptLocalization="true" runat="server"> <Scripts> <asp:ScriptReference Assembly="ProductDisplay" Name="ProductScripts.js" /> </Scripts> </asp:ScriptManager> Or <asp:ClientScriptManager ID="ClientScriptManager1" EnableScriptGlobalization="true" runat="server"> <Scripts> <asp:ScriptReference Assembly="ProductDisplay" Name="ProductDisplay.ProductScripts.js" /> </Scripts> </asp:ScriptManager> The ClientScriptManager class is not an ASP.NET control and cannot be used declaratively. It is a class that is used to programmatically add a script at runtime.

Question 13 You create a mobile Web application by using Microsoft ASP.NET 3.5. The following method exists in the code-behind file for a page: Public Function IsGpsSupported(ByVal capabilities As MobileCapabilities, _ ByVal optionalArgument As String) As Boolean Return Request.Headers("GPS") = Boolean.TrueString End Function This method determines whether the browser's device supports global positioning system (GPS). You must render a mobile Panel control that meets the following requirements: * If the device supports GPS, the Panel control should render a custom control named Map. * Otherwise, the Panel control should display the following text: GPS is not supported on this device. You need to declare the mobile Panel control. What should you do? A) Add the following markup to the page: <mobile:Panel ID="_panel" runat="server"> <mobile:DeviceSpecific ID="_deviceSpecific" runat="server"> <Choice Filter="IsGpsSupported"> <ContentTemplate> <cc1:Map ID="_map" runat="server"/> </ContentTemplate> </Choice> <Choice> <ContentTemplate> GPS is not supported on this device. </ContentTemplate> </Choice> </mobile:DeviceSpecific> </mobile:Panel> B) Add the following configuration to the Web.config file: <deviceFilters> <filter name="IsGpsSupported" compare="GPS"/> </deviceFilters> Add the following markup to the page: <mobile:Panel ID="_panel" runat="server"> <mobile:DeviceSpecific ID="_deviceSpecific" runat="server"> <Choice Filter="IsGpsSupported:True"> <ContentTemplate> <cc1:Map ID="_map" runat="server"/> </ContentTemplate> </Choice> <Choice> <ContentTemplate> GPS is not supported on this device. </ContentTemplate> </Choice> </mobile:DeviceSpecific> </mobile:Panel> C) Add the following configuration to the Web.config file:

<deviceFilters> <filter name="IsGpsSupported" argument="GPS"/> </deviceFilters> Add the following markup to the page: <mobile:Panel ID="_panel" runat="server"> <mobile:DeviceSpecific ID="_deviceSpecific" runat="server"> <Choice Filter="Headers"> <ContentTemplate> <cc1:Map ID="_map" runat="server"/> </ContentTemplate> </Choice> <Choice> <ContentTemplate> GPS is not supported on this device. </ContentTemplate> </Choice> </mobile:DeviceSpecific> </mobile:Panel> D) Add the following markup to the page: <mobile:Panel ID="_panel" runat="server"> <mobile:DeviceSpecific ID="_deviceSpecific" runat="server"> <Choice Filter="GPS"> <ContentTemplate> <cc1:Map ID="_map" runat="server"/> </ContentTemplate> </Choice> <Choice> <ContentTemplate> GPS is not supported on this device. </ContentTemplate> </Choice> </mobile:DeviceSpecific> </mobile:Panel>

Answer A You should add a DeviceSpecifc control to the Panel control. The DeviceSpecific control allows you to render different content for different devices. The DeviceSpecific control supports one or more Choice elements that define the criteria for rendering to a specific device. The Filter attribute of the Choice element specifies the criteria that the device must meet for the content of that Choice element to be rendered. The ASP.NET mobile framework first attempts to locate a method in the containing page or user control that matches the value of the Filter attribute. That method must match a pre-defined signature. The first parameter must be a MobileCapabilities instance that represents the capabilities of the browser. The second parameter must be a String instance that represents an optional argument. If the mobile framework cannot find such a method, it evaluates the deviceFilters section of the Web.config file. If it finds a filter element whose name attribute matches the Filter attribute of the Choice element, the mobile framework uses that filter to determine whether the criteria are met. In this scenario, a method named IsGpsSupported that matches the required signature is defined in the code-behind file for the page. Therefore, that method will be used to determine whether the criteria are met. If the filter is not present, that choice is selected by default. You should not specify a value for the Filter attribute of the Choice element that does not match either the name of a filter in the Web.config file or the name of a method in the current page. Otherwise, the mobile framework would not be able to evaluate the filter to determine if the browser's device supports GPS.

Question 14 You are creating a Web site using ASP.NET 3.5. When the user clicks the btnSubmit button on article.aspx, the application needs to display review.aspx and show the text that the user typed in the TextBox control named txtArticle in a Label control named lblReviewArticle. You need to write the code necessary to implement this functionality. What should you do? (Each correct answer presents part of the solution. Choose two.) A) Add the following code to the btnSubmit_Click event procedure: Server.Transfer("review.aspx") B) Add the following code to the btnSubmit_Click event procedure: Response.Redirect("review.aspx") C) Add the following code to the Page_Load event of review.aspx: Dim txt As TextBox txt = Application.review.txtArticle If Not IsNothing(txt) Then lblReviewArticle.Text = Server.HtmlEncode(txt) Else lblReviewArticle.Text = "No article submitted" End If D) Add the following code to the Page_Load event of review.aspx: Dim txt As TextBox txt = CType(Context.PreviousHandler.FindControl ("txtArticle"), TextBox) If Not IsNothing(txt) Then lblReviewArticle.Text = Server.HtmlEncode(txt.Text) Else lblReviewArticle.Text = "No article submitted" End If E) Add the following code to the Page_Load event of review.aspx: Dim txt As TextBox txt = CType(Page.PreviousPage.FindControl ("txtArticle"), TextBox) If Not IsNothing(txt) Then lblReviewArticle.Text = Server.HtmlEncode(txt.Text) Else lblReviewArticle.Text = "No article submitted" End If

Answers A and D You should add the following code to the btnSubmit_Click event procedure: Server.Transfer("review.aspx") You need to perform a cross-page post using Server.Transfer if you want to be able to access data from the previous page. You should also add the following code to the Page_Load event of review.aspx: Dim txt As TextBox txt = CType(Page.PreviousPage.FindControl ("txtArticle"), TextBox) If Not IsNothing(txt) Then lblReviewArticle.Text = Server.HtmlEncode(txt.Text) Else lblReviewArticle.Text = "No article submitted" End If If control was transferred to the page using Server.Transfer, you can obtain a reference to the page that performed the transfer using the PreviousPage property of the Page object. Then you can use the FindControl method to obtain a reference to the control. You should not use the following code: Add the following code to the btnSubmit_Click event procedure: Response.Redirect("review.aspx") If you use Response.Redirect, you will not be able to access the previous page. The PreviousPage property of the Page object will be set to Nothing. You should not add the following code to the Page_Load event of review.aspx: Dim txt As TextBox txt = CType(Context.PreviousHandler.FindControl ("txtArticle"), TextBox) If Not IsNothing(txt) Then lblReviewArticle.Text = Server.HtmlEncode(txt.Text) Else lblReviewArticle.Text = "No article submitted" End If The PreviousHandler property of the Context object returns a reference to the handler that last executed. It does not return a reference to the previous page. The HttpHandler object does not have a FindControl method. You should not add the following code to the Page_Load event of review.aspx: Dim txt As TextBox txt = Application.review.txtArticle If Not IsNothing(txt) Then lblReviewArticle.Text = Server.HtmlEncode(txt) Else lblReviewArticle.Text = "No article submitted" End If You cannot access a page through the Application object. The Application object is used to store application state, which is accessible from any session.

Question 15 You create a Web site by using Microsoft ASP.NET 3.5. The following code exists in the App_Code folder: Namespace BcdTrain.Providers Public class SessionSiteMapProvider Inherits SiteMapProvider ' Members omitted for brevity End Class End Namespace You need to modify the Web.config file to ensure that SiteMapDataSource controls use the SessionSiteMapProvider class by default. Which configuration should you use? A) <siteMap defaultProvider="SessionSiteMapProvider"> <providers> <add name="SessionSiteMapProvider" type="BcdTrain.Providers.SessionSiteMapProvider, App_Code"> </providers> </siteMap> B) <siteMap defaultProvider="BcdTrain.Providers.SessionSiteMapProvider, App_Code"> </siteMap> C) <siteMap defaultProvider="SessionSiteMapProvider"> <providers> <add name="BcdTrain.Providers.SessionSiteMapProvider" type="SiteMapProvider"> </providers> </siteMap> D) <siteMap defaultProvider="BcdTrain.Providers.SessionSiteMapProvider"> </siteMap>

Answer A You should use the following configuration: <siteMap defaultProvider="SessionSiteMapProvider"> <providers> <add name="SessionSiteMapProvider" type="BcdTrain.Providers.SessionSiteMapProvider, App_Code"> </providers> </siteMap> This configuration adds a site map provider named SessionSiteMapProvider that maps to the SessionSiteMapProvider class in the BcdTrain.Providers namespace. The name attribute specifies a user-friendly name of the provider. The type attribute specifies the fully-qualified type name of the provider in the form [Namespace].[Class], [Assembly]. App_Code indicates that the assembly is one that is generated for code in the App_Code folder. This configuration also sets the defaultProvider attribute to SessionSiteMapProvider, which is the name of the provider that is added. SiteMapDataSource controls that do not specify a value for the SiteMapProvider property will automatically use the default provider. You should not use the following configuration: <siteMap defaultProvider="SessionSiteMapProvider"> <providers> <add name="BcdTrain.Providers.SessionSiteMapProvider" type="SiteMapProvider"> </providers> </siteMap> The defaultProvider attribute must match the name of a defined site map provider. Also, the type attribute must specify the fully-qualified type name of a site map provider. You should not use the following configuration: <siteMap defaultProvider="BcdTrain.Providers.SessionSiteMapProvider"> </siteMap> The defaultProvider attribute must match the name of a defined site map provider. In this configuration, no additional site map providers are defined. You should not use the following configuration: <siteMap defaultProvider="BcdTrain.Providers.SessionSiteMapProvider, App_Code"> </siteMap> The defaultProvider attribute must match the name of a defined site map provider. In this configuration, no additional site map providers are defined.

You might also like