Sie sind auf Seite 1von 10

What is .NET Framework and what are CLR, CTS and CLS?

. NET is a software platform. It's a language-neutral environment for developing


.NET applications that can easily and securely operate within it. The .NET Framework has two main components: the Common Language Runtime (CLR) and the .NET Framework class library. The Runtime can be considered an agent that manages code at execution time. Thus providing core services such as memory management, thread management, and remoting. Also incorporating strict type safety, security and robustness. The class library is a comprehensive collection of reusable types that you can use to develop traditional command-line, WinForm (graphical user interface) applications, Web Forms and XML Web services. The .NET Framework provides a Runtime environment called the Common Language Runtime or (CLR) that handles the execution of the code and provides useful services for the implementation of the application. CLR takes care of code management upon program execution and provides various services such as memory management, thread management, security management and other system services. The managed code targets CLR benefits by using useful features such as cross-language integration, cross-language exception handling, versioning, enhanced security, deployment support, and debugging. Common Type System (CTS) describes how types are declared, used and managed. CTS facilitates cross-language integration, type safety, and high performance code execution. The CLS is a specification that defines the rules to support language integration. This is done in such a way, that programs written in any language (.NET compliant) can interoperate with one another. This also can take full advantage of inheritance, polymorphism, exceptions, and other features.

What is an Intermediate language?


Assemblies are made up of IL code modules and the metadata that describes them. Although programs may be compiled via an IDE or the command line, in fact, they are simply translated into IL, not machine code. The actual machine code is not generated until the function that requires it is called. This is the just-intime, or JIT, compilation feature of .NET. JIT compilation happens at runtime for a variety of reasons, one of the most ambitious being Microsoft's desire for cross-platform .NET adoption. If a CLR is built for another operating system (UNIX or Mac), the same assemblies will run in addition to the Microsoft platforms. The hope is that .NET assemblies are write-once-run-anywhere applications. This is a .NET feature that works behind-the-scenes, ensuring that developers are not limited to writing applications for one single line of products. No one has demonstrated whether or not this promise will ever truly materialize. CTS/CLS

The MSIL Instruction Set Specification is included with the .NET SDK, along with the IL Assembly LanguageProgrammers Reference. If a developer wants to write custom .NET programming languages, these are the necessary specifications and syntax. The CTS and CLS define the types and syntaxes that every .NET language needs to embrace. An application may not expose these features, but it must consider them when communicating through IL.

Understanding and Using .NET Partial Classes


In a nutshell, partial classes mean that your class definition can be split into multiple physical files. Logically, partial classes do not make any difference to the compiler. During compile time, it simply groups all the various partial classes and treats them as a single entity. One of the greatest benefits of partial classes is that it allows a clean separation of business logic and the user interface (in particular the code that is generated by the visual designer). Using partial classes, the UI code can be hidden from the developer, who usually has no need to access it anyway. Partial classes will also make debugging easier, as the code is partitioned into separate files.

Page Life Cycle


Page_Init LoadViewState LoadPostData Page_Load RaisePostDataChangedEvent RaisePostBackEvent Page_PreRender SaveViewState Page_Render Page_Unload Page Initialization View State Loading Postback Data Processing Page Loading PostBack Change Notification PostBack Event Handling Page Pre Rendering Phase View State Saving Page Rendering Page Unloading

The first processed method is Page_Init(). Once the control tree has been created, the controls declared in the .aspx file are initialized. The controls can modify some of the settings set in this method to be used later in the page life cycle. Obviously no other information is available to be modified at this time. The next processed method is LoadViewState(). The Viewstate contains stored information that is set by the page and controls of the page. This is carried to and from every aspx page request per visitor. I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself. The next processed method is LoadPostData(). These are values associated with the HTML form

