cấu hình email cho graffiti cms

by Neon Quach 29. April 2010 20:26

Graffiti CMS cung cấp cho chúng ta 1 cách linh động trong việc thiết lập cấu hình email, cho việc gửi email mổi khi có bài viết mới, 1 entry mới được thêm hoặc 1 lời bình luận mới được thêm vào, để cấu hình email, chúng ta login vào admin → Site Options → Email Settings và fill form như hình bên dưới.


Ở đây mình dùng tài khoản gmail, bạn cũng có thể cấu hình với email server khác, để test cấu hình của bạn có đúng hay chưa? các bạn có thể điền email account trong phần Test your settings, và nhấn vào nút Send email.

Nếu chúng ta nhận được email của graffiti test email có nội dung:

This email was sent to test your email settings configured in Graffiti. If you are seeing this message, your settings worked!

Graffiti Admin


Thì những setting của các bạn đã hoạt động. → Update Settings

Hope this help!

Tags: , , ,


Categories: asp.net | open source | graffiticms

khắc phục lổi potentially dangerous message trong blogengine

by Neon Quach 27. April 2010 03:26

khi approve bài viết trong blogengine nếu bài viết chứa các ký tự đặc biệt hoặc chứa ký tự html giống như:



Chúng ta sẻ gặp lổi sau và không thể approve bài viết được.



Lý do chúng ta submit form mà chứa các ký tự đặc biệt, để khắc phục trường hợp này trước khi submit, chúng ta phải encode các ký tự này trong textarea đi bằng cách thêm dòng

txtArea.Value = HttpUtility.HtmlEncode(_comment.Content);


Trong sự kiện page load của admin\Comments\Editor.aspx.cs thì chúng ta sẻ không thấy lổi này nửa.

Hope this help,

Tags: , ,


Categories: asp.net | blogengine | c#

nên Disposable SmtpClient object khi sử dụng .net 4.0

by Neon Quach 24. April 2010 21:52

Mặc định trình "thu lụm rác" (Garbage Collection) trong Visual studio sẻ tự động hủy object, sau khi nó không còn được reference nửa, nếu muốn tự tay mình disposable object sau khi object đó ra khỏi phạm vi sử lý nửa thì thường chúng ta wrap chúng trong using statement like:

using(object obj = new object())
{
.......
}


Trong version 3.5 trước của Net framework, khi chúng ta sử dụng object SmtpClient thì object này không inherit từ IDisposable nên chúng ta không thể bọc object trong using statement được. Nhưng đối với .net 4.0 thì chúng ta có thể làm được điều đó.

   
public string SendMail(string subject, string body, string to, bool isHtml, bool isSSL)
    {
        try
        {
            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(FormAddress, "code2code.info");
                mail.To.Add(to);
                mail.Subject = subject;
                mail.Body = body;
                mail.IsBodyHtml = isHtml;
                using (SmtpClient client = new SmtpClient())
                {
                    client.EnableSsl = isSSL;
                    if (FileUpload1.HasFile)
                    {
                        mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
                    }
                    client.Send(mail);
                }
            }
        }
        catch (SmtpException ex)
        {
            return ex.Message;
        }
        return "Send email successful!";
    }


Nếu chúng ta build với StyleCop enable thì sẻ cảnh báo message này:

Warning    20    CA2000 : Microsoft.Reliability : In method 'TestEmail.btnSendTest_Click(object, EventArgs)', call System.IDisposable.Dispose on object 'new SmtpClient()' before all references to it are out of scope.

Note: việc quản lý object bằng cách hủy chúng đi khi không còn reference nửa, rất quan trọng trong vấn đề cải thiện tốc độ cho ứng dụng, chúng ta nên warp tất cả các đối tượng nào kế thừa từ IDisposable.

Hope this help.

Tags: , , ,


Categories: asp.net | visual studio 2010 | visual studio tips | c#

hướng dẫn cài graffiti cms trên localhost

by Neon Quach 24. April 2010 21:01

