C#: Simple multithread website stress tool

You have probably searched online for a simple tool that could try and time your server response, handy for benchmarking especially when you are about to move to a new server.
You probably found that there are not much, but some cloud-based online services that actually can’t help much! Why? Cause simply you might end up stress testing a VM from another VM on the same set.

Solution was to write a custom simple multithread tool that you could:
1. Enter a url to be hit
2. Enter number of simultaneous threads
3. Enter number of concurrent hits per thread.
4. Start DoS attack 🙂

The complete working app can be found in my GitHub account: https://github.com/georgekosmidis/WebStressTool

In order to write the tool, i would need three basic things: create and start the threads, get a timed HttpWebResponse from within each thread, and finally update the UI not only from within each thread, but also at the end after everything has finished
These are the technics I used:

Continue reading


ASP.NET MVC 5: Custom AuthorizeAttribute for custom authentication

In my previous post, I wrote about how to protect your web app from human errors by enforcing authentication by default.

Since that process involves global filters, you can use that to add your own custom authentication by extending the AuthorizeAttribute.
Continue reading

ASP.NET MVC 5: Secure your web app

Securing your MVC app is one of the tricky things when migrating, as an engineer, from classic ASP.NET to ASP.NET MVC.

By default, access is allowed to every controller and action of your web app, which is potentially unsafe. As an architect, I am sure you would like to enforce the security of your app and don’t rely on whether a developer will actually remember to add the [Authorize] attribute to a sensitive controller or action.
Continue reading

C#: Programmatically “Run As Administrator”

A few days ago I wanted to write to hosts, a HOSTS file in system32 used by Microsoft TCP/IP for Windows. Since this file is protected, you can edit it in administrative mode only. This means the user has to right click it and select “Run as administrator” for your project to run correctly. Fortunately there is a solution. The following code will request admin access from the user, and rerun it’s self in admin mode:

Continue reading

How to Minify JavaScript with C#, a Google PageSpeed suggestion

Google sais “compacting JavaScript code can save many bytes of data and speed up downloading, parsing, and execution time” and that is obviously true (you can read about it here. And although there are many tools to minify javascript, like JSMin and YUI Compressor, it’s quite time consuming (and boring) to have to run these tools for each change your Web Designer decides to do for every JS file in your project. Except that, non of these tools compacts JS in one file to minimize browser requests.

The solution I came up goes like this (in my project this code runs only once in every application boot by using HttpContext.Current.Cache)

Step 1
Add a new Web Form to your project and name it js.aspx

Continue reading

Export MS SQL Database schema with C#

A few days ago, I was searching for a way to export MS SQL schema of all databases of a server for backup and migration purposes. Although I found some tools, what I needed was a way to get stored procedures, functions, views, triggers and everything even if it was encrypted.

Since I couldn’t find a way to automate this (e.g. run it every night to backup schema of my server), I thought it would be a nice weekend project.

You can read more about it, or download project from https://github.com/georgekosmidis/mssql-schema-dump!

Continue reading