elements the visitor has typed, changed or selected. Now the control has access to this information which can update their stored information pulled from the Viewstate. The next processed method is Page_Load(). This method should look familiar and is usually the most common used method on the server side application code for an .aspx file. All code inside of this method is executed once at the beginning of the page. The next processed method is RaisePostDataChangedEvent(). When a visitor completes a form and presses the submit button, an event is triggered. This change in state signals the page to do something. The next processed method is RaisePostBackEvent(). This method allows the page to know what event has been triggered and which method to call. If the visitor clicks Button1, then Button1_Click is usually called to perform its function. Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased! The next processed method is Page_PreRender(). This method is the last chance for the Viewstate to be changed based on the PostBackEvent before the page is rendered. The next processed method is SaveViewState(). This method saves the updated Viewstate to be processed on the next page. The final Viewstate is encoded to the _viewstate hidden field on the page during the page render. The next processed method is Page_Render(). This method renders all of the application code to be outputted on the page. This action is done with the HtmlWriter object. Each control uses the render method and caches the HTML prior to outputting. The last processed method is Page_Unload(). During this method, data can be released to free up resources on the server for other processes. Once this method is completed, the HTML is sent to the browser for client side processing.

How To Use Cookie


HttpCookie userCookie = new HttpCookie("UserInfo"); userCookie["Country"] = "Italy"; userCookie["City"] = "Rome"; userCookie["Name"] = "Jones"; userCookie.Expires = DateTime.Now.AddDays(3); Response.Cookies.Add(userCookie); Label1.Text = "Cookie create successful!<br><br/>"; HttpCookie cookie = Request.Cookies["UserInfo"]; if (cookie != null) { string country = cookie["Country"]; string city = cookie["City"]; string name = cookie["Name"]; Label2.Text = "Cookie Found and read<br/>"; Label2.Text += "Name: " + name; Label2.Text += "<br />Country: " + country;

Label2.Text += "<br />City: " + city; }

Some Questions : What is the maximum number of cookies that can be allowed to a web site? a) 1 b) 10 c) 20 - correct answer d) More than 30 a) IsPostBack is a method of System.UI.Web.Page class b) (your answer) IsPostBack is a method of System.Web.UI.Page class c) IsPostBack is a readonly property of System.Web.UI.Page class - correct answer Postback occurs in which of the following forms? a) Winforms b) HTMLForms c) Webforms - correct answer
Which of the following is true?

What namespace does the Web page belong in the .NET Framework class hierarchy? a) System.web.UI.Page - correct answer b) System.Windows.Page c) System.Web.page

The first event to be triggered in an aspx page is? a) Page_Load() b) Page_Init() - correct answer When an .aspx page is requested from the web server, the out put will be rendered to browser in following format? a) HTML - correct answer b) XML c) WML d) JSP

Difference between Server.Transfer and Response.Redirect


Response.Redirect simply sends a message down to the browser, telling it to move to another page. So, you may run code like: Response.Redirect("WebForm2.aspx") Or

Response.Redirect("http://www.karlmoore.com/")
To send the user to another page. Server.Transfer is similar in that it sends the user to another page with a statement such as Server.Transfer("WebForm2.aspx"). However, the statement has a number of distinct advantages and disadvantages.

Firstly, transferring to another page using Server.Transfer conserves server resources. Instead of telling the browser to redirect, it simply changes the "focus" on the Web server and transfers the request. This means you don't get quite as many HTTP requests coming through, which therefore eases the pressure on your Web server and makes your applications run faster. But watch out: because the "transfer" process can work on only those sites running on the server, you can't use Server.Transfer to send the user to an external site. Only Response.Redirect can do that. Secondly, Server.Transfer maintains the original URL in the browser. This can really help streamline data entry techniques, although it may make for confusion when debugging. That's not all: The Server.Transfer method also has a second parameter"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to. For example, if your WebForm1.aspx has a TextBox control called TextBox1 and you transferred to WebForm2.aspx with the preserveForm parameter set to True, you'd be able to retrieve the value of the original page TextBox control by referencing Request.Form("TextBox1").

Initialization of a Const member values are done at the declaration of the member whereas

Differences between constant and read only variable


