Skip to main content

Tip Badges in ghost

So I am a huge fan of ghost, and I love providing my content free of charge. That being said server hosting costs money.

I added a tips badge to the bottom of my blog posts (see below) to try to offset the costs.

Continue Reading

Hosting NancyFx with OWIN on IIS

So I was quite confused about hosting Nancyfx on OWIN under IIS. Parts of the Nancy wiki led me slightly astray.

Here is the simple guide.

Make sure you Install the following nuget packages (if you havn't already).

Continue Reading

New Series: Windows myths debunked!

Over the last 8 years the demand to scale has ever increased.

We have gone from curating machines like your favorite pets, and started spinning up, and destroying VM's at an ever increasing pace.

As engineers the Unix like platforms, have always been easier to work with. Personally I enjoy linux, I love package managers, I love ssh, and configurations are much easier. That being said, lately I have been interacting a lot with Windows servers.

Continue Reading

Excel Interop cannot open my file!

So a while back I made a website that uses the Excel interop (long story). Since I made it a while ago, the IIS configuration is not automated, and must be done artisanally.

Recently I have been working on moving it to a new server. I installed Excel, and the website.

Continue Reading

Anti-Forgery Tokens in NancyFX with Razor

Getting started with anti-forgery tokens in NancyFX with razor views is pretty simple.

To start you need to enable csrf in application startup.


 protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
 {
  	Csrf.Enable(pipelines);
    base.ApplicationStartup(container, pipelines);
 }

Now you need to create a token on the get request that returns the form



 Get["/"] = x =>
            {
                this.CreateNewCsrfToken();
                return View["Index"];
            };

<!-- more -->

Now in your view you need to render the token


<form method="POST">
    Username <input type="text" name="Username" />
    <br />
    Password <input name="Password" type="password" />
    <br />
    <input type="submit" value="Login" />
    @Html.AntiForgeryToken()
</form>

Finally you need to authenticate the token on the post request

Post["/"] = x =>
{
	try
	{
		this.ValidateCsrfToken();
	}
	catch (CsrfValidationException)
	{
		return Response.AsText("Csrf Token not valid.").WithStatusCode(403);
	}
    //do something
};



Continue Reading