Sunday, April 26, 2015
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that ...
0 comments Posted by Duc Nguyen at 7:57 PM
Validation of viewstate MAC failed. If this application is hosted
by a Web Farm or cluster, ensure that configuration
specifies the same validationKey and validation algorithm. AutoGenerate
cannot be used in a cluster.
Hầu hết các website bằng asp.net thường mắc lỗi. Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
Khi ta chạy website viết bằng ASP.NET trên web-hosting mà có nhiều website cùng chạy, mỗi khi ta cập nhật thư viện, assembly, mã nguồn mới (các file cs), khi đó nếu người dùng submit lên từ một trang được sinh ra từ code cũ có thể sẽ gặp phải lỗi “Validation of viewstate MAC failed”. Trong bài viết này tôi sẽ hướng dẫn cách khắc phục triệt để lỗi trên.
Cách giải quyết thứ nhất:
Thêm đoạn cấu hình sau vào trong thẻ trong file web.config
Sunday, March 1, 2015
Username Availability Check in ASP.NET Web Forms with jQuery Validation Plugin
0 comments Posted by Duc Nguyen at 6:58 PM<
form
id
=
"form1"
runat
=
"server"
>
<
fieldset
>
<
legend
>Register</
legend
>
<
p
>
<
asp:Label
ID
=
"UserNameLabel"
runat
=
"server"
AssociatedControlID
=
"UserName"
>User Name:</
asp:Label
>
<
asp:TextBox
ID
=
"UserName"
runat
=
"server"
ClientIDMode
=
"Static"
></
asp:TextBox
>
</
p
>
<
p
>
<
asp:Label
ID
=
"PasswordLabel"
runat
=
"server"
AssociatedControlID
=
"Password"
>Password:</
asp:Label
>
<
asp:TextBox
ID
=
"Password"
runat
=
"server"
TextMode
=
"Password"
ClientIDMode
=
"Static"
></
asp:TextBox
>
</
p
>
<
p
>
<
asp:Label
ID
=
"ConfirmPasswordLabel"
runat
=
"server"
AssociatedControlID
=
"ConfirmPassword"
>Confirm Password:</
asp:Label
>
<
asp:TextBox
ID
=
"ConfirmPassword"
runat
=
"server"
TextMode
=
"Password"
ClientIDMode
=
"Static"
></
asp:TextBox
>
</
p
>
<
p
>
<
asp:Button
ID
=
"Button"
runat
=
"server"
Text
=
"Sign Up"
/>
</
p
>
</
fieldset
>
</
form
>
CSS:
<
style
type
=
"text/css"
>
label
{
display:block;
}
input.error
{
border: solid 2px #CC0000;
}
input.valid
{
border: solid 2px green;
}
span
{
margin-left:5px;
}
span.valid
{
width:16px;
height:16px;
color: green;
background:url("http://cdn1.iconfinder.com/data/icons/basicset/tick_16.png") left center no-repeat;
display:inline-block;
}
span.error
{
width: 100%;
color: red;
}
</
style
>
jQuery Validation:
For simplicity, I am using jquery validation plugin from cdn.< script src = "http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js" ></ script > < script src = "http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js" type = "text/javascript" ></ script > |
$( "#<%=form1.ClientID%>" ).validate({ errorElement: 'span' , rules: { UserName: { required: true , remote: function () { return { url: "/Default.aspx/IsUserNameAvailable" , type: "POST" , contentType: "application/json; charset=utf-8" , dataType: "json" , data: JSON.stringify({ userName: $( '#UserName' ).val() }), dataFilter: function (data) { var msg = JSON.parse(data); if (msg.hasOwnProperty( 'd' )) return msg.d; else return msg; } } }, }, Password: { required: true , minlength: 8, }, ConfirmPassword: { required: true , minlength: 8, equalTo: "#Password" } }, messages: { UserName: { required: "User name is Required" , remote: "This user name is already in use" , }, Password: { required: "Password is Required" , minlength: "Password requires at least 8 characters" , }, ConfirmPassword: { required: "Confirm password is Required" , minlength: "Confirm password requires at least 8 characters" , equalTo: "Confirm password must match the Password" , } }, onkeyup: false , onblur: true , onfocusout: function (element) { $(element).valid() } }); |
highlight:
function
(element, errorClass, validClass) {
$(element).parent().find(
'span'
).remove();
$(element).addClass(errorClass).removeClass(validClass);
},
unhighlight:
function
(element, errorClass) {
$(element).removeClass(errorClass);
},
success:
function
(label) {
var
$label = $(label);
$(label).nextAll().remove();
if
(!$label.hasClass(
'valid'
)) {
$label.addClass(
'valid'
);
}
$label.removeClass(
'error'
);
}
Tuesday, January 13, 2015
Download and install Microsoft SQL Server 2008 R2 Express
0 comments Posted by Duc Nguyen at 1:35 AMIntroduction
Instructions
- Download Microsoft SQL Server 2008 R2 Express. There are 32-bit (x86, file name SQLEXPRWT_x86_ENU.exe) and 64-bit (x64, file name SQLEXPRWT_x64_ENU.exe) versions available for download. If you are unsure if your operating system is 64-bit, download the 32-bit version:
• Microsoft SQL Server 2008 R2 Express 32-bit (x86)
- or -
• Microsoft SQL Server 2008 R2 Express 64-bit (x64)
This download also includes basic management tools for the database server.
Important: You may have to install Microsoft .Net Framework 3.5 SP1, Windows Installer 4.5 and Windows PowerShell 1.0 before installing Microsoft SQL Server 2008 R2 (typically required for Windows XP and Windows Server 2003).- Open the downloaded file (SQLEXPRWT_x86_ENU.exe or SQLEXPRWT_x64_ENU.exe) to start the SQL Server Installation Center.
- Click on New installation or add features to an existing installation.
- Follow the installation wizard.
- When prompted for the Instance Configuration, select Default instance.
- Follow the installation wizard.
- When prompted for the Database Engine Configuration, it is recommended that you select Mixed Mode (SQL Server authentication and Windows authentication) and provide a strong password.
- Follow the installation wizard and wait until the installation is complete.
- Go to Start > All Programs > Microsoft SQL Server 2008 R2 > Configuration Tools > SQL Server Configuration Manager.
- Open the node SQL Server Network Configuration and select Protocols for MSSQLSERVER.
- Double-click on TCP/IP.
- Set Enabled to Yes.
- Click on OK.
- Close the SQL Server Configuration Manager.
- Restart the computer or the SQL Server service.
Monday, November 17, 2014
How can we get SMTP to work on Windows 7 (Development Environment) as
we used to just be able to turn it on for a windows XP box.
SMTP isn't included in Windows 7 by default. But you can install Remote Server Administration Tools
that includes SMTP Server Tools for Windows 7. It enables IT
administrators to manage roles and features that are installed on remote
computers that are running Windows Server 2008 R2 but it can be installed ONLY on computers that are running the Enterprise, Professional, or Ultimate editions of Windows 7.
First install Remote Server Administration Tools, and then upgrade to Service Pack 1 as it CANNOT BE INSTALLED on computers that are running Windows 7 with Service Pack 1 (SP1).
Download http://www.microsoft.com/downloads/details.aspx?FamilyID=7d2f6ad7-656b-4313-a005-4e344e43997d
For configuring SMTP E-mail IIS 7, please refer to: Configure SMTP E-mail (IIS 7)
Monday, July 28, 2014
MỌI NGƯỜI CÙNG ĐỌC VÀ SUY NGẪM.
1.Trong vụ cướp nhà băng
được cho là ở Cộng hòa Nhân dân Trung Hoa, một tên cướp hét lên: "Tất
cả đứng im, nên nhớ tiền thuộc về Nhà nước, còn mạng sống thuộc về chúng
mày!"
Mọi người trong ngân hàng nghe xong liền im lặng nằm xuống.
2.Có cô nhân viên nằm trên bàn trong tư thế khêu gợi, một tên cướp hét lên: "Làm ơn cư xử văn minh, chúng tôi là cướp chứ không phải những kẻ hiếp dâm!"
> Điều này được gọi là "Hành xử chuyên nghiệp - Chỉ tập trung vào công việc mà bạn được huấn luyện!"
3.Khi tên cướp quay lại, một tên cướp trẻ hơn (có bằng MBA) nói với tên cướp già hơn (kẻ mới tốt nghiệp hết phổ thông): "Đại ca, có phải đếm xem chúng ta cướp được bao nhiêu?". Tên cướp già gằn giọng: "Mày ngu lắm, bao nhiêu tiền, đếm thế nào được? Đợi đi, tối nay TV sẽ nói chúng ta cướp được bao nhiêu!"
> Điều này được gọi là: "Kinh nghiệm - Ngày nay thì kinh nghiệm quan trọng hơn giấy tờ, sách vở"
4.Sau khi băng cướp rời khỏi, giám đốc chi nhánh định gọi báo cảnh sát. Kế toán trưởng vội vã chạy đến, thì thầm vào tai ngài: "Đợi đã, hay để 5 triệu chúng ta biển thủ vào trong số bị băng cướp lấy mất!"
> Điều này được gọi là: "Bơi theo dòng nước - Chuyển đổi những tình huống bất lợi trở thành thuận lợi"
5.Người giám đốc tự nhủ: "Vậy thật tuyệt nếu cứ mỗi tháng lại có một vụ cướp!"
> Điều này được gọi là: "Hãy loại bỏ những điều khó chịu - Hạnh phúc là điều quan trọng nhất"
6.Ngày hôm sau, TV đưa tin 100 triệu đã bị cướp khỏi nhà băng. Những tên cướp đếm đi đếm lại thì chỉ có 20 triệu. Chúng rất giận dữ: "Chúng ta mạo hiểm mạng sống của mình chỉ để lấy 20 triệu, bọn chó lãnh đạo chỉ ngồi chơi mà cướp được 80 triệu. Đúng là học hành, có bằng cấp thì chúng nó được ngồi cái ghế đấy, cướp tiền siêu đẳng hơn chúng ta!"
> Điều này giải thích tại sao: "Kiến thức thì giá trị như vàng"
KẾT LUẬN: Trong cuộc sống luôn có những điều chúng ta có thể nhanh chóng nhìn ra, có những điều không như chúng ta thấy từ bên ngoài, và chân lý chỉ mang tính tương đối.
Quan trọng nhất là thái độ đối với cuộc sống này, hay cách nhìn chúng ta lựa chọn để mang lại vui vẻ, hạnh phúc cho bản thân, cho những người thân xung quanh mình.
Friday, July 18, 2014
A potentially dangerous Request.Form value was detected from the client,
0 comments Posted by Duc Nguyen at 1:02 AM ...
When you are sure you HTML-encode everywhere you pass strings to HTML, then set validateRequest="false"
.
In .NET 4 you may need to do a little more. Sometimes it's necessary to also add
to web.config
Wednesday, May 28, 2014
how to detect which social networks your visitors are logged into.
0 comments Posted by Duc Nguyen at 8:37 PMPlease see this link:
Social Network Login Status Detector Demo:
http://www.tomanthony.co.uk/tools/detect-social-network-logins/
Monday, January 27, 2014
http://www.jb51.net/list/list_159_1.htm
http://www.aspsnippets.com/jQueryFAQs.aspx?s=1
http://blog-of-darius.blogspot.com/search/label/C%23
Friday, January 10, 2014
.rounded_wrapper { position: relative; } .rounded_wrapper img { border-width: 0; border-style: none; } .rounded_wrapper div { height: 7px; position: absolute; width: 100%; } .rounded_wrapper .tl { top: 0; left: 0; background: url(img/rounded_corners/tl.gif) no-repeat left top; } .rounded_wrapper .tr { top: 0; right: 0; background: url(img/rounded_corners/tr.gif) no-repeat right top; } .rounded_wrapper .br { bottom: 0; right: 0; background: url(img/rounded_corners/br.gif) no-repeat right bottom; } .rounded_wrapper .bl { bottom: 0; left: 0; background: url(img/rounded_corners/bl.gif) no-repeat left bottom; } /* IE6 fix */ .ie6_width .tr { right: -1px; } .ie6_width .br { right: -1px; } .ie6_height .br { bottom: -1px; } .ie6_height .bl { bottom: -1px; }
$('img.rounded').one('load',function () { var img = $(this); var img_width = img.width(); var img_height = img.height(); // build wrapper var wrapper = $(''); wrapper.width(img_width); wrapper.height(img_height); // move CSS properties from img to wrapper wrapper.css('float', img.css('float')); img.css('float', 'none') wrapper.css('margin-right', img.css('margin-right')); img.css('margin-right', '0') wrapper.css('margin-left', img.css('margin-left')); img.css('margin-left', '0') wrapper.css('margin-bottom', img.css('margin-bottom')); img.css('margin-bottom', '0') wrapper.css('margin-top', img.css('margin-top')); img.css('margin-top', '0') wrapper.css('display', 'block'); img.css('display', 'block') // IE6 fix (when image height or width is odd) if ($.browser.msie && $.browser.version == '6.0') { if(img_width % 2 != 0) { wrapper.addClass('ie6_width') } if(img_height % 2 != 0) { wrapper.addClass('ie6_height') } } // wrap image img.wrap(wrapper); // add rounded corners img.after(''); img.after(''); img.after(''); img.after(''); }).each(function(){ if(this.complete) $(this).trigger("load"); });
Asp.net
var persons = new DataTable(); string lastName = string.Empty; DataRow[] foundRows = persons.Select("Person_Id = 100"); if (foundRows.Length == 1) { lastName = foundRows[0]["Last_Name"].ToString(); }
now with LINQ, I have created the following method:
public static T GetFirstResultValue(DataTable table,string colToSearch, string colToReturn, TY searchValue) where TY: IComparable { T ret = default(T); IEnumerable rows = from row in table.AsEnumerable() where row.Field (colToSearch).CompareTo(searchValue) == 0 select row; if (rows.Count() == 1) { ret = (T) rows.First()[colToReturn]; } return ret; }