资源描述
Click to edit Title Slide,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,ASP.NET Development,Agenda,What is ASP.NET?,Web Forms,Server Controls&User Controls,Databinding ASP.NET Pages,ASP.NET Caching,ASP.NET Configuration,ASP.NET Security,ASP.NET Applications,Deploying ASP.NET Web Applications,What is ASP.NET?,Microsofts platform for building,Web Applications,Part of the.NET Framework,Server Side Technology,.NET Framework,Base Class Library,Common Language Specification,Common Language Runtime,ADO.NET:Data and XML,VB,C+,C#,Visual Studio.NET,ASP.NET:Web Services,and Web Forms,JScript,WindowsForms,ASP.NET,Base Class Library,Common Language Specification,Common Language Runtime,VB,C+,C#,Visual Studio.NET,ASP.NET:Web Services,and Web Forms,JScript,WindowsForms,ADO.NET:Data and XML,ASP.NET Features,ASPX,ASP Side by Side,Simplified Programming Model,Control-based,event-driven execution model,Code Behind Pages,Powerful Controls,Powerful Data Access,Better Performance,Executed via CLR as native code,ASP.NET Feature,Simplified Browser Support,Simplified Form Validation,Better Session Management,Caching,Security,Web Services,Simplified Deployment,ASP.NET Execution Model,ASPX,.ASPX,ASP.NET Execution Model,.ASPX,Compiled,ASP.NET Execution Model,.ASPX,Compiled,ASP.NET Execution Model,.ASPX,Compiled,.ASPX,Compiled,ASP.NET Execution Model,demo,Agenda,What is ASP.NET?,Web Forms,Server Controls&User Controls,Databinding ASP.NET Pages,ASP.NET Caching,ASP.NET Configuration,ASP.NET Security,ASP.NET Applications,Deploying ASP.NET Web Applications,Web Form Pages,Part Declarative,Part Code,Declarative“tags”,HTML,server controls,static text,Server Side Code,Great separation between code and markup,Form1.aspx,code,Form1.aspx,code,Form1.vb,single file,separate files(“code-behind”),A Page Can Include,Directives,Code Block,Render Blocks,Server Control Tags,HTML(WML,etc),Runtime Compilation,ASPX,File,Request,ASPX,Engine,Parse,GendPageClass,Generate,Response,Request,Instantiate,Response,Code-behindclass,Page,Class,Instantiate,Process and Render,Compile,ASP.NET Page Life Cycle,Similar to Microsoft,Win32,application,Events raised as page created,Form_Initialize()-Page_Init(),Form_Load()-Page_Load(),Form_Activate()-Page_PreRender(),Form_Unload()-Page_Unload(),Simple ASP.NET Page,demo,Agenda,What is ASP.NET?,Web Forms,Server Controls&User Controls,Databinding ASP.NET Pages,ASP.NET Caching,ASP.NET Configuration,ASP.NET Security,ASP.NET Applications,Deploying ASP.NET Web Applications,ASP.NET Server Controls,Server controls encapsulate,Rendering,Behavior,Generate markup that is sent to the client,DHTML,HTML 3.2,WML,etc.,Offer up dynamic experience,Process input sent from client,Bind to data,Fire server side events for notifications,Standard ASP.NET Controls,Web Controls,Render client-targeted HTML and script,Consistent,strongly-typed object model,Some render as single HTML tags:,Button,TextBox,DropDownList,Some render richer HTML+script:,DataGrid,Calendar,Validators,Html Controls,Map 1:1 with HTML tags,ASP.NET Server Controls,Runat Enables Server Side Processing,Required validator control,Range validator control,Compare validator control,Regular expression validator,Custom validator control,ASP.NET Validation Control,ASP.NET Server Control,demo,Control Event Processing,Events are:,Triggered on the client,Handled in server code,Requires a,postback,to the same page,Relies on State Management,Handling Control Events,Wire up the handler on the tag:,Event handler code:,Sub btn1_Click(s,as Object,e as EventArgs),Message.Text=Button1 clicked,End Sub,VS.NET,Page/Control Event Execution,Page_Load,Page_Unload,Textbox1_Changed,Button1_Click,(on PostBack),1.Change Events,2.Action Events,Page is loaded,control hierarchy initialized,Page is disposed,Control hierarchy is rendered,Page_Load Details,Page_Load fires on every request,Test,Page.IsPostBack,to execute conditional logic,Example:,Sub Page_Load(s As Object,e As EventArgs),If Not,Page.IsPostBack,Then,executes only on initial page load,Message.Text=initial value,End If,End Sub,State Management,ViewState,helps restore control to its previous state,Implemented as a hidden form field,Disable via:,EnableViewState=false,SessionState,used to store data associated with the current session,Postback Forms,demo,User Controls,Server controls,authored like pages,Enable full encapsulation,Supports nested controls,Separate code namespace,Separate code language,Great way to partition work,Great way to reuse work across multiple pages and applications,Directive,Registers User Control for use on a Web Forms page:,Exposing An Object Model,User controls expose an object model,Properties,Fields,Events,Methods,Example:,public string Color,get,set,Creating a User Control,demo,Agenda,What is ASP.NET?,Web Forms,Server Controls&User Controls,Databinding ASP.NET Pages,ASP.NET Caching,ASP.NET Configuration,ASP.NET Security,ASP.NET Applications,Deploying ASP.NET Web Applications,Web Forms Data Binding,Provides a simple,declarative way to bind Web UI elements to data,“Simple”binding to a single property,“List”binding to a data source,DataGrid,DropDownList,etc.,Huge variety of data sources supported,But,One way snapshot model,Requires code to update the data source,Simple Binding Syntax,Step 1:Set bindings,Declaratively(in HTML):,Step 2:Call DataBind,Sub Page_Load(s As Object,e As EventArgs)Label1.,DataBind,(),End Sub,Simple Binding Example,Sub Page_Load(s as Object,e as EventArgs),Label1.DataBind(),End Sub,Binding Data To Lists,DataGrid,DropDownList,etc.,Supported DataSources,ADO.NET Connected:,DataReader,ADO.NET Cached:,DataSet,DataTable,DataView,Also other IEnumerable types:,ArrayList,Array,Hashtable,Result of a method,List Binding Syntax,Step 1:Set bindings,Declaratively(in HTML):,Imperatively(in code):,DataGrid1.DataSource=ds;,Step 2:Call DataBind,Sub Page_Load(s As Object,e As EventArgs)DataGrid1.,DataBind,()End Sub,Binding To Templated Lists,Templates enable“Lookless”UI,Customize structure not just style,Controls can be nested within templates,Repeater,DataList,DataGrid,Container:alias for the item created from the template+data,Container.DataItem,“this row of data”,Templated List Example,Sub Page_Load(s as Object,e as EventArgs),DataList1.DataSource=GetCustData(),DataList1.DataBind(),End Sub,DataBinder.Eval Method,Helper method for late-binding,before,:,after,:,Optional 3,rd,param for formatting,ASP.NET Databinding,demo,Agenda,What is ASP.NET?,Web Forms,Server Controls&User Controls,Databinding ASP.NET Pages,ASP.NET Caching,ASP.NET Configuration,ASP.NET Security,ASP.NET Applications,Deploying ASP.NET Web Applications,Page Output Caching,Pages that dont change frequently,Dramatic performance increase,Fragment Caching,Dynamic portions of a page,Data doesnt change frequently,User control,Cache APIs,Programmatically cache data,Cache.Insert(_,Key,_,Value,_,CacheDependency,_,AbsoluteExpiration,_,SlidingExpiration,_,Priority,_,PriorityDecay,_,Callback),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,Cache APIs,AbsoluteExpiration,Cache item can expire at some fixed time.,SlidingExpiration,Cache item can expire after a certain amount of inactivity,Priority,When forcing items from the cache,which items should go first,Cache APIs,ASP.NET Cache,demo,Agenda,What is ASP.NET?,Web Forms,Server Controls&User Controls,Databinding ASP.NET Pages,ASP.NET Caching,ASP.NET Configuration,ASP.NET Security,ASP.NET Applications,Deploying ASP.NET Web Applications,Web.config,Site configuration file,Ships with the site,Stores most configuration options,Eases maintenance and deployment,Changes take effect immediately,Hierarchical Architecture,Web.config files and their settings are inherited in a hierarchy,Machine settings(WinntMicrosoft.NETVersion),Web application root directory,Subdirectories,Settings can be targeted at a specified set of file/directory by use of the tag,Hierarchical Architecture,Default Configuration Settings,Machine.config,TracingDisabled,Execution timeout90 seconds,Session stateEnabled,inproc,AuthenticationAllow anonymous,Multiple CPU supportDisabled,Custom Configuration Settings,Examples of customization,AppSettings,CustomErrors,Trace settings,Authentication,Session settings,Custom setting in web.config,add key=DSN value=server=localhost”,Accessing with code,DSN=ConfigurationSettings.AppSettings(DSN),AppSettings,Redirect certain errors to certain pages,CustomErrors,Trace Configuration,Writing to trace log,Trace.Write(Page_Load,Entering Event),Trace.Warn(“Login,Invalid Argument),Tracing,Tracing,Enabled,Tracing information will be stored.Information can be accessed through“site/trace.axd”,RequestLimit,Store tracing information for this many requests,PageOutput,Allows trace output to also appear at the bottom of the page,TraceMode,Allows trace information to be sorted by time or category,ASP.NET Configuration,demo,Agenda,What is ASP.NET?,Web Forms,Server Controls&User Controls,Databinding ASP.NET Pages,ASP.NET Caching,ASP.NET Configuration,ASP.NET Security,ASP.NET Applications,Deploying ASP.NET Web Applications,Security Concepts,Authentication,Authorization,Impersonation,Authentication,Windows,Basic,Digest,Integrated,Form,Passport,Windows Authentication,Enabled for IIS through Internet Services Manager,Enabled for ASP.NET through web.config,Windows Authentication,Site can easily access user name,Dim UserName As String,UserName=User.Identity.Name,NT groups automatically map to ASP.NET roles,If User.IsInRole(Administrators)Then,Windows Authentication,Web site is responsible for security,not IIS,Configure IIS to allow anonymous access,Set web.config to force users to authenticate through a form,Any unauthenticated user will get sent to Login.aspx,Form Authentication,You code a form to collect user ID and password,After authenticate a user:,FormAuthentication.RedirectFromLoginPage(UserName,False),RedirectFromLoginPage,Marks the user as authenticated,Takes the user to the page they originally requested,If the user requested the login page,takes the user to default.aspx,Can persist authentication in a cookie,Form Authentication,Declarative Form Authentication,For simple sites,you can store user ID and password in web.config,User is authenticated by calling,FormsAuthentication.Authenticate(UserName,Password),Programmatic Form Authentication,Code is used to authenticate the user,If UserFoundInDataBase then,FormAuthentication.RedirectFromLoginPage(UserName,false),Else,lblLoginError.Text=User Not Found or Invalid Password,end if,Role Based Security,Jane,Jill,John,Jenny,Jamie,RD,Admins,Page,RD Content,Admin Content,Programmatically assigning users to roles,Sub Application_AuthenticateRequest(ByVal Sender As Object,ByVal e As EventArgs),If request.IsAuthenticated=True Then,sql=select role from roles where userid=&UserID&,Get Roles from Result Set,context.User=New GenericPrincipal(user,roles),End If,End Sub,Role Based Security,Display content based on roles,If User.IsInRole(HumanRes)Then,cmdEditSalary.Visible=true,End If,Role Based Security,Impersonation,Windows authentication,web.config,ASP.NET Security,demo,Agenda,What is ASP.NET?,Web Forms,Server Controls&User Controls,Databinding ASP.NET Pages,ASP.NET Caching,ASP.NET Configuration,ASP.NET Security,ASP.NET Applications,Deploying ASP.NET Web Applications,Application_OnStart,Application_OnEnd,Session_OnStart,Session_OnEnd,Traditional ASP(Global.asa),ASP.NET Global.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,Application_BeginRequest,Text to be included at the start of every page,Application_EndRequest,Text to be added to the end of every page,Application_Error,Useful for sending out an e-mail or writing to the event log when an error occurs that was not properly handled at the source of the error,Global.asax Event Usage,Session_End,Writing to a log file or database that a user has logged out at a given time,Application_End,Useful for writing out when the Web application had to stop.Could write an entry out to the event log,Application_Start,Useful for loaded site specific configuration information,Global.asax Event Usage,Essentially global variables for the application,Application(CompanyName),Can lock or unlock application state variables,Application.lock,Application(GlobalCounter)=NewValue,Application.unlock,Saving Application State,Per-user variables,Available to all pages in the site,Session(UserID)=5,UserID=Session(UserID),Saving Session State,ASP session state,Dependent on cookies,Not fault tolerant,ASP.NET session state,Support for Web gardens and server farms,Doesnt require cookies,Better fault tolerance-Proc,State Server,SQL Server,ASP vs.ASP.NET Session State,Configuration information stored in web.config,Configuring 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,Configuring Session State,SQLConnectionString,Contains the datasource,userid,and password parameters necessary to connect to a SQL database that holds the session state,stateConnectionString,Contains information needed to connect to the state server,Configuring Session State,You must run a small T-SQL script on the target server,Install SQLState.sql which can be found in sysdrivewinntMicrosoft.NETFrameworkversion,Creates the following on the server,A database called ASPState,Stored procedures,Tables in TempDB to hold session data,Uninstall via UninstallSQLState.sql,Storing Session in SQL Server,Agenda,What is ASP.NET?,Web Forms,Server Controls&User Controls,Databinding ASP.NET Pages,ASP.NET Caching,ASP.NET Configuration,ASP.NET Security,ASP.NET Applications,Deploying ASP.NET Web Applications,Deployment,Install,XCopy,No Registering DLLs,No Locked DLLs,Apps are Isolated,Each App Can Have Its Own Version,Uninstall,Delete,Summary,What is ASP.NET?,Web Forms,Server Controls&User Controls,Databinding ASP.NET Pages,ASP.NET Caching,ASP.NET Configuration,ASP.NET Security,ASP.NET Applications,Deploying ASP.NET Web Applications,2003 Microsoft Corporation.All rights reserved.,This presentation is for informational purposes only.MICROSOFT MAKES NO WARRANTIES,EXPRESS OR IMPLIED,IN THIS SUMMARY.,
展开阅读全文