Wednesday, April 11, 2012

Understanding the .NET Framework





Overview
The Internet revolution of the late 1990s represented a dramatic shift in the way
individuals and organizations communicate with each other. Traditional applications,
such as word processors and accounting packages, are modeled as stand-alone
applications: they offer users the capability to perform tasks using data stored on the
system the application resides and executes on. Most new software, in contrast, is
modeled based on a distributed computing model where applications collaborate to
provide services and expose functionality to each other. As a result, the primary role of
most new software is changing into supporting information exchange (through Web
servers and browsers), collaboration (through e-mail and instant messaging), and
individual expression (through Web logs, also known as Blogs, and e-zines — Web
based magazines). Essentially, the basic role of software is changing from providing
discrete functionality to providing services.
The .NET Framework represents a unified, object-oriented set of services and libraries
that embrace the changing role of new network-centric and network-aware software. In
fact, the .NET Framework is the first platform designed from the ground up with the
Internet in mind.
This chapter introduces the .NET Framework in terms of the benefits it provides. I
present some sample code in Visual C# .NET, Visual Basic .NET, Visual Basic 6.0, and
Visual C++; don't worry if you're not familiar with these languages, since I describe in the
discussion what each sample does.

Benefits of the .NET Framework
The .NET Framework offers a number of benefits to developers:
§ A consistent programming model
§ Direct support for security
§ Simplified development efforts
§ Easy application deployment and maintenance

Consistent programming model

Different programming languages offer different models for doing the same thing. For
example, the following code demonstrates how to open a file and write a one-line message to it using Visual Basic 6.0:

Public Sub testFileAccess()
On Error GoTo handle_Error
' Use native method of opening an writing to a file...
Dim outputFile As Long
outputFile = FreeFile
Open "c:\temp\test.txt" For Output As #outputFile
Print #outputFile, "Hello World!"
Close #outputFile
' Use the Microsoft Scripting Runtime to
' open and write to the file...
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim outputText As TextStream
Set outputText = fso.CreateTextFile("c:\temp\test2.txt")
outputText.WriteLine "Hello World!"
outputText.Close
Set fso = Nothing
Exit Sub
handle_Error:
' Handle or report error here
End Sub





The .NET Class Library is a key component of the .NET Framework — it is sometimes
referred to as the Base Class Library (BCL). The .NET Class Library contains hundreds
of classes you can use for tasks such as the following:
§ Processing XML
§ Working with data from multiple data sources
§ Debugging your code and working with event logs
§ Working with data streams and files
§ Managing the run-time environment
§ Developing Web services, components, and standard Windows applications
§ Working with application security
§ Working with directory services
The functionality that the .NET Class Library provides is available to all .NET languages,
resulting in a consistent object model regardless of the programming language
developers use.

Direct support for security
Developing an application that resides on a user's desktop system and uses local
resources is easy, from a security point of view, because security simply isn't a
consideration in this scenario. Security becomes much more important when you create
applications that access data on remote systems or applications that perform privileged
tasks on behalf of nonprivileged users, because systems may have to authenticate
users, and encryption (scrambling to avoid eavesdropping) may be necessary to secure
data communications.
Windows NT, Windows 2000, and Windows XP have a number of security features
based on Access Control Lists (ACLs). An ACL contains a number of entries that specify
which users may access, or are explicitly denied access, to resources such as files and
printers. ACLs are a great way of protecting executable files (applications) from
unauthorized access, but they do not secure all parts of the file. The .NET Framework
enables both developers and system administrators to specify method-level security.
Developers (through easy-to-use programming language constructs called attributes)
and systems administrators (by using administrative tools and byediting an application's
configuration file) can configure an application's security so that only authorized users
can invoke a component's methods.
The .NET Framework uses industry-standard protocols such as TCP/IP and means of
communications such as the Extensible Markup Language (XML), Simple Object Access
Protocol (SOAP, a standard application messaging protocol), and HTTP to facilitate
distributed application communications. This makes distributed computing more secure,
because .NET developers cooperate with network connectivity devices as opposed to
attempting to work around their security restrictions.

