cookieChoices = {};
Showing posts with label ASP. Show all posts
Showing posts with label ASP. Show all posts

Wednesday, 20 August 2014

ASP LIFE CYCLE


In general terms, the page goes through the stages outlined in the following table. In addition to the page life-cycle stages, there are application stages that occur before and after a request but are not specific to a page.
Some parts of the life cycle occur only when a page is processed as a postback. For postbacks, the page life cycle is the same during a partial-page postback (as when you use an UpdatePanel control) as it is during a full-page postback.
Stage
Description                                                                                           7
Page request
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.
Start
In the start stage, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. The page also sets the UICulture property.
Initialization
During page initialization, controls on the page are available and each control's UniqueID property is set. A master page and themes are also applied to the page if applicable. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.
Load
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
Postback event handling
If the request is a postback, control event handlers are called. After that, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page. (There is an exception to this sequence: the handler for the event that caused validation is called after validation.)
Rendering
Before rendering, view state is saved for the page and all controls. During the rendering stage, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStreamobject of the page's Response property.
Unload
The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and cleanup is performed.
http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gifLife-Cycle Events

Within each stage of the life cycle of a page, the page raises events that you can handle to run your own code. For control events, you bind the event handler to the event, either declaratively using attributes such as onclick, or in code.
Pages also support automatic event wire-up, meaning that ASP.NET looks for methods with particular names and automatically runs those methods when certain events are raised. If the AutoEventWireup attribute of the @ Page directive is set to true, page events are automatically bound to methods that use the naming convention of Page_event, such asPage_Load and Page_Init. The following table lists the page life-cycle events that you will use most frequently. There are more events than those listed; however, they are not used for most page-processing scenarios. Instead, they are primarily used by server controls on the ASP.NET Web page to initialize and render themselves. If you want to write custom ASP.NET server controls, you need to understand more about these events.
Page Event
Typical Use
Raised after the start stage is complete and before the initialization stage begins.
Use this event for the following:
·        Check the IsPostBack property to determine whether this is the first time the page is being processed. The IsCallback and IsCrossPagePostBack properties have also been set at this time.
·        Create or re-create dynamic controls.
·        Set a master page dynamically.
·        Set the Theme property dynamically.
·        Read or set profile property values.
NoteNote
If the request is a postback, the values of the controls have not yet been restored from view state. If you set a control property at this stage, its value might be overwritten in the next event.
Raised after all controls have been initialized and any skin settings have been applied. The Init event of individual controls occurs before the Init event of the page.
Use this event to read or initialize control properties.
Raised at the end of the page's initialization stage. Only one operation takes place between the Initand InitComplete events: tracking of view state changes is turned on. View state tracking enables controls to persist any values that are programmatically added to the ViewState collection. Until view state tracking is turned on, any values added to view state are lost across postbacks. Controls typically turn on view state tracking immediately after they raise their Init event.
Use this event to make changes to view state that you want to make sure are persisted after the next postback.
Raised after the page loads view state for itself and all controls, and after it processes postback data that is included with the Request instance.
The Page object calls the OnLoad method on the Page object, and then recursively does the same for each child control until the page and all controls are loaded. The Load event of individual controls occurs after the Load event of the page.
Use the OnLoad event method to set properties in controls and to establish database connections.
Control events
Use these events to handle specific control events, such as a Button control's Click event or aTextBox control's TextChanged event.
NoteNote
In a postback request, if the page contains validator controls, check the IsValid property of the Pageand of individual validation controls before performing any processing.
Raised at the end of the event-handling stage.
Use this event for tasks that require that all other controls on the page be loaded.
Raised after the Page object has created all controls that are required in order to render the page, including child controls of composite controls. (To do this, the Page object callsEnsureChildControls for each control and for the page.)
The Page object raises the PreRender event on the Page object, and then recursively does the same for each child control. The PreRender event of individual controls occurs after the PreRender event of the page.
Use the event to make final changes to the contents of the page or its controls before the rendering stage begins.
Raised after each data bound control whose DataSourceID property is set calls its DataBind method. For more information, see Data Binding Events for Data-Bound Controls later in this topic.
Raised after view state and control state have been saved for the page and for all controls. Any changes to the page or controls at this point affect rendering, but the changes will not be retrieved on the next postback.
This is not an event; instead, at this stage of processing, the Page object calls this method on each control. All ASP.NET Web server controls have a Render method that writes out the control's markup to send to the browser.
If you create a custom control, you typically override this method to output the control's markup. However, if your custom control incorporates only standard ASP.NET Web server controls and no custom markup, you do not need to override the Render method. For more information, seeDeveloping Custom ASP.NET Server Controls.
A user control (an .ascx file) automatically incorporates rendering, so you do not need to explicitly render the control in code.
Raised for each control and then for the page.
In controls, use this event to do final cleanup for specific controls, such as closing control-specific database connections.
For the page itself, use this event to do final cleanup work, such as closing open files and database connections, or finishing up logging or other request-specific tasks.
NoteNote
During the unload stage, the page and its controls have been rendered, so you cannot make further changes to the response stream. If you attempt to call a method such as the Response.Writemethod, the page will throw an exception.


Wednesday, 5 February 2014

IIS



What is IIS (Internet Information Server)?
It is a windows component, a web server that accepts requests from client browsers and responds with the requested page(s)

IIS Manager: A tool to configure and manage IIS. To launch IIS Manager one of the below methods can be used.
Control Panel à Administrative Tools à IIS Manager
                                                (Or)
Start à Run à inetmgr.exe

Default Website: Default website is a website provided in IIS at the time of installation of IIS.  The physical directory used by the default website of IIS is c:\inetpub\wwwroot and the port is 80

