tailieunhanh - Building Secure ASP.NET Applications phần 8

Thủ tục này thực hiện một ứng dụng xử lý sự kiện xác thực và xây dựng GenericPrincipal và các đối tượng FormsIdentity dựa trên thông tin chứa trong vé xác thực. Để xây dựng GenericPrincipal và các đối tượng FormsIdentity 1. Giải pháp Explorer, mở . 2. Chuyển sang chế độ code và thêm bằng cách sử dụng báo cáo sau đây để đầu của tập tin: | 382 Building Secure Applications 4. Construct GenericPrincipal and FormsIdentity Objects This procedure implements an application authentication event handler and constructs GenericPrincipal and FormsIdentity objects based on information contained within the authentication ticket. To construct GenericPrincipal and FormsIdentity objects 1. From Solution Explorer open . 2. Switch to code view and add the following using statements to the top of the file using using 3. Locate the Application_AuthenticateRequest event handler and add the following code to obtain the forms authentication cookie from the cookie collection passed with the request. Extract the forms authentication cookie string cookieName HttpCookie authCookie cookieName if null authCookie There is no authentication cookie. return 4. Add the following code to extract and decrypt the authentication ticket from the forms authentication cookie. FormsAuthenticationTicket authTicket null try authTicket catch Exception ex Log exception details omitted for simplicity return if null authTicket Cookie failed to decrypt. return How To Create GenericPrincipal Objects with Forms Authentication 383 5. Add the following code to parse out the pipe separate list of role names attached to the ticket when the user was originally authenticated. When the ticket was created the UserData property was assigned a pipe delimited string of role names. string roles new char 6. Add the following code to create a FormsIdentity object with the user name obtained from the ticket name and a GenericPrincipal object that contains this identity together with the user s role list. Create an Identity object FormsIdentity id new FormsIdentity authTicket This principal will flow throughout the request. GenericPrincipal principal new GenericPrincipal id

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.