Simplified development efforts

Two aspects of creating Web-based applications present unique challenges to Web
developers: visual page design and debugging applications. Visual page design is
straightforward when creating static content; however, when you need to present the
result of executing a query in a tabular format using an ASP page, page design can get
rather involved. This is because developers need to mix traditional ASP code, which
represents the application's logic, and HTML, which represents the presentation of the
data. ASP.NET and the .NET Framework simplify development by allowing developers to
separate an application's logic from its presentation, resulting in an easier-to-maintain
code base. ASP.NET can also handle the details of maintaining the state of controls,
such as the contents of text boxes, between calls to the same ASP.NET page, thereby
reducing the amount of code you need to write. Visual Studio .NET, which is tightly
integrated with the .NET Framework, assists developers as they create ASP.NET and
other applications by providing visual designers that facilitate visual drag and drop
editing, making page layout and form layout a breeze.
Another aspect of creating applications is debugging. Developers sometimes make
mistakes; systems don't behave as you expect them to, and unexpected conditions arise
— all of these issues are collectively referred to as, using the affectionate term, "bugs."
Tracking down bugs — known as "debugging" — quickly and effectively requires
developers to be familiar with a variety of tools, sometimes available from a third party,
and techniques — a combination of programming techniques and techniques for using a
particular tool. The .NET Framework simplifies debugging with support for Runtime
diagnostics.
Runtime diagnostics not only help you track down bugs but also help you determine how
well your applications perform and assess the condition of your application. The .NET
Framework provides three types of Runtime diagnostics:
§ Event logging
§ Performance counters
§ Tracing


Event logging

Windows 2000 and Windows XP have a feature called an Event Log _ a database
containing information about important hardware or software events. The Event Log is
useful for recording information about the status of your applications and provides
systems administrators a means of diagnosing problems, since they can review Event
Log entries using the Event Viewer (supplied with Windows and available in the
Administrative Tools group in the Control Panel). There are three types of Event Log
events:
§ Informational events: Usually contain basic information, such as an
application starting or shutting down
§ Warning events: Usually provide information about unusual conditions that
have the potential to become errors
§ Error events: Represent critical errors in an application that prevent it from
executing normally
Events are stored in Event Logs — Windows supports three types of Event Logs:
§ Application: Contains messages that applications such as Microsoft SQL
Server log
§ System: Contains messages that device drivers and system services log.
§ Security: Contains system-generated messages about events that occur
when security auditing is enabled

The .NET Framework makes it easy to work with the Event Log as shown in the following code:

Imports System
Imports System.Diagnostics
Module eventLogDemo
Sub Main()
If Not EventLog.SourceExists("ASPnetBible") Then
EventLog.CreateEventSource( _
"ASPnetBible", "Application")
Console.WriteLine( _
"Created new EventSource 'ASPnetBible'")
End If
Dim evLog As New EventLog()
evLog.Source = "ASPnetBible"
' Note: this listing does not show the
' complete message for brevity
evLog.WriteEntry( "...starting")
Console.WriteLine("Wrote 'starting'...")
evLog.WriteEntry("... exiting")
Console.WriteLine("Wrote 'exit'...")
End Sub
End Module




This code is a Visual Basic .NET console application that creates an Event Source called
ASPnetBible and logs the application's starting and exiting events to the system's
Application event log — although the listing doesn't show it, both messages are
informational.

Performance counters
Performance counters are useful for monitoring the health and performance of an
application. You can chart the value of performance counters using the Performance
applet in the Administrative Tools folder of the systems Control Panel. The .NET
Framework makes it easy for you to read the value of existing performance counters,
such as the system's percent CPU Utilization, as well as create your own applicationspecific
performance counters. The following code demonstrates how to work with
performance counters in a simple Windows Forms application:
' Create a new performace counter

