




已阅读5页,还剩88页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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,Windows Forms,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,Windows Forms,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,Runtime Compilation,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 3rd 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 Tracing Disabled Execution timeout 90 seconds Session state Enabled, inproc Authentication Allow anonymous Multiple CPU support Disabled,Custom Configuration Settings,Examples of customization AppSettings CustomErrors Trace settings Authentication Session settings,Custom setting in web.config 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 “http:/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 datab
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 45448-2025再生变形高温合金原料
- GB/T 13460-2025再生橡胶通用规范
- 项目管理复杂问题解析试题及答案
- 产品销售协议合同2025
- 中等职业教育联合办学协议
- 企业金融管理的变革方向试题及答案
- 未来展望2025年银行从业资格证试题及答案
- 证券从业资格证考试复习材料的选择与使用技巧试题及答案
- 微生物耐药性检测与解读试题及答案
- 灵活运用项目管理考试的理论知识试题及答案
- 2024年交管12123学法减分考试题库及完整答案【考点梳理】
- 急诊护理一科一特色
- 永辉超市干货部培训课件
- BIPAP呼吸机的使用与护理课件
- 统编版三年级下册第二单元“寓言故事”大单元整体学习设计
- 卵巢癌术后护理查房
- icu家属健康宣教
- 技术创新与产品研发投入效果评估与优化报告
- 挪用公款还款协议书范本
- 架空输电线路基础设计规程2023
- TWI-JM(工作改善)课件
评论
0/150
提交评论