08/10/2021

mysql error: Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.

 Khi import/restore mysql database lớn đôi khi gặp lỗi này

có thể cấu hình lại file config của mysql như sau:

innodb_log_file_size=512M;
 innodb_strict_mode=0;

thêm: SET GLOBAL max_allowed_packet=134217728;

restart mysql và kiểm tra lại:
SELECT @@max_allowed_packet;
SELECT @@innodb_log_file_size;
SELECT @@innodb_strict_mode;

18/09/2021

Sử dụng log4net ghi log trong ASP.NET MVC

 Khi bạn cần debug hay handle exception trong chương trình

bạn có thể tự viết hàm ghi log nhưng log4net có thể làm giúp bạn rất tốt với 5 kiểu khác nhau:

  • Debug
  • Information
  • Warnings
  • Error
  • Fatal
Dưới dây là 1 đoạn log exception:

2021-09-18 15:30:43,751 [5] ERROR MonitoringLogger - Load index error
System.DivideByZeroException: Attempted to divide by zero.
at WebApp.Controllers.HomeController.Index() in P:\****\Controllers\HomeController.cs:line 37

Tham khảo bài viết chi tiết tại đây: https://vnn.me/sJlMw9v

12/08/2021

Export table html to excel with utf-8 using javascript

 // đây là hàm export toàn bộ nội dung trong 1 bảng html ra excel

function exportTableToExcel(tableID, filename = '') {

        var downloadLink;

        var dataType = 'application/vnd.ms-excel;charset=utf-8';

        var tableSelect = document.getElementById(tableID);

        var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');


        // Specify file name

        filename = filename ? filename + '.xls' : 'excel_data.xls';


        // Create download link element

        downloadLink = document.createElement("a");


        document.body.appendChild(downloadLink);


        if (navigator.msSaveOrOpenBlob) {

            var blob = new Blob(['\ufeff', tableHTML], {

                type: dataType

            });

            navigator.msSaveOrOpenBlob(blob, filename);

        } else {

            // Create a link to the file

            downloadLink.href = 'data:' + dataType + ', ' + tableHTML;


            // Setting the file name

            downloadLink.download = filename;


            //triggering the function

            downloadLink.click();

        }

    }


//sử dụng

<button class="btn btn-success" onclick="exportTableToExcel('tableId', 'file_excel.xlsx')">Export</button>

11/04/2021

Mã hóa số thành chuỗi với Base62 c#

 Đôi khi bạn cần mã hóa 1 số thành chuỗi, để đảm bảo chuỗi mã hóa không trùng, bạn cần 1 số long và kiểu mã hóa đủ rộng, ở đây có mô tả Base62

code sample như sau:

private string ToBase62(long number)

        {

            try

            {

                var alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

                var n = number;

                long basis = 62;

                var ret = "";

                while (n > 0)

                {

                    long temp = n % basis;

                    ret = alphabet[(int)temp] + ret;

                    n = (n / basis);

                }

                return ret;

            }

            catch(Exception ex)

            {

                //Helpers.Log.Error("ToBase62 error" + number.ToString(), ex); //hander exception error

                return string.Empty;

            }

        }

10/03/2021

Kiểm tra 1 trang web có cho phép mở trong iframe hay không bằng c#

 Khi cần nhúng 1 trang web (URL) khác vào website của bạn dưới dạng iframe

Nếu website đó không cho phép mở dưới dạng iframe, website bạn sẽ hiển thị lỗi :)

Bạn cần kiểm tra trước để hiển thị phù hợp, code c# có thể dùng như sau:

//using using System.Net;

//check frame support

                    string frame_support;

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(iframeUrl);

                    using (WebResponse response = request.GetResponse())

                    {

                        //DENY, SAMEORIGIN, ALLOW-FROM

                        //null is open in iframe

                        frame_support = response.Headers["X-Frame-Options"];

                    }

Đăng ký tên miền, hosting, máy chủ, thiết kế lập trình website theo yêu cầu

 Chính thức trở thành đơn vị cung cấp dịch vụ đăng ký tên miền quốc tế, tên miền Việt Nam hosting, máy chủ, cloud hosting, cloud server, ema...