Graffiti CMS là phần mềm mã nguồn mở viết bằng asp.net C#, được phát triển bởi Telligent, trước đây chúng ta đã biết đến Community Server cũng của cty này, Graffiti giúp chúng ta dễ dàng xuất bản (publish), cũng như dễ dàng quản lý, chỉnh sửa nội dung của bài viết 1 cách dễ dàng và nhanh chóng mà không cần đến kiến thức về lập trình.
Trong bài này mình sẻ huớng dẫn mọi người cách cài đặt Graffiti trên localhost.

Các bước thực hiện:
1. Cài đặt và tải mã nguồn Graffiti.
2. Tạo CSDL, thêm lược đồ (schema) và data cho csdl.
3. Cấu hình chuổi kết nối (connection string).
4. Cài đặt theme cho Graffiti.
5. Thêm mới 1 bài viết và tạo danh mục (catagory)

Let's started!
1. Cài đặt và tải mã nguồn Graffiti.
Trước khi cài đặt Graffiti, máy của chúng ta phải cần có Visual Studio (optinal) và sql server, version mình đang sài là VS2010 và sql2008, nhưng version củ hơn cũng có thể làm được. Download Graffiti tại http://graffiticms.codeplex.com/.

Download the source http://graffiticms.codeplex.com/SourceControl/ListDownloadableCommits.aspx
Download binary: http://graffiticms.com/lib/lib.zip
Giả nén source code, tiếp sau đó giả nén lib.zip và copy toàn bộ *.dll và bỏ vào thư mục \Branches\v1.3\src\Lib.

2. Tạo CSDL, thêm lược đồ (schema) và data cho csdl.
Mặc dù Graffiti support nhiều loại csdl nhưng trong bài này mình sẻ sử dụng csdl sql: Open Sql server và tạo csdl tên là Graffiti, sau đó tiến hành setup schema bằng cách run Branches\v1.3\data\Graffiti_SQL_Schema.sql, tiếp tục cài data Branches\v1.3\data\Graffiti_SQL_Data.sql

Begin inserting data in graffiti_Categories
(1 row(s) affected)
Begin inserting data in graffiti_Comments
Begin inserting data in graffiti_Logs
Begin inserting data in graffiti_ObjectStore
(1 row(s) affected)

3. Cấu hình chuổi kết nối (connection string).
Double click vào Graffiti.sln -> open web.config (có thể dùng notepad...) tìm đến dòng <add name="Graffiti" connectionString="...."
và sửa chúng thành

<add name="Graffiti" connectionString="Data Source=.\sqlexpress;Initial Catalog=Graffiti;Persist Security Info=True;User ID=sa;Password=111111"/>

Run trang default, Graffiti sẻ open màng hình config đầu tiên như hình sau:

graffiti config

Sau khi save xong Graffiti sẻ redirect chúng ta vào phần admin.

graffiti admin section

4. Cài đặt theme cho Graffiti.
Graffiti release với theme mặc định, để thay đổi theme, chúng ta tiến hành download tại http://ooto.info/files/uploads/freshG1.0.zip và giải nén chúng ta có 1 file freshG1.0.xml, đừng quan tâm đến filename, chúng ta sẻ import chúng vào.

Từ admin, chúng ta navigate đến Presentation → Themes
Upload Theme chọn file freshG1.0.xml vừa unrar.

graffiti theme

5. Thêm mới 1 bài viết và tạo danh mục (catagory)
Để tạo 1 bài viết mới chúng ta click chọn Write và nhập tiêu đề, nội dung, và tạo danh  mục mới nếu muốn.

graffiti new article

Tóm lại: Graffiti là phần mềm CMS mã mở, giúp chúng ta xây dựng và publish nội dung động, có thể mở rộng bằng các plug-in,widget, extension... 1 phần mềm tuyệt vời, đơn giản, và dễ sử dụng.

Tags: , , , ,


Categories: asp.net | open source | c# | graffiticms

asp.net/html spell checker for vs 2008 sp1

by Neon Quach 10. April 2010 15:09

