Important of Net Framework
1. What is the main difference
between an ASP.NET Web application and a traditional Windows application?
ASP.NET Web applications run under common language
runtime using managed code where as Unmanaged Windows application runs under
Windows using unmanaged code.
2. What are the two main parts of
the .NET Framework?
The two main parts of the .NET Framework are
1. The common language runtime (CLR).
2. The .NET Framework class library.
3. When can’t you use ASP.NET to
create a Web application?
When you are developing for non–Microsoft Windows
Web servers, such as Linux/Apache.
4. List the four major differences
between Web and Windows applications.
Web forms cannot use the standard Windows controls.
Instead, they use server controls, HTML controls, user controls, or custom
controls created especially for Web forms.
Web applications are displayed in a browser.
Windows applications display their own windows and have more control over how
those windows are displayed.
Web forms are instantiated on the server, sent to
the browser, and destroyed immediately. Windows forms are instantiated, exist
for as long as needed, and are destroyed.
Web applications run on a server and are displayed
remotely on clients. Windows applications run on the same machine they are
displayed on.
5. Describe the life cycle of a
Web application: When are Web forms instantiated and how long do they exist?
A Web application starts with the first request for
a resource within the application’s boundaries. Web forms are instantiated when
they are requested. They are processed by the server and are abandoned
immediately after the server sends its response to the client. A Web
application ends after all client sessions end.
6. How do you preserve persistent
data, such as simple variables, in a Web application?
You can preserve data in state variables, such as
ApplicationState, SessionState, or ViewState.
7. How does the .NET Framework
organize its classes?
The .NET Framework uses namespaces to organize its
classes.
8. In Visual Basic .NET, what is
the difference between a class module and a code module?
Class modules are instantiated at run time to
create objects that provide separate storage for variables and properties in
each instance. Code modules do not have instances, so any module-level
variables they use are shared among calls to the module’s procedures.
9. In Visual C#, how do you
declare a method to make it available without having to first instantiate an
object from the class?
To create a method that can be called without
instantiating an object, declare that method as static.
10. How do you call a member of a
base class from within a derived class?
To refer to a member of a base class in Visual
Basic .NET, use the MyBase keyword. To refer to a member of a base class in
Visual C#, use the base keyword.
11. Where would you save the
following data items so that they persist between requests to a Web form?
A control created at run time, an object that
provides services to all users, User preferences
Save controls created at run time in the Page
object’s ViewState.
Save objects that provide services to all users in
the Application state.
Save user preferences in SessionState.
12. What is the main difference
between the Button server control and the Button HTML control?
When clicked, the Button server control triggers an
ASP.NET Click event procedure on the server. The Button HTML control triggers
the event procedure indicated in the button’s onclick attribute, which runs on
the client.
13. How do you get several
RadioButton controls to interoperate on a Web form so that only one of the
RadioButton controls can have a value of True/true at any given time?
Set the Group Name property of each RadioButton to
the same name.
14. Why does ASP.NET perform
validation on both the client and the server?
Client-side validation helps avoid round-trips to
the server. Validating on the client ensures that the data is valid before it
is submitted, in most cases. However, because validation might be turned off
(or maliciously hacked) on the client, data must be revalidated on the server
side. This provides full assurance that the data is valid while avoiding as
many round-trips as possible.
15. What types of validation would
you use to verify that a user entered a valid customer number?
You would use a RequiredFieldValidator and a
RegularExpressionValidator. If you have access to a list of expected customer
numbers, you could replace the RegularExpressionValidator with a
CustomValidator that checked the list.
16. What is wrong with the
following line of code?
Server.Transfer ("Default.htm");
You can’t use the Transfer method with HTML pages.
It works only with .aspx pages.
17. Why can’t you open a new
browser window from within server code?
Server code executes on the server, whereas the new
window is created on the client. You need to use client-side code to do things
that affect the client, such as upload files, display new windows, or navigate
back in history.
18. What steps would you follow
and what objects would you use to quickly find the number of records in a
database table?
There are two ways to accomplish this task:
Use a database connection and a command object to
execute a SQL command that re-turns the number of rows in the table.
Use a database connection and data adapter object
to create a data set for the table, and then get the number rows in the data
set.
19. How do typed data sets differ
from untyped data sets, and what are the advantages of typed data sets?
Typed data sets use explicit names and data types
for their members, whereas untyped data sets use collections to refer to their
members. The following examples show a typed reference vs. an untyped reference
to a data item:
// Typed reference to the Contacts table's
HomePhone column.
DataSet1.Contacts.HomePhoneColumn.Caption =
"@Home";
// untyped reference to the Contacts table's
HomePhone column.
DataSet1.Tables ["Contacts"].Columns ["HomePhone"].Caption
= "@Home";
Typed data sets do error checking at design time.
This error checking helps catch typos and type mismatch errors, which would be
detected only at run time with untyped data sets.
20. How do you call a stored
procedure?
Create a command object, set the object’s
CommandText property to the name of the stored procedure, and set the
CommandType property to StoredProcedure. To execute the stored procedure, use
the command object’s ExecuteNonQuery, ExcecuteScalar, ExecuteReader, or
ExecutelXmlReader method. For example, the following code calls the Ten Most
Expensive Products stored procedure on the Northwind Traders database:
// create a connection for NorthWind Trader's
database.
SqlConnection connNWind = new SqlConnection ("integrated
security=SSPI;" +
"data source=(local);initial
catalog=Northwind");
// Create a command object to execute.
SqlCommand cmdTopTen = new SqlCommand(connNWind);
cmdTopTen.CommandText = "Ten Most Expensive
Products";
// Set the command properties.
cmdTopTen.CommandType =
CommandType.StoredProcedure;
// create a data reader object to get the results.
SqlDataReader drdTopTen;
// Open the connection.
connNWind.Open();
// Excecute the stored procedure.
drdTopTen = cmdTopTen.ExecuteReader();
21. Explain the difference between
handling transactions at the data set level and at the database level.
Data sets provide implicit transactions, because
changes to the data set aren’t made permanent in the database until you call
the Update method. To handle transactions in a data set, process the Update
method and check for errors. If errors occur during an update, none of the
changes from the data set is made in the database. You can try to correct the
error and resubmit the update, or you can roll back the changes to the data set
using the RejectChanges method.
Databases provide explicit transactions through the
Transaction object. You create a Transaction object from a database connection
and then assign that Transaction object to the commands you want to include in
the transaction through the command object’s Transaction property. As you
perform the commands on the database, you check for errors. If errors occur,
you can either try to correct them and resubmit the command, or you can restore
the state of the database using the Transaction object’s RollBack method. If no
errors occur, you can make the changes permanent by calling the transaction
object’s Commit method.
22. Explain why exception handling
is important to a completed application.
When an unhandled exception occurs in an
application, the application stops—the user can’t proceed, and any work he or
she did immediately prior to the exception is lost. Exception handling provides
a way to intercept and correct unusual occurrences that would otherwise cause
these problems.
23. List two different
exception-handling approaches in ASP.NET Web applications.
Exceptions can be handled in exception-handling
blocks using the Try, Catch, and finally keywords in Visual Basic .NET or the
try, catch, and finally keywords in Visual C#. They can also be handled using
Error event procedures at the Global, Application, or Page levels using the
Server object’s GetLastError and ClearError methods.
24. Describe the purpose of error
pages and why they are needed.
Because Web applications run over the Internet,
some exceptions occur outside the scope of the application. This means that
your application can’t respond directly to these exceptions. These types of
exceptions are identified by HTTP response codes, which IIS can respond to by
displaying custom error pages listed in your application’s Web.config file.
25. Explain why tracing helps with
exception handling.
Tracing allows you to record unusual events while
your application is running, without users being aware of it. If an
unanticipated exception occurs, your application can write a message to the
trace log, which helps you diagnose problems during testing and after
deployment.
26. Write the HTML for a hyperlink
that will send mail when the user clicks the link.
&late href="mailto:you@pragim.com?SUBJECT=Sending
from a client&BODY=some message text."> Send mail
27. Write the code that creates a
cookie containing the user name Rob Young and the current date to the user’s
computer. Set the cookie to remain on the user’s computer for 30 days.
HttpCookie cookUserInfo = new
HttpCookie("UserInfo");
CookUserInfo["Name"] = "Rob
Young";
CookUserInfo["Time"] =
DateTime.Now.ToString();
cookUserInfo.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(cookUserInfo);
28. What attribute do you use to
hide a public .NET class from COM?
Use the ComVisible attribute to select which public
.NET classes and members are visible to COM. This attribute applies
hierarchically for the assembly, class, and member levels.
29. Why can’t you open a new
browser window using server-side code? How would you display a page in a new
window with a client-side script?
Server-side code can execute tasks only on the
server. To perform a task on the client’s computer, such as opening a new browser
window, the code needs to run on the client.
You can open a new window using the DOM window
object. For example, the following HTML Button control opens a Help page in a
new window:
< button id="butHelp"
onclick="window.open('help.aspx', 'help', 'height=200,width=300')"
> Help
30. Which ASP.NET authentication
mode is best suited to identifying and authorizing users who belong to a
corporate network?
Windows authentication is best suited to
authenticating users of a corporate network because it uses the accounts and
permissions that already exist for network users.