Mark the Use default checkbox. If you like you can set your Startup dir (mine is C:\code).

In the same Settings window now select Hotkeys. Find Paste and change the hotkey to CTRL+V. You can now paste text into the commandline using CTRL+V!

Set up Powershell scripts

I’ve got two going on. The first is the best.
Powershell scripts is “installed” by referring to psm1 files in your so called $profile. Jump to Powershell and enter $profile. It will return something like C:\Users\jhovgaard\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1. To include a script simply append a new line to the file like this:

Import-Module "C:\PATH\TO\YOUR\SCRIPT.PSM1"

Search and open .sln file in current folder

My script is available here:
https://gist.github.com/jhovgaard/8a91441e621094544a17

Save the file to your machine and add a reference in your $profile.

Open new Google Search from Powershell

My script is available here:
https://gist.github.com/jhovgaard/9dad2a49a441a83a5874

Do you know that special feeling some features can give you? Things that only can be described as neat. I think we just made one of them on Servant. Check out this GIF:

Yeah, I just used drag and drop to deploy a website to my IIS. I don’t wanna brag but I really think it’s awesome!

Behind the scene we use the browser to pack and compress your files into one zip archive. Then we upload this zip to a hidden URL. The zip is only stored in memory and it’s automatically wiped after 5 minutes. Now we tell your Servant Client (meaning your web server) to download the zip, extract it to the specific site (into a new folder) and change the site’s disk path to the new location.

By deploying to a new folder we also remove the seconds of downtime you normally experience when using the same-folder-strategy. The new folder name will include a timestamp.

We will extend this deployment feature with history, auto warm-up and error detection with automatic roll-back (no ETA yet).

What do you think? Cool and useful or a complete waste of time? Leave a comment!

What have changed?

Some of you may already know about Servant for IIS - a lightweight web interface for IIS (Which is still available at GitHub of course). Servant.io is the next step in making management of web servers even easier and much more awesome.

What we have done is simply move Servant to a hosted cloud environment like you know it from Boundary, New Relic and services like that. We have developed a small client/agent to be able to communicate with your servers (the source is open and available for everyone).

We’re working like crazy apes to bring new features. Below I’ll list the features we have pushed live so far.

Web farm support: One of the biggest feature requests on Servant for IIS was multi-server/web farm support. Servant.io now fully supports IIS web farm setups. You simply select one server to be your primary configuration, and Servant will take care of keeping your sites in sync.

Deployment: We bring automated deployment to both single servers and web farms. You upload a zip file containing you site, and Servant will extract the site on every server. Servant always extract to a new folder when deploying, and it doesn’t change the path until the site is completely ready. This dramatically reduces downtime on deployment.

Plug and play: One super important thing for us is that it won’t be annoying to install the Servant Client. To overcome firewall issues we communicate entirely on port 443 (HTTPS). We use WebSockets (SignalR actually) to send commands to your server so you don’t have to open for incoming traffic. All communication is of course securely done via SSL.

Security: Everyone knows that no software is completely secure. We do a lot to keep Servant super safe, but if something bad happens we introduced a completely automated and silent updater. This makes us able to push security fixes instantly to your server. Everything is happening without any effort required by you. Your Servant Client will always be up to date.

The future

We have endless numbers of features that we want to introduce, but right now this is what we have in the official pipeline.

Drag and drop deployment: Simply drag a folder from your disk onto your site in Servant, and we will handle zipping and deploying.

Deploy from Visual Studio/IDE: We’re developing support for deployment (server + web farm) via FTP. This will enable you to deploy to all your servers directly from Visual Studio/your IDE.

Powershell/command line access: You will be able to execute commands and powershell on your server directly from the Servant.io web interface. Executing commands on every server in a farm will also be possible.

Pricing

Servant.io is currently in public preview which is completely free for everyone. When we feel like the product is worth paying for, we will introduce a price model.

I promise prices will be fair and will match the size of your organization. Also we will have a discount for students + completely free for open source organizations!

That’s all for now. I hope you’re as excited as we are. We want to bring the best web server manager ever.

What is PJAX and why?

Today most web applications use a layout page, because we need to maintain the same HTML code over multiple pages. This HTML could be the header, footer and so on.

When the user clicks around our application they need to download this header and footer again and again and again.

Some developers use AJAX to download data from the server, and then manipulate with the DOM using Javascript to show this new data. Some use big Javascript frameworks and call their application a SPA. This is clever, but isn’t compatible with search engines and non-javascript users. So developers is forced to support two “versions” - a AJAX version and a pure HTML version. Cumbersome and expensive if you care about SEO.

PJAX fixes this issue. When enabled it will tell the server if it should include the layout HTML or not. If Javascript is enabled (not a crawler) there’s no reason to include the layout. If not, the server returns the complete HTML.

Quote from https://github.com/defunkt/jquery-pjax: pjax works by grabbing html from your server via ajax and replacing the content of a container on your page with the ajax’d html. It then updates the browser’s current url using pushState without reloading your page’s layout or any resources (js, css), giving the appearance of a fast, full page load. But really it’s just ajax and pushState.

So to get to the point: PJAX is a plug-and-play plugin that reduces bandwidth usage, increase performance and is fully compatible with non-javascript users.

Setting up the demo

I’ll go through setting up the demo application real quick, since this article isn’t about Nancy, but PJAX. If you’re new to Nancy I suggest you start by reading my getting started on Nancy blog posts.

Great, now ViewBag.IsPjax can tell is if the request is coming from PJAX. Now we simply need to add an if-sentence to our Views, to make them able to ditch the layout if request is coming from PJAX:

@{
Layout = ViewBag.IsPjax ? null : "_Layout.cshtml";
}

I’ll do this everywhere I set the Layout in Razor. In my demo it will be Index.cshtml, First.cshtml and Second.cshtml.

Now when I click around my application, I’ll see that the “Layout loaded” timestamp doesn’t change, but the content and URL does! If I disable Javascript, everything still works as any other regular webpage.

We’re done!

That’s it, one complete PJAX application. You should notice that when you write Javascript for PJAX application it is very important that all events is attached to the #container object. For example to handle a click event on some button, you should NOT do this:

Wrong way:

$('#MyButton').click(function() {});

Right way:

$('#container').on('click', '#MyButton', function() {});

The reason is that PJAX will inject the content of your pages into the existing DOM. The “wrong example” only hooks up to instances of my #MyButton on intilization, but PJAX injects #MyButton after initilization.

I hope you see the power of PJAX. I really do think this is the next big thing. I already use it in production and it is a huge timesaver and have really changed the way I do web applications. To be honest I tend to write much more C# than Javascript now, after PJAX. Simplicity at it’s best. PJAX have my vote for the no. 1 web technology of 2014.

As you can I simply return a text response to the user, telling them the token is invalid. Also I’m returning a 403 Forbidden status code instead of 500 Internal Error. You may choose another solution :-)

Simple as that!

That is how CSRF protection works using Nancy. Please notice I’m not showing best practice here. You should move the try-catch into a BaseModule (maybe use the Before hook), there’s no need to copy/paste that code into every action of your application.