Check your spelling inside visual studio

  • Created by: Mikhail Arkhipov (Microsoft)
  • Rating: (0)
  • Downloads: 497
  • Last Updated: Tuesday, March 30, 2010
  • Version: 2.3.1
  • Supported Versions Visual Studio 2008

Download

Tags: , ,


Categories: asp.net | visual studio add-in

send email với attachment

by Neon Quach 9. April 2010 02:42

Ở bài viết trước Gửi Email động trong ASP.NET chúng ta đả được làm quen với đối tượng MailMessage và 1 số thuộc tính quan trong của nó trong việc gửi email.

Giờ chúng ta sẻ làm quen với việc làm thế nào để đính kèm tập tin khi send mail.

Tại source code tại: http://code2code.info/post/send-dynamic-email-in-aspnet.aspx và thêm mới 1 section bao gồm 1 nhãn named là Đính kèm và 1 FileUpload control.

            <tr>

                <td>Đính kèm:</td>

                <td>

                    <asp:FileUpload ID="FileUpload1" runat="server" Width="250px" />

                </td>

            </tr>
Chỉnh sửa 1 tí về cấu hình smtp, mình sẻ send mail dùng stmp của google, vì có rất nhiều bạn send mail và message cho mình nhờ giúp đở về việc send email sử dụng mail server của google.

  <system.net>

    <mailSettings>

      <smtp>

        <network host="smtp.gmail.com" port="587" userName="quachngochoangnguyen@gmail.com" password="your password"/>

      </smtp>

    </mailSettings>

  </system.net>

Ở đây mình cũng sẻ nói thêm luôn là nếu send mail thông qua mail server của google thì chúng ta sẻ phải enable SSL của đối tượng SmtpClient.

Chúng ta sẻ chỉnh sửa hàm SendMail để nhận đính kèm:

C#:
                if (FileUpload1.HasFile)

                {

                    mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));

                }

                client.Send(mail);
VB:
                client.EnableSsl = isSSL

                If FileUpload1.HasFile Then

                    mail.Attachments.Add(New Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName))

                End If

                client.Send(mail)
Constructor của Attachment nhận vào 2 tham số bao gồm: nội dụng dạng Stream của file, và tên file, Press F5 lên và tiến hành send mail có đính kèm:



và kết quả:


Hope this help
Check out my code:http://code2code.googlecode.com/svn/trunk/SendingDynamicEmailWithAttachment

SendingDynamicEmailWithAttachment.rar (8.38 kb)

Tags: , ,


Categories: asp.net | net framework | c#

asp.net role membership provider phần 2

by Neon Quach 7. April 2010 02:34

Đây là bài viết nằm trong tập bài viết về asp.net role membership.
asp.net role membership provider phần 1

Trong phần 1 chúng ta đả làm quen với việc tạo asp.net membership database, trong phần 2 này chúng ta sẻ bắt đầu việc tạo user, login, logout và display user sau khi login thành công.

Vì do chúng ta đả tạo membership database trước nên bước đầu tiên chúng ta phải cấu hình connection string và membership.

  <connectionStrings>

    <add name="aspnetdbcon" connectionString="Data Source=localhost\sqlexpress;Initial Catalog=aspnetdb;uid=sa;pwd=111111"/>

  </connectionStrings>

Cấu hình chế độ chứng thực:

    <authentication mode="Forms">

      <forms loginUrl="~/login.aspx" timeout="2880"/>

    </authentication>

Config membership:

    <membership>

      <providers>

        <clear/>

        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="aspnetdbcon" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/"/>

      </providers>

    </membership>

Trong đó:

connectionStringName: tên của connection string (string)

enablePasswordRetrieval: Có hổ trợ chức năng nhận lại password (true/false)
enablePasswordReset: Cho phép reset password (true/false)
requiresQuestionAndAnswer: Có buộc nhập câu hỏi và câu trả lời bảo mật hay không
requiresUniqueEmail: Có bắt buộc 1 địa chỉ email cho 1 user hay không?
passwordFormat: Định dạng của password (Hashed, SHA1, Clear)
maxInvalidPasswordAttempts: Số lượng cho phép nhập sai password, ví dụ = 5, thì sau 5 lần đăng nhập thất bại, user phải đợi tới 15’ sau mới có thể đăng nhập lại.
minRequiredPasswordLength: Số lượng tối đa của mật khẩu

