1.04k likes | 1.05k Views
This course provides an overview of web development using ASP.NET and focuses on topics such as debugging, .NET controls, security, email/file integration, XML, and web services.
E N D
Programming in C#Developing Web ApplicationsPlatform II1/11/2014 – 2/22/2014 David Henson dhenson@certifiednetworks.com
Class Logistics • Class Hours • Classroom Setup • Class Format • https://www.certifiednetworks.com
Course Outline Module 1 - Web Overview Module 2 - ASP.NET Overview Module 3 - ASP.NET Webform Module 4 – Debugging/Tracing Module 5 - .NET Controls Module 6 – ADO.NET
Course Outline, Contd. Module 7 – Advanced Data Topics Module 8 - Security Module 9 – ASP.NET Email/File Integration Module 10 – XML and Web Services
Definitions • C# • MSIL • CLR • ASP.NET • MVC • HTTP • HTML • IIS • Virtual Directory • Browser • ASP
Web Server/Client Interaction • Disconnected Paradigm • “Cookies” used to emulate state
HTTP Protocol • Header • Body
Lab 1A – Viewing HTTP Traffic • Things to look for: • Header • Body • Server Response Code
Methods For Dynamic Server-Based Content • CGI – Opens separate executable • ASP – Interpreted each page load, Windows Only • JSP – Portable, fast familiar to Java Programmers • PHP – Cross Platform, C & Perl Like • ASP.NET – Compiled, integrated into framework
HTML Protocol • End result of any dynamic server side product- dictates rendering of page • Tags: <html> <body> <table><tr><td> <form> <a href=“…”> <br> <input type=“…”>
What is ASP.NET • Not a programming language but a delivery mechanism • Can leverage any .NET programming language, like built-in VB.NET, C#, and third party like Delphi
.NET Features • Multiple Language Support • Increased Performance • Compiled code • Cache • Server Controls • Web Services • Improved Security • Greater Scalability • Cookie-less Sessions • Easy Configuration and Deployment
Classic ASP Programming Model • Procedural, Top to Bottom Approach • HTML/ASP Code Mixed
Classic Windows Programming Model • Create a Form • Drop Controls On Form • Write Event Handlers • User activity generates messages which are handled by the event handlers
Demonstration – Spy++ • What to look for: • Event Driven Model of Windows
ASP.NET Programming Model • Process Same as Windows Programming • Connectivity/State is emulated
ASP.NET Configuration Files • Web.config • IIS Settings • Application Defined
Solution Files • Solution contains 1 or more projects • .sln file created in: My documents\Visual Studio Projects\*.* • To Change Defaults: Tools/Options/Environment/Projects & Solutions • New Solution Created With New Project
Project Files • Project maps to web application • Web Application Created in: c:\inetpub\wwwroot\projectname • Project Configuration File: (.vbproj or .csproj) • New Virtual Directory Created W/ Project • Each Application can have its own web.config
Other Files • Webforms: .aspx • Web Services: .asmx • Styles.css IIS Prevents Execution of Pre-Defined Extensions • Code Behind Files: .vb & .cs • Discovery Files: .disco, .vsdisco • ASP.NET Application File: Global.asax • Resource Files: .resx • Web.Config
Webforms Defined • aspx extension • @Page Directive • Framework Is an Object Model • Denoted by the runat="server" Attribute • Contain Client-side and Server-side Code • Contain HTML and .NET Server Controls <%@ Page Language="vb" %> <Form runat="server"> </Form>
Events • User requests dbdemo.aspx • Page_Load event detected • Sub Page_Load() executed • All event handlers are called in a single flow of motion, before the user ever gets to see the page.
WebForm Main Events • Events Occur Each Time the Page is Accessed • Page_Init • Page_Load • Controls(only when form is posted back…Button1_Click for example) • Page_Unload
Other Supported Webform Events • Error – whenever the page generates one • CommitTransaction • AbortTransaction
Defining Server Control Event Handlers <asp:button id=“Button1” onclick=“MyHandler”/> You may also double-click the control in design view to get into the “default” event handler for that control with a pre-defined event handler name.
Webform Validation • Page.IsValid will be false if any control has failed validation • Asp:ValidationSummary Control • Set Display property of any validation control to None • ValidationSummary Control will display msg from all controls • Client Side Validation Setting: Set BaseValidator.EnableClientSideScript for any contol
Manual Validation • Add form submit button with CausesValidation set to False, then call Page.Validate yourself. • Take action based upon page.IsValid property
Module 4 – Debugging/Tracing • Debugging • Tracing • Error/Exception Handling
To Compile in Debug Mode • 1. Add a "Debug=true" directive at the top of the file that generated the error. Example: <%@ Page Language="C#" Debug="true" %>or:2) Add the following section to the configuration file of your application:<configuration> <system.web> <compilation debug="true"/> </system.web></configuration>
Using the Debugger • Setting Breakpoints • Debug shortcut keys:
Logging Exceptions Try …some code Catch err AS Exception Dim log as New EventLog() Log.Source = “MyPage” Log.WriteEntry(err.Message, EventLogEntryType.Error) End Try
Display of Errors • Error Modes: • RemoteOnly – Default, hides details if not local client • Off – Shows all details and source…good for development, not production • On – Displays custom error page if any, or generic error message
Custom Error Pages <configuration> <system.web> <customErrors defaultRedirect=“MyError.aspx”> <error statusCode=“404” redirect=“My404.aspx”> </customErrors> </system.web> </configuration> Only works if ASP.NET is handling the request(.aspx extension)
Lab 04A – Debugging/Tracing • Enabling Tracing • Exception Handling • Debugging • Writing to the Windows Eventlog • Custom Error Messages
The ASP.NET Server Controls • HTML Server Controls • ASP.NET Web Form Controls • ASP.NET List Controls • ASP.NET Templated Controls • ASP.NET Rich Controls • ASP.NET Validation Controls • ASP.NET Mobile Controls
User Controls • .ascx file • Replaces the #include file from ASP • Provides re-usuable code within your application • Contained within a Webform
Custom Server Controls • Based on System.Web.UI.Control • Generates its own HTML (unlike a business logic assembly)