320 likes | 569 Views
Build Web Applications with Visual Studio ® .NET. Carlotta Eaton – www.nr.vccs.edu/eaton Associate Professor of IST New River Community College Slides by Microsoft Modified by Carlotta Eaton. Agenda. Web Forms ASP.NET Applications Caching. Session Prerequisites.
E N D
Build Web Applications with Visual Studio® .NET Carlotta Eaton – www.nr.vccs.edu/eaton Associate Professor of IST New River Community College Slides by Microsoft Modified by Carlotta Eaton
Agenda • Web Forms • ASP.NET Applications • Caching
Session Prerequisites • Experience with Visual Basic® 6.0, Visual Basic .NET, Visual C#™or Visual C++®, Visual Basic Scripting Edition • Experience developing Web Applications Level 200
Agenda • Web Forms • ASP.NET Applications • Caching
Web FormsActive Server Pages .NET • Part of the .NET Framework • ASP.NET builds, deploys, and runs Web applications and services • Visual Studio .NET Web applications support ASP.NET directly VB C++ C# Perl Python … Web Services User Interface ASP.NET ADO.NET: Data and XML Base Framework Common Language Runtime
Web Forms ASP.NET Page Framework • New control-based, event-driven execution model for Web UI • “Visual Basic for the Web” • Much less code required than ASP • Cleanly encapsulated functionality • Executed via CLR as native code • Visual Basic, C#, JScript® • ASP.NET pages use “.ASPX” extension • Runs side-by-side on Internet Information Server with current ASP applications
Web Forms Part Declarative, Part Code • A Web Form combines declarative tags (HTML, ASP directives, server controls and static text) with code • However, good separation provided between code and tags Visual Studio .NET single file separate files <tags> <tags> code code Form1.aspx Form1.aspx Form1.vb
Web Forms Page Event Life Cycle Page is loaded and initialized Page_Load Control Events Textbox1_Changed 1. Change Events Button1_Click 2. Action Events Page_Unload Page is disposed
Web FormsServer Controls • 45 Built In Controls • Target any HTML 3.2 browser • Raise Events to Server • Basic Controls • textbox, checkbox, radio, button • Advanced Controls • AdRotator, Calendar, DataGrid, Validator
Web Forms Server Controls • Declared as HTML or XML tag with runat=server attribute • Examples:<input type=text id=text2runat=server> <asp:calendar id=myCal runat=server/> • Tag name identifies control to create • Control is implemented as .NET object • ID attribute provides programmatic accessor
Web FormsBasic Server Controls • <asp:textbox id=text1 runat=server/>text1.text = “Hello World” • <asp:checkbox id=check1 runat=server/>check1.checked=True • <asp:button id=button1 runat=server/>onclick=button1_onClick() • <asp:DropDownList id=DropDownList1 runat=server>DropDownList1.SelectedItem.Text = “Hello”
Web FormsServer Side Events • <asp:button id=Button1 runat=server • onClick=Button1_Click> • <asp:DropDownList id=DrpDwn1 runat=server OnSelectedIndexChanged=DrpDwn1_ItemSelected>
Agenda • Web Forms • ASP.NET Applications • Caching
ASP.NET ApplicationsSaving Application State • Essentially global variables for the application • Application(“CompanyName”) • Can lock or unlock Application State Variables • Application.lock • Application(“GlobalCounter”) = NewValue • Application.unlock
ASP.NET ApplicationsSaving Session State • Per User Variables • Available to All Pages in the Site • Session(“UserID”) = 5 • UserID = Session(“UserID”)
ASP.NET ApplicationsASP versus ASP.NET State • ASP Session State • Forces “Server Affinity” • Dependent on cookies • Not fault tolerant • ASP.NET Session State • Support for Web Gardens and Server Farms • Doesn’t require cookies • Better fault tolerance
ASP.NET ApplicationsConfiguring Session State • Configuration information stored in Web.Config <sessionState mode=“sqlserver” cookieless=“false” timeout=“20” sqlConnectionString=“data source=127.0.0.1;user id=sa;password=“” stateConnectionString="tcpip=127.0.0.1:42424" /> </sessionState>
ASP.NET ApplicationsConfiguring Session State • Mode • InProc – Conventional session variables. Stored in-memory on the web server • StateServer – Sessions are stored on an external server, in memory • SqlServer – Sessions are stored in a SQL database • Cookieless • Determines if Cookieless sessions should be used • Values are true or false • TimeOut • Determines the default timeout for the web site
ASP.NET ApplicationsConfiguring Session State • sqlConnectionString • contains the datasource, userid, and password parameters necessary to connect to a sql database that holds the session state • connectionString • Contains information needed to connect to the state server
ASP.NET ApplicationsStoring Data in SQL Server™ • In order to setup the SQL Server to store state information you must run a small T-SQL script on the target server • InstallSQLState.sql can be found in [sysdrive]\winnt\Microsoft.NET\Framework\[version] • Creates the following on the server • A database called ASPState • Stored Procedures • Tables in TempDB to hold session data. • Uninstall is via • UninstallSQLState.sql
Agenda • Web Forms • ASP.NET Applications • Caching
CachingPage Output Caching • Pages That Don’t Change Frequently • Dramatic Performance Increase <%@ OutputCache Duration= "500“ VaryByParam=“none” %>
Caching Fragment Caching • Dynamic Portions of a Page • Data Doesn’t Change Frequently • User Control Site Header <%@ OutputCache Duration=“60“ VaryByParm=“none” %> Navigation Page Body Caches only the page body for the specified duration
Caching Cache APIs • Programmatically Cache Data Cache.Insert( _ Key, _ Value, _ CacheDependency, _ AbsoluteExpiration, _ SlidingExpiration, _ Priority, _ PriorityDecay, _ Callback)
Caching Cache APIs • Key • String used to look up the cached item • Value • Item or object to store in the cache • CacheDependency • Cache item can automatically expire when a file, directory, or other cache item changes
Caching Cache APIs • AbsoluteExpiration • Cache item can expire at some fixed time (midnight, for example) • SlidingExpiration • Cache item can expire after a certain amount of inactivity • Priority • When forcing items from the cache, which items should go first • PriorityDecay • Within a given priority range, does this item expire fast or slow
Session Summary • Visual Studio .NET + ASP.NET = “Visual Basic for the Web” • Drag-drop-double-click • Event-driven, control-based encapsulation • Target any client, or specific clients • Big runtime benefits over ASP: • Fast native code execution • Hassle-free deployment • “Baked-in” support for security, Web Farms, out-of-proc Session state, etc.
For More Information… • MSDN Web site at • msdn.microsoft.com • Microsoft® Official Curricula (MOC) • Introduction to ASP.NET • Course 2063 • Programming the .NET Framework with Visual Basic • Course 2415 • Microsoft Press® • Introducing Microsoft .NET
MSDNEssential Resources for Developers Subscription Services Library, Professional, Universal Delivered via CD-ROM, DVD, Web OnlineInformation MSDN Online, MSDN Flash Training & Events MSDN Training, Tech-Ed, PDC, Developer Days, MSDN/Onsite Events Print Publications MSDN Magazine MSDN News MembershipPrograms MSDN User Groups