minRequiredNonalphanumericCharacters: Số lượng ký tự đặc biệt cho phép.
passwordAttemptWindow: Mặc định là 10’ là khoảng cách giửa lần đăng nhập thất bại đầu tiên và lần cuối cùng, nếu lớn hơn 10’ thì user sẻ bị log.
passwordStrengthRegularExpression: Expression cho password.
applicationName: Tên của ứng dụng (default là root /)


Bắt đầu tạo user

Từ version 2.0 trở đi thì ASP.NET cung cấp 1 số control cho việc tạo user, đăng nhập, quên mật khẩu, thay đổi mật khẩu (Create User Wizard, Login, ChangePassword…)

Để cho phép tạo mới user, chúng ta add 1 page mới và đặt tên là createuser.aspx và kéo control CreateUserWizard vào set thuộc tính ContinueDestinationPageUrl="~/login.aspx"

        <asp:CreateUserWizard ID="CreateUserWizard1" runat="server"

 

            ContinueDestinationPageUrl="~/login.aspx">

            <WizardSteps>

                <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">

                </asp:CreateUserWizardStep>

                <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">

                </asp:CompleteWizardStep>

            </WizardSteps>

        </asp:CreateUserWizard>

Ở màng hình create user wizard, chúng ta không thấy textbox nhập câu hỏi bảo mật và câu trả vì trong file web.config chúng ta không enable nó requiresQuestionAndAnswer="false". Sau khi create user xong chúng ta nhấn Continue chúng ta sẻ được chuyển sang trang login, nơi mà ta sẻ thực thi chức năng đăng nhập.

Tạo trang login.aspx và kéo Login control, ở đây tình huống là khi user chưa đăng nhập thì chúng ta hiển thị login control, ngược lại nếu user đả đăng nhập rồi và quay lại trang login thì chúng ta hiển thị message welcome + name chẳng hạn.

Chúng ta có thể để dàng làm được nhờ vào LoginView control, Click vào smart tag của LoginView chúng ta có thể thấy 2 template: AnonymousTemplate và  LoggedInTemplate.

 


Ở mode AnonymousTemplate chúng ta thêm Login control và ở mode LoggedInTemplate chúng ta thêm loginstatus và loginname, loginstatus là control sẻ hiển thị trạng thái của user đả login hay chưa, nếu login rồi thì nó sẻ hiển thị logout, và ngược lại, còn loginname nó sẻ hiển thị tên của user hiện tại login.

History version: 2010-04-07 02:34 first release

Tags: , , , ,


Categories: asp.net | net framework | open source | vs .net

comment your html code nên và tránh

by Neon Quach 6. April 2010 05:35

Bạn có thể dùng để commment your html code, nhưng chúng ta có 1 option khác để comment html code của chúng ta bằng <%-- --%> thay vì , bởi vì vẫn được render và send to client, chính vì thế khiến cho page của chúng ta load chậm. Để tránh điều đó chúng ta có thể thay thế tất cả comment html code → comment dạng server code like <%-- --%>.


Trong Visual Studio để thay thế tất cả các comment, chúng ta có thể làm được nhờ vào hộp thoại Find & Replace

Nhấn Ctrl + H để open hộp thoại Find & Replace → \<!--{[^-]*}--\> và pattern thay thế là <%--\1--%>

Reference

Tags: ,


Categories: asp.net | visual studio tips

Đưa ứng dụng web asp.net lên host.

by Neon Quach 30. March 2010 12:00

Sau khi phát triển web app xong, giai đọan cuối cùng là đưa web lên host (go live), mình sẻ hướng dẫn các bạn cách đưa ứng dụng go live mà dùng tiện ích có sẳn của Visual Studio(VS).

Cái quan trọng là mình phải purchase 1 cái host support asp.net, ở đây mình sài free host của godaddy.com (mình mua 1 domain .info có sẳn free host), mình sẻ tạo 1 web app simply (like hello world), giờ đưa nó go live bằng cách.

