Dejan's Web Log

Server-side, client-side, code snippets, scripts, automation, best practices, proven approaches, tips & tricks...

Setting IP address and domain filtering in IIS using PowerShell script

Restricting and allowing traffic to web application through IIS using PowerShell
0
Starting from IIS 7.0 Microsoft introduced IP and Domain restrictions feature as a part of IIS setup. However, if you do not have this feature installed on your IIS you can easily install it through windows features adding steps which are pretty much same for each Windows version (https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/ipsecurity/add) or simply by using WebPlatform Installer. Just run WebPlatform Installer and search for IP and Domain restrictions in search box ... read more

Handling Cross-Site Scripting (XSS) in ASP.NET MVC

Handling XSS in ASP.NET MVC with custom Razor Html helpers and HttpModule
 
 
0
Cross-site Scripting (XSS) refers to client-site code injection attack where an attacker can execute malicious scripts into a web application. Basically attacker manages to upload malicious script code to the website which will be later on served to the users and executed in their browser. It is ofter use to steal form inputs, cookie values, change the page layout or redirect to attackers website. ... read more

Optimize JPG images for internet using jpegtran and PowerShell

Reduce size of existing JPG images without loosing quality with jpegtran
 
0
Recently I wrote an article about optimizing PNG images for intenrent using pngcrush and PowerShell. I actually used this method to optimize all PNG images on my website. Although I mostly use PNG images, there are still some JPEG images I use on the pages and this was not included in optimization with PNGCRUSH utility since it is specialized for PNG ... read more

Optimize PNG images for internet using pngcrush and PowerShell

Reduce size of existing PNG images without loosing quality with pngcrush
 
0
Imagine a case where you have an existing website which is running for the past few years. You decided to run a Google PageSpeed insights on couple of pages and you realized that your PNG images on the pages are not optimized for Internet. Now this can be solved thanks to a lot of online PNG image optimizers, but considering the number of the files you might have over the years of website running it can be matter of days, even maybe weeks to optimize all of them. This was my case and I could not afford myself that much time. ... read more

Minify CSS and JavaScript files with PowerShell script

JavaScript and CSS file optimization with PowerShell script
 
0
Minification of Cascade Style Sheet (CSS) and Java Script (JS) should be on a TODO list for every web application. The minification of CSS and JS can be easily one on the runtime with ASP.NET bundling which is build in in ASP.NET framework, but in case of distributing your resource files over CDN you cannot use the runtime minification. You physical files need to be minified ... read more

Switch from HTTP to HTTPS in existing ASP.NET web application

Switch complete traffic from unsecured to secured with web.config update
0
Starting from few years ago, Google enforces secured over unsecured website traffic. However it is an ongoing process since both publishers and advertisers need to implement HTTPS in order to avoid mixed contnet exception in a browser and preventing ads to load on a website. ... read more

Minify HTML output of your pages

Minification of HTML output using ASP.NET IHttpModule
 
0
Minification of resource can speed up your page load and decrease network traffic making you pages load faster, especially on a poor Internet connections. Keep in mind that not all of your website visitors have high speed Internet connection. Especially if you are targeting countries with mostly poor Internet connection, HTML minification can really boost the page load and improve user experience ... read more

Export DataSet and DataTable to Excel with C#

Saving DataSet or DataTable instace to an Excel spreadsheet with C#
0
Some time ago I wrote an article on how to export data to Excel from C# code. Essentially it exports data to file which can be opened in Excel but it does not produce the actual Microsoft Office Excel document. I recently wrote an article on Working with Excel files in .NET without using COM in C#, so I decided to use this approach to create extension methods for DataTable and DataSet classes ... read more

Export DataTable to HTML in C#

Generate HTML table from DataTable instance in C#
0
When I searched for exporting s to HTML table in C# I found a lot of articles and code snippets which are basically doing string concatenation or String.Format on the hard-coded HTML String to generate HTML string of the table. To me this approach is a bit like a workaround and I was never a fan of hard-coding values. In addition, code with a lot of hard-coded value end up as hardly maintainable code ... read more

Simplest way to store lists and dictionaries in config files

Fast and simple way of storing and using lists and dictionaries in config files
0
Configuration files are a useful place too keep any related configuration settings. It provides easy to use configuration fetching which you can invoke from any part of the application. However it does not support many stuff out of the box, but on the other hand it is pretty flexible and expendable. One of the things that are not there built in is support for lists. ... read more

JavaScript

read more

Umbraco CMS

read more

.NET

read more

SQL/T-SQL

read more