Dim counterCollection As New CounterCreationDataCollection()
Dim couterItem As New CounterCreationData()
counterName = "demoCounter"
perfCatName = "ASPnetBible"
couterItem.CounterName = counterName
couterItem.CounterType =
PerformanceCounterType.NumberOfItems32
counterCollection.Add(couterItem)
PerformanceCounterCategory.Create(perfCatName, _
"sample counter", counterCollection)
' ...elsewhere in the application - Increment the counter
Dim perfCounter As PerformanceCounter
perfCounter = New PerformanceCounter()
perfCounter.CategoryName = perfCatName
perfCounter.CounterName = counterName
perfCounter.ReadOnly = False
perfCounter.IncrementBy(50)
System.Threading.Thread.Sleep(2000)
perfCounter.IncrementBy(-50)
'...elsewhere in the application - Delete the sample counter
PerformanceCounterCategory.Delete(perfCatName)

This code demonstrates how to create a new performance counter category and counter
using the CouterCreationDataCollection and CouterCreationData classes —
the fragment shown is from the sample application's Load event handler. In the next
section of the code, from a button's Click event handler, the code creates an instance
of the sample performance counter, increments it, and waits two seconds before
decrementing the counter. The last part of the code shows how to delete the
performance counter when the form closes.





Tracing

Debugging an application by using the Visual Studio .NET debugger is a great way to
track down problems; however, there are many scenarios in which things happen too
quickly to follow interactively or in which you simply need to know the sequence of
events that lead to a problem before the problem occurs.
Tracing is an alternative to using a debugger to step through each line of code as your
application executes. You can configure ASP.NET tracing by using two methods: pagelevel
tracing and application-level tracing. Both types of tracing provide similar results;
however, the difference is in how you access the results for each approach. Page-level
tracing provides trace details on the ASPX page when it completes executing, and
application-level tracing stores the details of the trace in a file called (by default)
trace.acx, which is located in the same directory as the ASP.NET application — you
can view the file by using your browser.
When you enable tracing, which is disabled by default, ASP.NET records detailed
information about the page request, trace messages, control information, cookies,
header information, the contents of any form fields, and a raw output of the contents of
server variables (like CONTENT_TYPE and HTTP_REFERRER). Table 1-1 shows a
fragment of a trace output from a simple ASP.NET page.





Easy application deployment and maintenance

Applications are often made up of several components:
§ Web pages
§ Windows forms-based components
§ Web services
§ Components housed in DLLs
The .NET Framework makes it possible to install applications that use some or all of
these components without having to register DLLs (using regsvr32.exe) or to create
Registration Database (also known as the system Registry) entries.
The .NET Framework makes it easy to deploy applications using zero-impact installation
— often all that's required to install an application is to copy it into a directory along with
the components it requires. This is possible because the .NET Framework handles the
details of locating and loading components an application needs, even if you have
several versions of the same component available on a single system. All of this is
possible because the .NET Framework records extra information about an application's
components — the extra information is called metadata. A component of the .NET
Framework, the Class Loader, inspects an application's metadata and ensures that all of
the components the application depends on are available on the system before the
application begins to execute. This feature of the .NET Framework works to isolate
applications from each other despite changes in system configuration, making it easier to
install and upgrade applications.
Once an application is running on a system, it is sometimes necessary to change certain
traits of the application, such as its security requirements, optional parameters, and even
database connections. .NET Framework applications use a configuration model based
on application-configuration files. A configuration file is a text file that contains XML
elements that affect the behavior of an application. For example, an administrator can
configure an application to use only a certain version of a component the application
relies on, thereby ensuring consistent behavior regardless of how often the component is
upgraded. The following code shows an ASP.NET's basic configuration file; the file is called web.config:










This code shows that the ASP.NET application will have page buffering on (pages will be
sent to clients only when the page is completely rendered), and that ASP.NET will track
individual clients' session information (as shown in the pages tag). This code also
demonstrates how to define a custom configuration key, called dsn — within the
appSettings section, which applications have access to through the TraceSwitch
class.

If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website

0 comments:

Post a Comment