Từ solution của VS nhấn vào Coppy Website, hoặc vào Menu Website -> Copy Web Site....

VS sẻ đưa ta đến màng hình sau:

Sau đó chúng ta nhấn vào Conect, chúng ta chọn FTP site và điền thông tin FTP account vào like this.

Ok nếu thành công chúng ta sẻ có màng hình như sau: 1 bên là local (bên trái) và 1 bên phải là remote site (bên phải).



Sau đó mình copy entire các files và folder từ local lên web host.

Xong giờ view web page

Tags:


Categories: asp.net | vs .net

Employee Info Starter Kit v4.0.0

by Neon Quach 27. March 2010 16:35

Employee Info Starter Kit is a ASP.NET based web application, which includes very simple user requirements, where we can create, read, update and delete (crud) the employee info of a company. Based on just a database table, it explores and solves most of the major problems in web development architectural space. 

This open source starter kit extensively uses major features available in latest Visual Studio, ASP.NET and Sql Server to make robust, scalable, secured and maintainable web applications quickly and easily.

Since it's first release, this starter kit achieved a huge popularity in web developer community and includes 1,50,000+ downloads from project web site.

Visual Studio 2010 and .NET 4.0 came up with lots of exciting features to make software developers life easier.  A new version (v4.0.0) of Employee Info Starter Kit is now available in both MSDN Code Gallery and CodePlex. Checkout the latest version of this starter kit to enjoy cool features available in Visual Studio 2010 and .NET 4.0.


[ Release Notes ]

Architectural Overview

  • Simple 2 layer architecture (user interface and data access layer) with 1 optional cache layer
  • ASP.NET Web Form based user interface
  • Custom Entity Data Container implemented (with primitive C# types for data fields)
  • Active Record Design Pattern based Data Access Layer, implemented in C# and Entity Framework 4.0
  • Sql Server Stored Procedure to perform actual CRUD operation
  • Standard infrastructure (architecture, helper utility) for automated integration (bottom up manner) and unit testing

Technology Utilized

Programming Languages/Scripts

  • Browser side: JavaScript
  • Web server side: C# 4.0
  • Database server side: T-SQL

.NET Framework Components

  • .NET 4.0 Entity Framework
  • .NET 4.0 Optional/Named Parameters
  • .NET 4.0 Tuple
  • .NET 3.0+ Extension Method
  • .NET 3.0+ Lambda Expressions
  • .NET 3.0+ Anonymous Type
  • .NET 3.0+ Query Expressions
  • .NET 3.0+ Automatically Implemented Properties
  • .NET 3.0+ LINQ
  • .NET 2.0 + Partial Classes
  • .NET 2.0+ Generic Type
  • .NET 2.0+ Nullable Type
  • ASP.NET 3.5+ List View (TBD)
  • ASP.NET 3.5+ Data Pager (TBD)
  • ASP.NET 2.0+ Grid View
  • ASP.NET 2.0+ Form View
  • ASP.NET 2.0+ Skin
  • ASP.NET 2.0+ Theme
  • ASP.NET 2.0+ Master Page
  • ASP.NET 2.0+ Object Data Source
  • ASP.NET 1.0+ Role Based Security

Visual Studio Features

  • Visual Studio 2010 CodedUI Test
  • Visual Studio 2010 Layer Diagram
  • Visual Studio 2010 Sequence Diagram
  • Visual Studio 2010 Directed Graph
  • Visual Studio 2005+ Database Unit Test
  • Visual Studio 2005+ Unit Test
  • Visual Studio 2005+ Web Test
  • Visual Studio 2005+ Load Test

Sql Server Features

  • Sql Server 2005 Stored Procedure
  • Sql Server 2005 Xml type
  • Sql Server 2005 Paging support

Reference

Tags: , , ,


Categories: net framework | asp.net | vs .net | vb.net | visual studio 2010

Powered by BlogEngine.NET 1.6.0.0 - Eco Theme by n3o Web Designers