Developer

Beyond the basics: Test your ASP.NET knowledge

If you've mastered the basics of ASP.NET and want to assess your skills beyond the standard user interface, try your hand at our ASP.NET quiz. Tackle these five questions and see where you stand.


So you’ve learned how to drag and drop controls from the VS.NET toolbox onto a Web form. You can bind a DataGrid to an ADO.NET data source object such as a DataSet, then hit [F5] and watch in astonishment as the grid actually renders all of your data in a browser. But how deep is your knowledge of ASP.NET beyond the typical user interface and data access coding?

UI and data access code is by no means trivial. These are the areas where we all start our explorations into ASP.NET and where we progress beyond the beginner level the fastest. But when the time comes to prepare a Web application for deployment, many other concerns must be taken into account. Here are just a few:
  • ·        Who should have access to the application?
  • ·        Should the same set of users have the same level of access to every page contained within a particular application?
  • ·        How do you access and reuse code that is useful across multiple applications?
  • ·        What kind of instrumentation can you build into your application to monitor it while it runs in a production environment?

We created a short quiz to help you gauge your knowledge of these important aspects of robust ASP.NET development and deployment. Only one of the five questions concerns something as mundane as Web controls. The rest concentrate on user and code security, as well as configuration files and diagnostics. Do you know enough to adequately prepare your ASP.NET Web apps for the real-world production environment? Test yourself and find out!

Question 1
Given the following fragment of an ASPX file:
<form runat=”server” method=”post” id=”form1”>
<asp:TextBox ID=”txtName” Text=”Builder.Com” EnableViewState=”false”/>
<br>
<asp:TextBox ID=”txtName2” Text=”” EnableViewState=”false”/>
</form>


and the following fragments of the ASPX file’s codebehind file (in C#):
protected TextBox txtName = new TextBox();
protected TextBox txtName2 = new TextBox();

// Assume this is properly wired as the Load event handler.
private void Page_Load(object source, EventArgs args)
{
       txtName2.Text = txtName.Text;
}


which of the following is true?

Possible answers
a) ASP.NET would generate an exception when it tried to run this.
b) “Builder.Com” would appear in txtName, but an empty string would appear in txtName2.
c) “Builder.Com” would appear in both txtName and txtName2.
d) Neither txtName nor txtName2 would render as HTML input controls on the loaded page.
e) “Builder.Com” would appear in txtName, but txtName2 wouldn’t render at all—i.e., no HTML control with an ID attribute of “txtName2” would be present on the loaded page.

Question 2
Your Web application, which we’ll simply call root, contains a subfolder called sub that is truly just a subfolder, not an IIS application or FrontPage “subweb” beneath root. The sub subfolder contains some sensitive pages that only the users ourdomain\mike and ourdomain\molly should have access to. You want to allow everyone, even outsiders, to see pages at the root-level of the root app. Which of the following will accomplish this? Select two and assume that everyone is using Internet Explorer 5.5 or higher and that IIS is configured to allow integrated security.

Possible answers
a) In the root folder, in the settings file named root. config, include the following lines:
<authentication mode=”Windows”>
<folder path=”/”>
<allow users=”?”/>
</folder>
</authentication>


b) In the root folder, in the settings file named Wweb.config, include the lines from answer a).

c) In the root folder, in the settings file named Web.config, include the following lines:
<authentication mode=”Windows”/>
<authorization><allow users=”*”/></authorization>


d) In the sub folder, in the settings file named Web.config, include the following lines:
<authentication mode=”Windows”/>
<authorization>
<allow users=”ourdomain\mike,ourdomain\molly”/>
<deny users=”*”/>
</authorization>


e) In the sub folder, in the settings file named Web.config, include the following lines:
<authorization>
<allow users=”ourdomain\mike,ourdomain\molly”/>
<deny users=”*”/>
</authorization>


f) In the sub folder, in the settings file named Web.config, include the following lines:
<authentication mode=”Windows” inheritFromParent=”false”>
<folder path=”/sub”>
<deny users=”*”/>
<allow users=”ourdomain\mike,ourdomain\molly”/>
</folder>
</authentication>


Question 3
Your Web server contains an ASP.NET app we’ll call /app1. It uses a cool library DLL that you created while you were developing it. Now you’re making a second, separate application (/app2), and you want to use that same cool DLL, but without putting it into the Global Assembly Cache. Which of the following will accomplish this?

Possible answers
a) Set a reference to the desired DLL (either in VS.NET or while compiling at the command line) and add the [AllowExternalRef(true)] attribute to your Page class in the new project.
b) Set a reference to the desired DLL (either in VS.NET or while compiling at the command line) and add the [SecureCoApp(name=”app1”)] attribute to your Page class in the new project.
c) Just include a reference to the desired DLL, either in VS.NET or while compiling at the command line. If using VS.NET, make sure that the reference’s CopyLocal property is set to AsNeeded.
d) None of the above.

Question 4
The config file for your ASP.NET Web app includes the following:
<system.diagnostics>
<switches>
<add name=”diagSwitch” value=”1”/>
</switches>
</system.diagnostics>


Which of the following lines, if included in a code file for the same project, will make the previous <system.diagnostics> lines useful?

Possible answers
a) System.Runtime.Switching.BoolSwitch diagSwitch = new System.Runtime.Switching.BoolSwitch(“mySwitch”,”Does some switching.”);
b) System.Switching.BooleanSwitch diagSwitch = new System.Switching.BooleanSwitch(“mySwitch”,”Does some switching.”);
c) System.Diagnostics.BooleanSwitch diagSwitch = new System.Diagnostics.BooleanSwitch(“mySwitch”,”Does some switching.”);
d) System.Diagnostics.BooleanSwitch mySwitch = new System.Diagnostics.BooleanSwitch(“diagSwitch”,”Does some switching.”);

Question 5
While testing your Web app in a nonproduction environment, you want the browser output of all of the app’s ASPX pages to include helpful messages concerning when certain page events such as Load, Render, and PreRender occur and how long they take to execute. You’d also like to see the contents of all server variables. What is the simplest way to achieve this without having to code such messages on every page?

Possible answers
a) Create your own class that inherits from System.Web.UI.Page and put in code to use Response.Write to send helpful messages and server variable contents to the browser in the Load, Render, and PreRender events. Then, temporarily change all of your page classes to inherit from this class, instead of directly from System.Web.UI.Page. You can just switch them back when ready to deploy.
b) Put Trace=True in the @Page directive at the top of all of your ASPX files.
c) In the Web app’s config file, include <trace value=”true” allPages=”true”/> in the <system.web> element.
d) In the Web app’s config file, include <trace level=”page”> in the <system.web> element, and then, within the <trace> element, put <page name=”...”/> elements to indicate the list of pages that should include these trace messages.
e) In the Web app’s config file, include <trace enabled=”true” pageOutput=”true”/> in the <system.web> element.
f) Write the subclass as explained in answer a), but also enable the page-level tracing on each page using the technique in answer b).

If you want to take a peek at the answers, you can view them in this sidebar. A future article will explain the answers in detail.

 

Editor's Picks