Ngôn ngữ lập trình Java - Giới thiệu ms.net asp.net

MS. NET Framework & C# Nền tảng MS .NET Framework Ngôn ngữ chính của .NET: C# ASP.NET Tổng quan về công nghệ ASP.NET Lịch sử phát triển Đặc tính cơ bản

ppt51 trang | Chia sẻ: thuychi16 | Lượt xem: 790 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Ngôn ngữ lập trình Java - Giới thiệu ms.net asp.net, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
Trình bày: ThS Nguyễn Hà GiangMS. NET Framework & C#Nền tảng MS .NET FrameworkNgôn ngữ chính của .NET: C#ASP.NETTổng quan về công nghệ ASP.NETLịch sử phát triểnĐặc tính cơ bản****Chương trình nền tảng cho cho công nghệ .NETCung cấp tập hợp class library thường dùngQuản lý sự thực thi của các chương trình .NETCommon Language RuntimeBase Framework ClassesData and XML ClassesCustom ClassesC# VB.NET J# C++ XML Web ServiceWeb FormsWindows FormsASP.NET***Nguyen Ha Giang *.NET 1.1 (Apr-2003)VS .NET 2003Default: Server 2003.NET 3.5 (Nov-2007)VS.NET 2008Default: Windows 7.NET 3.0 (Nov-2006)Default: Windows Vista, Server 2008.NET 2.0 (Nov-2005)VS.NET 2005 **Common Language Infrastructure (CLI)Provide a language-neutral platform for application development and execution **Chạy trên nền (.NET Framework)Mã nguồn được biên dịch qua MSILMSIL được thông dịch qua mã máy lúc thực thi nhờ vào CLRĐộc lập nền tảngVề lý thuyết có thể chạy trên mọi nền!**MS ILCLRC++ CompilerC# CompilerJ# .NET CompilerCT C#.NETCT VB.NETCT C++.NET.NET FrameworkCT J#.NETVB .NET Compiler101101010110101011010Programmer**Theo quan điểm của người lập trình, .NET có thể hiểu như môi trường thực thi mới và thư viện lớp cơ sở cải tiến.Môi trường thực thi là: Common Language Runtime - CLRVai trò chính CLR: locate, load, manage .NET typesCLR còn quản lý những phần ở mức thấp như: memory management, security check**Common Type System (CTS): Mục đích hỗ trợ thực thi chéo ngôn ngữĐịnh nghĩa kiểu DL tiền định và có sẵn trong IL:Tất cả ngôn ngữ .NET sẽ được sinh ra mã cuối trên cơ sở kiểu dữ liệu này!IntegerInt32intVB.NETILC#**Intermediate Language Abstracted assembly language Ý tưởng về mã Java byteMã cấp thấp cú pháp đơn giản  quá trình dịch sang mã máy nhanh hơn!CLR chuyển IL thành mã máy lúc runtimeSự chuyển này gọi là Just – In – Time Compilation hay JIT compiling***C++, C#, VB or any .NET languagecsc.exe or vbc.exe...Compiler.NET AssemblyDLL or EXESource Code*Managed ModulesChứa IL code để thực thiChứa resource, metadataPortable Executable (PE)Process assembly (EXE)Library assembly (DLL)*.NET Assembly**Ứng dụng được viết để sử dụng trong .NET FrameworkUD khác thì gọi là Unmanaged code“Managed”: do chạy dưới sự giám sát của cơ chế thực thi (CLR)Windows(OS khác)Legacy Software(unmanaged code)Common Language RuntimeManaged Executable*Nguyen Ha Giang - 2009*class myClass{ void Method(){ variable v1; variable v2; do{ . }}BECADManaged HeapA và D sẽ bị xoá do ko còn tham chiếu hay truy cập tới**GC xuất hiện không định trước, do CRL gọi.GC thực hiện việc tìm kiếm những đối tượng trong managed heap, xoá nếu ko còn tham chiếu tới.Có thể gọi GC một cách tường minh**Tránh xung đột tênCho phép phân cấpTruy cập đầy đủ qua tênTất cả data type có tiếp đầu ngữ là tên namespaceNamespace CS1Class AClass BClass CNamespace CS2Class AClass BClass CCS1.ACS2.A*Khác nhau!*Hầu hết các lớp cơ sở chung của .NET đều thuộc namespace SystemLớp CS Array thuộc System → System.Array.NET đề nghị tất cả kiểu do user định nghĩa phải nằm trong 1 namespaceCustomerPersonelCompanyNameTên lớpTên namespace**Nên phân thành 2 cấp:Công nghệ Gói phần mềm chức năngCustomerPersonelCompanyNameTên lớpTên namespaceSaleServicesManagingServices**Thư viện lớp cơ sở .NET là managed codeĐược xây dựng từ ngôn ngữ C#!Khá đa dạng & đầy đủ:Cho phép kế thừa để phát triển UDBao bọc tất cả các hàm APIDễ sử dụng (khác với VC++ trước đây)**Các lớp .NET bao gồm các vấn đềĐặc tính lõi cung cấp IL, kiểu dữ liệu trong CTSHỗ trợ Win GUI và controlWebForm (ASP.NET)Data Access (ADO.NET)Directory AccessFile System, registry accessNetworking and web browsing.NET attributes and reflectionWinOS accessCOM interoperability*Thư viện nền tảng cho .NET FrameworkChia làm 2 phần: base class library và framework class library*NamespaceDescriptionSystemChứa lớp toán học, chuyển đổi dữ liệuSystem.IOCác lớp cho thao tác Input và OutputSystem.NetCác lớp liên quan đến network protocolSystem.CollectionsChức các lớp liên quan đến xử lý tập hợpSystem.DataCác lớp của ADO.NETSystem.DrawingCác lớp thực thi chức năng GUISystem.ThreadingCác lớp lập trình MultiThreadSystem.WebCác lớp liên quan đến HTTP protocolSystem.XmlCác lớp liên quan XMLSystem.Web.UISystem.Web.UI. WebControlsCung cấp lớp và interface để tạo ASP.NET Server Control và ASP.NET web pages***ASP (Active Server Page)Server side scriptingCác file chứa HTML và scripting codeTruy cập thông qua HTTP Scripting code được interpreting ở server sideASP cho phépNhanh chóng và dễ dàng tạo ứng dụng WebKhởi tạo nội dung web độngValidation script ở phía clientSử dụng COM với chức năng mở rộng: truy cập DB**Trộn lẫn giữa layout (HTML) và phần logic (script)Interpreting ASP dẫn đến hạn chế thực thiNgôn ngữ script không mạnh về kiểu dlJScript, VBScriptTương thích với trình duyệtQuản lý trạng thái kémCập nhật file khi server down**Nền tảng phát triển web mới của MSMô hình lập trình server –side mớiWeb ClientOperating SystemASP.NETApplicationsIIS.NET Framework**Tách bạch giữa layout và business logicSử dụng các dịch vụ được cung cấp bởi .NETCode được compile lần đầu tiên khi page được request Quản lý trạng tháiSử dụng nhiều ngôn ngữ lập trìnhCross language integrationCập nhật file trong khi server running!**NamespaceCấu trúc được phân cấpDot-syntax, những lớp được nhóm lại một cách logicNhiều lớp trừu tượng cơ sở và đa dạng các lớp thực thiCho phép lập trình viện thoải mái sử dụng & cũng như tạo riêng cho mình các lớpVí dụ: System.Web.UI.WebControls. ButtonNamespaceClass**System.Web.UI. WebControlsListControlListBoxCheckBoxListButtonTableWebControlSystem.Web.UI.ControlSystem.ObjectTextBox......**Cú pháp ASP.NET và các ngôn ngữ hỗ trợTiến trình thực thiAssembliesQuản lý trạng thái, bảo mật và xử lý sự kiện**Layout và Business logicKhông còn trộn lẫn giữa HTML và scripting codeDễ dàng maintainance cho Web appPhân biệt hoàn toàn giữa phần layout và phần xử lý logicKhông chứa code thực thi trong những file HTMLChia ra các file dành cho thiết kế & các file dành cho lập trìnhCó thể trộn lẫn code và layout nếu muốn!.aspx.cs.aspx**Visual BasicVBScript is unmanaged !JScriptC#New component-based languageC++Managed Extensions for C++Others: Cobol, Smalltalk, ...Common Language Specification (CLS)**Các loại file phân biệt với tên phần mở rộngFile ASP.NET chuẩn: aspx, ascxWeb service: asmxCode (behind) file: .aspx.cs, .asmx.vbFile cấu hình: Web.configWeb applications: global.asax, global.asax.csTất cả file đều là dạng file textCách dễ dàng để bắt đầu từ file asp chuyển thành aspx**DirectivesCode Declaration Blocks [ lines of code ] Code Render BlocksHTML Control Syntax **Custom Control SyntaxCustom server controlsServer control propertySubpropertyServer control event binding**Data Binding Expression’ runat=“server” />Server-side Object TagsServer-side Include DirectivesServer-side Comments** void SubmitBtn_Click(object sender, EventArgs e) { Message.Text = "Hello " + Name.Text; } Name: ****CodebehindIISASP.NET RuntimeInstantiate controlsParse .aspx fileGenerate page classRequest .aspx fileResponseClientServer**Compile khi trang được request lần đầu tiênMS intermediate language (MSIL)Dạng ngôn ngữ trừu tượngĐộc lập CPUMSIL được thực thi bởi CLRCommon Language RuntimeJust-in-Time compilerManaged code**Kết quả của quá trình biên dịch là file *.exe/*.dllMột hoặc nhiều assembliesAssembly 1MyApp.dllpic1.jpgmetadata**Application StateWhat is an “application”?Files, pages, modules, and executable codeOne virtual directory and its subdirectoriesApplication state variablesGlobal informationImplementation rulesUse of system resources“Lock” and “unlock” your global informationBeware of global variables in multithreaded environmentsLoss of state when host is “destroyed”No state sharing across Web farms**Session StateWhat is a session?Restricted to a logical applicationContext in which a user communicates with a serverFunctionalityRequest identification and classificationStore data across multiple requestsSession eventsRelease of session data.NET State Server Process**Reasons for SecurityPrevent access to areas of your Web serverRecord and store secure relevant user dataSecurity Configuration in Web.Config, , , ...Authentication, Authorization, ImpersonationCode Access SecurityAre you the code you told me you are?Protect your server from bad code**AuthenticationValidates user credentialsAwards an authenticated identityTypes of authenticationWindows, integrating with IIS 5.0Passport, centralized services provided by MicrosoftForms, request attachmentAuthorizationDetermine whether request is permittedFile and URL authorization**ImpersonationIIS authenticates the “user”A token is passed to the ASP.NET applicationASP.NET impersonates the given tokenAccess is permitted according to NTFS settingsCode Access Security.NET Framework featureVerify the code‘s identity and where it comes fromSpecify operations the code is allowed to perform**Application-level Event HandlingWeb FormsDelegate ModelConnect event sender and event receiverSingle and multicast delegatesEvent Delegates Are MulticastEvent WiringRegister event handler with event sender**Events raised on client, but handled on serverServerWeb Clientparse messageeventevent handlereventmessageresponsecall appropriate event handler**Giải quyết được các hạn chế của ASPEnhanced performancePower and flexibilitySimplicityManageabilityScalability and availabilityCustomizability and extensibilityReliabilitySecurity**Make it easier to build web appsMake it easier to deploy web appsMake it easier to operate web appsProvide greater performance, reliability, and scalability**
Tài liệu liên quan