Thứ Sáu, 12 tháng 11, 2010

Thực hành : ASP.NET MVC Forms Authentication With SqlMembershipProvider

Tiếp tục trong loạt bài : Kỹ thuật cho KaizenCMS, trong bài này tôi sẽ giải thích một số kỹ thuật liên quan đến việc sử dụng SqlMembershipProvider xây dựng cơ chế xác thực và bảo mật ứng dụng.


The ASP.NET MVC Website Template comes pre-configured to use SqlMembershipProvider which manages storage of membership information for an ASP.NET application in a SQL Server database.
But before you can use this properly you will need to setup your database, which will be very easy because Microsoft shipped .NET 2.0 with a nice utility to do it! You can find this on your computer, at this path C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe
1
Your database should have these tables:
2
Now lets tell our ASP.NET MVC Website’s configuration where to find this database. Open the web.config and change the ApplicationServices connection string to point to your SQL Server. You should now rebuild your solution to avoid any problems in the next step!
  1. <connectionStrings>  
  2.     <add name="ApplicationServices"  
  3.          connectionString="Data Source=localhost;  
  4.                            Initial Catalog=database;  
  5.                            Persist Security Info=True;  
  6.                            User ID=user;  
  7.                            Password=password"  
  8.          providerName="System.Data.SqlClient"  
  9.     />  
  10. </connectionStrings>  
It’s all good and nice but now we need Users in this database otherwise it’s completly useless! So open up your ASP.NET MVC Solution in Visual Studio and go to Project » ASP.NET Configuration. This will open the ASP.NET Web Application Administration website. In the Security tab you can Add/Manage Users and Roles. For the moment, add a user so we can try the login. I’ve added userMike.
3
You can now run your application and click on [ Log On ] at the top right corner of the page, this will redirect you the the logon form.
4
If you entered the correct credential you should be redirected to the home page of the site and you will see your name and a Log Off button instead of the Log On button.
5
Well congraticulations! You now have SqlMembershipProvider working on your website, wasn’t so hard, was it? Not  ingle line of code required! I’ll be posting again soon to show you how to use Roles in your applications

Tham khảo : http://helios.ca/2009/04/22/aspnet-mvc-sqlmembershipprovider/


Một số hàm thường dùng trong ASP Membership Provider

Tóm lượt từ các tutorial tại www.asp.net
Create User:
link gốc : http://www.asp.net/learn/security/tutorial-05-cs.aspx
MembershipCreateStatus createStatus;
MembershipUser newUser = Membership.CreateUser(Username.Text, Password.Text, Email.Text, passwordQuestion, SecurityAnswer.Text, true, out createStatus);
kiểm tra quá trình create user bằng creatStatus.
Kiểm tra quyền của user:
link : http://www.asp.net/learn/security/tutorial-08-cs.aspx
Get a reference to the currently logged on user
MembershipUser currentUser = Membership.GetUser();
Determine the currently logged on user's UserId value
Guid currentUserId = (Guid)currentUser.ProviderUserKey;
Kiểm tra Role của user hiện tại:
bool allow = (currentUser.IsInRole("Role cần kiểm tra"))
Tạm thời copy 2 em thường dùng nhưng cũng thường quên nhất :(

Tinh lua duyen trang. Quang Le _ Ngoc Ha

Thứ Ba, 9 tháng 11, 2010

Tasks

Dưới đây là các tính năng dự kiến của KaizenCMS

1. Hiển thị tài liệu theo định dạng chuẩn html
Với tính năng này, chúng ta hoàn toàn có thể soạn bài viết dưới các định dạng tài liệu khác như Word. Excel, ... Sau đó kết xuất các file này dưới dạng Html, đưa vào (upload) lên KaizenCMS và có thể hiển thị một cách bình thường, định dạng đẹp, chuẩn, bạn tự do sáng tạo cho định dạng tài liệu này.

Đặc tính kỹ thuật :
- Sử dụng IFrame cho lớp View
- Sử dụng một số JavaScript để biên dịch tài liệu

Tham khảo :
http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/worddocumentinaspnetmvc07222009071101AM/worddocumentinaspnetmvc.aspx

2. Upload tài liệu
Tính năng này là cần thiết cho KaizenCMS để nạp bài viết mới cho KaizenCMS. Tuy nhiên hiện tại tính năng này chưa hoàn chỉnh theo nghĩa :

- Cần có một database quản lý các file upload lên và có nguyên tắc ánh xạ để quản lý các file này

Đặc tính kỹ thuật :
- Sử dụng Ajax

Cơ sở dữ liệu

Bảng Object
- Id
- Name : Tên object
- Description  : Mô tả về object, có thể là lời nói đầu của KaizenCMS về tài liệu được đưa lên
- Path : Đường dẫn (địa chỉ) lưu object
- Views : Số lần xem
- Uploader : Người cập nhật, lấy họ tên của user name
- Authors : Tác giả (nếu có)


Tham khảo :
http://www.codeproject.com/KB/aspnet/ASPNetMVCDemo.aspx

3. Tích hợp http://ckeditor.com/
Tôi dự kiến sẽ tích hợp CKeditor để sử dụng cho phần description và comments cho các bài viết. Và sẽ hiển thị đầy đủ, đúng định dạng của các bài viết, comment này lên website.