IIS Website & Application
·         A computer connected to the internet that maintains a series of web pages on the World Wide Web
·         A Website is made up of one or more IIS b (Virtual Directories).
·         Every Web Application has a Virtual Directory but every Virtual Directory doesn’t necessary need to be an Application.
·         The physical directory of the web application need not be the subdirectory of the physical directory of web site.

Steps to Create Multiple Website on Port 80
1.       Go to IIS Manager
2.       Right click on Websites à New à Website
3.       Host Header = "DemoSite"
4.       Give Physical Directory: c:\DemoSite
5.       Edit: c:\windows\system32\drivers\etc\hosts (this is alternative to DNS server)
6.       Note: Hosts is a file...Which can map name to IP Address
127.0.0.1    DemoSite
Note: The above address should be IP of server.             
7.       In c:\DemoSite create and Html file (demo.html)
8.       Browser: http://DemoSite/Demo.html

What is an Application Pool?

·         An Application Pool contains one or more applications and allows us to configure a level of isolation between different Web applications.
·         If we want to isolate all the Web applications running in the same computer, we can do so by creating a separate application pool for every Web application and placing them in their corresponding application pool.
·         Because each application pool runs in its own worker process, errors in one application pool will not affect the applications running in other application pools.
·         When you configure application pools for optimum availability, you also should consider how to configure application pools for application security. For example, you might need to create separate application pools for applications that require a high level of security, while allowing applications that require a lower level of security to share the same application pool.

In the above example, IIS is hosting three Applications in two Application Pools.  For example, If Web Application 3 crashes Web Application 2 will not be affected.  However Web Application 1 will be affected as it is in the same Application pool

What is AppDomain
Asp.Net introduces the concept of an Application Domain which is shortly known as AppDomain. It can be considered as a Lightweight process which is both a container and boundary. The .NET runtime uses an AppDomain as a container for code and data, just like the operating system uses a process as a container for code and data. As the operating system uses a process to isolate misbehaving code, the .NET runtime uses an AppDomain to isolate code inside of a secure boundary.





ISAPI Programming Model (Internet Server Application Programming Interface).
1.       ISAPI extensions are true applications that run on IIS and have access to all of the functionality provided by IIS. As an example of how powerful ISAPI extensions can be, ASP pages are processed through an ISAPI extension called ASP.dll. In general, clients can access ISAPI extensions the same way they access a static HTML file or dynamic ASP file.
2.      ISAPI filters are DLL files that can be used to modify and enhance the functionality provided by IIS. ISAPI filters always run on an IIS server, filtering every request until they find one they need to process. The ability to examine and modify both incoming and outgoing streams of data makes ISAPI filters powerful and flexible.
ASP.NET uses ISAPI programming model and it uses the below




General Terms
Web Farm: When multiple machines are used with different role(s) designated for each server, it is called a Web Farm Scenario.  It is normally applied, where heavy request and processing loads are expected.  Using Web Farm, enhances performance of the entire system.

Web Garden: When a single machine is configured to perform multiple roles it is called a Web Garden scenario.  For example, the webserver machine itself also acts as the database server and the SMTP server etc.  Web Garden in normally applied when request and processing loads are not high.

Network Load Balancing (NLB) : It is a service for Windows 2008 server. NLB gives a common virtual machine name to all the web servers present in an organization, i.e., web servers on different machines, i.e., if 10 machines are used in NLB then all the 10 machines would have the same virtual name and all of them share the load.  NLB sends new requests to the server with least load.



HTTPS (Secured Socket Layer)
HTTPS is used for sites containing sensitive data that requires secured environment/transfer of information.

How does Https work?
All https pages will contain a Certificate (Private Key + Public Key) which is issued by a Certificate Authority.  The pages that are transferred are encrypted and it can be decrypted only if the Private Key is available. 

Certificate Authority:  It’s a server that creates certificates. Examples: Verisign, Windows Certificate Authority. 
Windows Certificate Authority is a built-in Certificate Authority which comes with Windows OS. 
It can be installed from Control PanelàAdd Remove ProgramsàWindows Componentsàselect Certificate Services.

To Create a Certificate:
Goto IIS Manager è Select Machine Name àIn Center Panel, under IIS section, Double on Server Certificates
On the right panel à Select Create Self Signed Certificate à Give Friendly Name = “DemoCertificate”

To Enable HTTPS for a Website
·         Select the WebSite in left panel
·         On right Panel click on Bindings (Opens a Dialog)
·         Click on Add button à Type = Https, Port = 443, SSL certificate = “DemoCertificate”

In Browser open the website with URL starting with HTTPS.

Active Directory users and groups creation

Creating a group in Active Directory

  • Startà Administrative ToolsàActive Directory Users and Computers
  • Right click on domain name à New à Group à Group Name : DevelopersàGroup Scope: Domain LocalàOK
v  Similarly create Faculty group, Staff group and Students group

To Create Users in Active Directory

  • Startà Administrative ToolsàActive Directory Users and Computers
  • Right click on domain name à New à User à First Name : Developer1àUser Logon :developer1àNEXTàPassword : dss@123 àSelect user cannot change password àSelect password never expiresàNEXTàFINISH

To Associate User to a Specific Group

àRight click on User NameàPropertiesàMember ofàAddàAdvancedàFind NowàSelect DevelopersàOKàOK
v  Similarly create users (Faculty1, Student1 and Staff1) for other groups and associate with their respective group.  
v  We also create another user “CIO” for whom we give access at a higher level so we don’t associate this user to any other group.  (email address: cio@deccansoft.com)

 

Configuring Internet Explorer to prompt Username and Password

Internet ExploreràToolsàInternet OptionsàSecurityàLocal InternetàCustom Levelà[under user authentication] Prompt for Username and PasswordàOK