Affichage des articles du 2018

How to encrypt to a url safe string...

Here's a helper that can be used to encrypt/decrypt ids that are url safe.
For example, if your user needs to download an invoice, it's clearly more secure to provide a url like
instead of:
As there can be a malicious user that will try to download invoices from others, or you don't want the user to know what the invoice id is.
Example, in your controller:

[ActionName("download-invoice")] publicFileResult downloadInvoice(string id)         { var decodeId =int.Parse(id.DecryptBase64()); var invoice = MainService.getInvoiceById(decodeId); if (invoice == null) thrownewHttpException(404, "Not Found"); return File(MainService.generateInvoicePDF(decodeId), "application/pdf");         }      

In your view:

Html to Image...

Sometimes it's useful to generate an image from a url.

Here's how you can do it for free, without having to pay for expensive 3rd party components.

All you have to do is download wkhtmltoimage.exe from

       public static byte[] DownloadImage(string url)
            return DownloadImage(url, 1024, 768);

        public static byte[] DownloadImage(string url, int w, int h)
            var htmlToImageDir = Path.Combine("Your Path", "HtmlToImage");
            var process = new Process();
            var startInfo = new ProcessStartInfo
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                RedirectStandardInput = true,
                CreateNoWindow = false,
                FileName = Path.Combine(htmlToImageDir, "wkhtmltoimage.exe"),
                Arguments = s…