Readonly can be initialized at the declaration as well as in a constructor. i.e; Const members is a compile-time constant whereas readonly fields can be used as runtime constant (value assigned only at runtime). Constant values cannot be changed after its initialization. But read only variables values can be changed inside the constructors.
public const int i=10 ; public readonly int k=i; //constant initialization //readOnly initialization

Constant variables can be assigned to the readonly. But readonly variables cant be assigned to the constant variables.

What are the authentication methods in .NET?


1.WINDOWS AUTHENTICATION 2.FORMS AUTHENTICATION 3.PASSPORT AUTHENTICATION 4.NONE/CUSTOM AUTHENTICATION The authentication option for the ASP.NET application is specified by using the tag in the Web.config file, as shown below: other authentication options 1. WINDOWS AUTHENTICATION Schemes I. Integrated Windows authentication II. Basic and basic with SSL authentication III. Digest authentication IV. Client Certificate authentication 2. FORMS AUTHENTICATION As a Web application developer, are supposed to develop the Web page and authenticate the user by checking the provided user ID and password against some user database 3. PASSPORT AUTHENTICATION A centralized service provided by Microsoft, offers a single logon point for clients. Unauthenticated users are redirected to the Passport site 4 NONE/CUSTOM AUTHENTICATION: If we dont want ASP.NET to perform any authentication, we can set the authentication mode to ?none?. The reason behind this decision could be: We dont want to authenticate our users, and our Web site is open for all to use, or we want to provide our own custom authentication

What is the difference between a namespace and assembly name?


A namespace is a logical naming scheme for types in which a simple type name, such as MyType, is preceded with a dot-separated hierarchical name. Such a naming scheme is completely under control of the developer. For example, types MyCompany.FileAccess.A and MyCompany.FileAccess.B might be logically expected to have functionally related to file access. The .NET Framework uses a hierarchical naming scheme for grouping types

into logical categories of related functionality, such as the ASP.NET application framework, or remoting functionality. Design tools can make use of namespaces to make it easier for developers to browse and reference types in their code. The concept of a namespace is not related to that of an assembly. A single assembly may contain types whose hierarchical names have different namespace roots, and a logical namespace root may span multiple assemblies. In the .NET Framework, a namespace is a logical design-time naming convenience, whereas an assembly establishes the name scope for types at run time.

View State:
ViewState is the mechanism ASP.NET uses to keep track of server control state values that don't otherwise post back as part of the HTTP form. ViewState Maintains the UI State of a Page ViewState is base64-encoded. It is not encrypted but it can be encrypted by setting EnableViewStatMAC="true" & setting the machineKey validation type to 3DES. If you want to NOT maintain the ViewState, include the directive < %@ Page EnableViewState="false" % > at the top of an .aspx page or add the attribute EnableViewState="false" to any control.

What are the benefits and limitations of using hidden fields?


Advantages: a. Easy to implement b. Hidden fields are supported by all browsers c. Enables faster access of information because data is stored on client side Disadvantages: a. Not secure because the data is stored on Client side. b. Decreases page performance if too many hidden fields c. Only support single value.

ADO.Net Architecture

Dataset
Datasets store a copy of data from the database tables. However, Datasets can not directly retrieve data from Databases. DataAdapters are used to link Databases with DataSets. The Dataset contains the copy of the data we requested. The Dataset contains more than one Table at a time. We can set up Data Relations between these tables within the DataSet. The data set may comprise data for one or more members, corresponding to the number of rows. A DataSet is a disconnected architecture, means there is no need to always open & close connection. It is cache of data retrieved from database. It is made up of collections of datatables.

Reading Data into a Dataset


To read data into Dataset, you need to:

Create a database connection and then a dataset object. Create a DataAdapter object and refer it to the DB connection already created. Note that The Fill method of DataAdapter has to be called to populate the Dataset object.
every DataAdapter has to refer to a connection object. For example, SqlDataAdapter refers to SqlDataConnection.

Das könnte Ihnen auch gefallen