420 likes | 510 Views
An Introduction to ASP .NET. Chris Whitehead, MCSE Columbus State University. Microsoft’s Claim.
E N D
An Introduction toASP .NET Chris Whitehead, MCSE Columbus State University
Microsoft’s Claim ASP.NET is a revolutionary programming framework that enables the rapid development of powerful web applications and services. Part of the emerging Microsoft .NET Platform, it provides the easiest and most scalable way to build, deploy and run distributed web applications that can target any browser or device.
ASP • Simple procedural programming model • Access to COM Objects • ADO • File system object • No compiling, just save • Support for Multiple Scripting languages • Mix HTML and Code • VBScript – Leverage VB Skills
Advantages of Using ASP • Dynamic creation of Web pages • Easy connection and display of database information • Can perform form processing • Browser-independent • Can be tested on local machine • PWS – 95/98/ME • IIS – 2000/XP • Flexible server-side scripting capabilities • VBScript, JavaScript, CGI/Perl • C, C++, C#, Java • Pages can include both server-side scripting and client-side scripting
ASP Challenges • Code Readability • Mixed code + html • Performance • Interpreted • PostBack Complexity • Had to manage postback manually • Reuse • DLL Locking • Permission Denied (Error 70) • Deployment • Sessions • Restricted To Inproc • Caching • Different Programming models, debuggers, IDE’s etc
Why ASP .NET? Solve the issues inherent in ASP • Enhanced performance • Power and flexibility • Simplicity • Manageability • Scalability and availability • Customizability and extensibility • Reliability • Security
Why ASP .NET? (2) • Make it easier to build web apps • Make it easier to deploy web apps • Make it easier to operate web apps • Provide greater performance,reliability, and scalability
What is ASP .NET • Not an ASP upgrade • Next-generation, unified Web development framework • New control-based, execution model for Web UI
ASP .NET Capabilities • It’s really, really fast! • Deploy and upgrade running apps with XCOPY • Great tools support • Automatically detects and recovers from errors • Web farm scalable session state • Built-in output caching • Supports wide range of mobile devices • Uses compiled languages • Makes building web services easy • Much simpler page development model
Changes from Previous Versions • Requires .NET framework • Pages end in “.aspx” instead of “.asp” • Can process both “.asp” and “.aspx” • Expanded object library • Web services and server controls
2781 1989 1154 Microsoft ASP.NET PC Magazine Nile Application Test Pages Served per Second 2800 8 CPU 4 CPU 2 CPU 2400 2000 1600 1200 748 637 800 330 400 Microsoft ASP
System Requirements • Requires a ASP processor on the server • For previous versions of ASP • Windows 95/98/ME/NT/2000/XP • Preinstalled with PWS or IIS • Linux – add-in • For ASP .NET • Windows 2000+ • IIS 5.0+ • .NET Framework
Installation • Server • Download and install .NET Framework (http://www.asp.net/download.aspx) • Add ASPNET user
ASP .NET Configuration • Stored in XML file in directory with pages • web.config • Contains all ASP.NET settings • Authentication, compile options, custom error pages, etc. • Allows adding Application settings • DSN, URLs to WebServices, etc • Extensible • Can extend with custom configuration data
The .NET Framework VB C++ C# JScript … Visual Studio.NET Common Language Specification WindowsForms ASP.NET: Web Services and Web Forms WindowsForms ADO.NET: Data and XML Base Class Library Common Language Runtime
Web Forms • A Web Form combines declarative tags (HTML, ASP directives, server controls and static text) with code • However, good separation provided between code and tags separate files single file <tags> <tags> code code Form1.aspx Form1.aspx Form1.vb
Web Forms (2) • 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
ASP Architecture ASP .ASP Request for Page
ASP .NET Architecture ASPX .ASPX Request for Page
ASP .NET Architecture (2) Compiled .ASPX First Request for Page
Compiled .ASPX ASP .NET Architecture (3) Subsequent Request for Page
Compiled .ASPX ASP .NET Architecture (4) Page is modified
ASP .NET Syntax • Requires “<%” and “%>” enclose any ASP scripting • Scripting can be placed in any location in a Web page provided it is enclosed in the delimiters
Hello World Example <html> <head> <title>Hello World</title> <body> <% response.write (“Hello World!”) %> </body> </html> Save as helloworld.aspx
Server Controls • Used in addition to or instead of <% %> to control Web page • Use runat=“server” attribute
More on Server Controls • Previous form <form action = “process.asp”> <input type = “text” name = “mytextbox”> </form> • With server controls <form action = “process.aspx” method-post runat = “server”> <asp:textbox id = “MyTextBox” runat = “server” /> </form>
Data Controls • Bind to many data sources • Collections • Array • HashTable • Dictionary • ADO.NET • DataReader • DataSet • XML • Can bind data to virtually any control • Eg textbox, listbox + more specific data-orientated controls (eg datagrid)
DataSet DataGrid Authors Publishers Repeater DataList DataView/DataSet Data Controls “Data Controls”
ASP.NET Web Applications • Global ASAX • Application Variables • Session State • Web Configuration • i.e properties of the web site msdn.microsoft.com
Web ApplicationsGlobal.ASAX • First Request • Application_Start • First Request for Each User • Session_Start • Each Request • Application_BeginRequest • Application_Authenticate • Application_EndRequest • Application Error • Application_Error • User Logs Out/Session Times Out • Session_End • Web Server Shutdown • Application_End msdn.microsoft.com
ASP .NET Web ApplicationsConfig.Web • Site Configuration file • Like an .INI file for your site • XML format • Extensible • Some settings • Security • Session • Localization • Tracing • Debugging msdn.microsoft.com
ASP .NET Web ApplicationsSession Variables • Store state information • No longer require Cookies • Share between servers <sessionstate inproc="false" server=“AnotherServer" port="42424" /> msdn.microsoft.com
Caching • Output caching • Serves rendered result of a page from cache • Big performance win: cached pages are as fast as static pages • Vary by params, language, user-agent • Cache API • Enables arbitrary objects to be cached • Example: result of database query • Can be a big performance win
Improved Deployment • Components can be dynamically updated • No more locked DLLs • Just copy new DLL on top of old one • No tools, no configuration changes, no app shutdown, no re-boots • Works great with content replication systems
Improved Reliability • ASP.NET has been designed with assumption that failures will occur on systems • Designing for failure reduced fragility • Detects/recovers from common problems • Access Violations, Memory Leaks, Deadlocks • Pre-emptive cycling of applications • Time and Request Based Settings • Net Result: Users should never think that an ASP.NET application is down or unavailable
Migrating From ASP • http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspnetmigrissues.asp • Guidelines for existing ASP Solutions • Use Option Explicit • Avoid Using Default Properties • Use Parentheses and the Call Keyword • Avoid Nested Include Files • Organize Utility Functions into Single Files • Remove Code from Content as much as Possible • Do Not Declare Functions Inside <% %> Blocks • Avoid Render Functions • Explicitly Free Resources (Call Close Methods) • Avoid Mixing Languages msdn.microsoft.com
ASP .NET Resources • 123aspx.com • ASPFree.com • ASPNG.com • ASP Today • ASPAlliance • 4GuysFromRolla.com • ASPWorkshops.com • 411ASP.NET • ASPX101.net • ASP.net • MSDN.Microsoft.com
Summary • ASP.NET is a rich web application platform • Combines simplicity and power • Easy to deploy and maintain • Reliable, highly available and scalable • It’s really, really fast!