Using Protocol buffers v3 with ASP.NET core

By default ASP.NET core API methods operate on JSON: they deserialize JSON from request/response body to model type and back. JSON is everywhere and works well… unless you have very high throughput requirements. There are many alternative formats, but Google’s serialization format Protocol Buffers is one of the most used. It has overgone some changes recently: the old proto2 syntax is replaced with proto3. The latter even has an official C# support. The old proto2 used to have unofficial C# ports, and many ASP.NET MVC samples on the internet are based on those. I couldn’t find a working proto3 version, so I created my own. ...

March 11, 2016 · 3 min · Tero Teelahti

Don't let techies design game user experience

Today I had some 20 minutes spare time and I wanted to try games my co-workers had recommended for me. Heartstone First off was Heartstone - Heroes of warcraft. I had opened the game day before, and was in the middle of the tutorial story. Opening the game again got me slowly to the same tutorial spot… except when I clicked “Play” I got this: Smells like an american engineer. Three hour maintenance break is looong, but I can live with that; there might be a valid reason (like earthquake or tsunami or blown up data center). Instead, what irritated me, was that ...

February 2, 2016 · 3 min · Tero Teelahti

Using VS Team Services with go get

I use VS Team Services for some of my repositories. I use the Git repository type, and most of the time everything works fine. Until today I reorganized some of my Go code to be more idiomatic, meaning that I leverage the native Go package system as it is designed: the only way to reference packages is by their full repository URL: package main using ( "myorg.visualstudio.com/DefaultCollection/_git/MyRepo" ) and you can also load packages with Go get command, like: ...

January 19, 2016 · 2 min · Tero Teelahti

Azure Blob Storage CORS headers and ScriptCS

One of Basware’s products I work for uses CDN to deliver content for end users. CDN provider is Edgecast, and primary & secondary origins are Azure Blob storage accounts. So far we have not needed any cross domain access to the CDN, but now a new feature required Javascript requests from our application domain to the CDN domain… and browsers naturally block this nowadays. I knew right away that I need to set the Cross Origin Resource Sharing (CORS) headers to our origin servers, but setting this up was harder than it is supposed to be: Azure’s Powershell SDK does not have support to alter this value, and there is no UI to set it in the management portal. There is of course the management REST API you can use to do anything, but calling it with curl is hard due to the authentication scheme. Setting the DefaultServiceVersion property proved to be as complex before, so I knew what to expect. ...

May 29, 2015 · 2 min · Tero Teelahti

ASP.NET vNext presentation at Microsoft devdays 2014

At the beginning of October Microsoft Finland held the yearly developer conference, this time with name Devdays. This year’s conference felt slightly smaller than previously. As there is is lots of churn around the ASP.NET right now and I have a history with that framework, I proposed a presentation about ASP.NET vNext. Gladly it got accepted, and I had to dig deeper into what’s coming from the ASP.NET team. I played with the framework, watched every video and and read every blogpost about it from Scott Hanselman, David Fowler and others. I also prepared some demos, even a Linux demo which I had to scrap on last minute because I had only 45 minutes time to present. I tried to give the audience some guidelines how they can prepare to what’s coming, in order for the upgrade from current ASP.NET to be as easy as possible. It was nice to prepare and present, I hope it helped someone. ...

December 2, 2014 · 2 min · Tero Teelahti

How-to deploy to Azure website deployment slot from TFS

I changed some of my websites deployment to use different deployment slots on a single Azure web site instead of having different web sites for different staging areas. I deploy all my staging areas automatically from TFS (using the GitContinuousDeploymentTemplate.12.xaml process), each area from different Git branch. Works for my setup. What did not work was deploying to other slots than the main slot. On Azure portal different slots have name and address scheme like mywebsite-slotname. I tried to use this name as deployment target: ...

October 24, 2014 · 1 min · Tero Teelahti

How to change your Outlook default calendar

Since Office 2013 was launched, I’ve had some problems with Outlook and account settings: I can set up all the accounts, but Outlook refuses to display my default Exchange calendar on the todo-pane, and instead shows an empty calendar from one of the other accounts that I use for email only. I like the todo-pane as its easy to glance whats coming with it. I’ve searched for resolution a couple of times, and most Microsoft community answers suggest to change the default data file on via Outlook > Account Settings: ...

August 6, 2014 · 1 min · Tero Teelahti

What has pharmacy to do with programming?

I visited my local pharmacy last Friday to get some prescription drug. I sat in front of the pharmacist, who gave me very thorough guidance about the usage. At the time of payment - before she handed me the boxes - she suddenly said: Excuse me, but I need to get a signature from someone else, as I am a trainee. Immediately another pharmacist came by, put her smart card into the computer, checked the boxes against the electronic prescription, and then signed the delivery. The whole process took maybe 20 seconds, and I’m certain trainee felt safer as her work is checked against mistakes. And myself - as a client - I felt like they care. ...

June 3, 2014 · 2 min · Tero Teelahti

The promise of OWIN starts to materialize

OWIN stands for the “Open web interface for .NET”. Basically it is a reasonably simple specification that defines how data goes through the request pipeline, and how to attach to that pipeline. It is a specification for both the server and the application (middleware on OWIN’s terms) part. When I first saw the project I was not that convinced, but since then lots of applications that rely on OWIN and not the old System.Web stack has emerged, and also there are some hosting components that implement the spec. SignalR is a good example of middleware, and Katana a host. For me the new project Helios is also very interesting and I hope the project succeeds, as that would make hosting ASP.NET WebApi very lightweight. And light is never bad. ...

May 9, 2014 · 3 min · Tero Teelahti

Yet another take on Internet Explorer compatibility mode

I have touched this subject already twice: first I I blogged about forcing site rendering to be done with Internet Explorer’s latest engine. Then I faced a situation where separate intranet zone (bad idea, Microsoft!) fallbacks to compatibility mode and does not respect the IE=edge meta tag as internet zone web sites do. Well… the saga isn’t over, as I faced this situation at work today. Again. I was going to put the IE=11 meta tag in place to force normal mode, but then I started to doubt how older IE’s (9, 10) would interpret the “11” tag. Short answer is: they don’t. Luckily you can specify many different modes, and the browser will pick the first one it supports. To apply this use either a meta tag in your page: ...

February 4, 2014 · 1 min · Tero Teelahti

Mass convert WMA files to MP3's

I’ve always been a music fan. Not a die-hard-fan, but one with lots of music and decent equipment. During the era of CD’s, I routinely bought new discs, and they accumulated in hundreds. And then hard disk prices fell and network speeds grew, and I wanted to digitize all I had. This was years ago, maybe around year 2004. I wanted everything in lossless format, as digitizing was slow and I was not going to do it again. “Alternative” media format (.flac, .ogg) support was poor in Windows world, and I chose lossless windows media audio (WMA). I spent many evenings changing the disc on my laptop, and typing album and track names when they were not automatically found from media info databases. ...

February 3, 2014 · 3 min · Tero Teelahti

Blog migrated to Github pages

I already blogged about the original platform Orchard I used to host this blog. I needed a new blogging platform, and after all the complexity I wanted something simpler and easier to upgrade. Lately Github pages and Jekyll have drawn a lot of attention. Tipping point for me was reading what it took for Phil Haack to move his blog over. I tend to test new technology all the time, and decided to take a shot on Jekyll as a blogging platform. ...

January 26, 2014 · 5 min · Tero Teelahti

The Orchard experience

When I originally started this blog I had two options: use some readymade blogging platform, or host one of the blogging platforms myself. I wanted a complete control of everything, and decided to build the blog to my own hosting. As .NET was (and partly still is) my thing, I wanted the platform to be .NET based. Sadly, none of the available platforms pleased me: dasBlog was aging and was not updated, DNN was too complex and written in Visual Basic. Luckily there was one new emerging platform called Orchard that was exactly what I wanted. ...

January 25, 2014 · 2 min · Tero Teelahti

0x80070005 revisited

A while ago I blogged about a recurring problem in my laptop: event log was filling with Software protection service scheduling errors, and the fix was to change one system folder’s permissions. I ended up re-installing my laptop from scratch (to Windows 8.1), and again after I joined the machine to our company domain and installed Symantec Endpoint Protection the problem re-appeared. I still do not know which - domain or SEP or both together - is the root cause, but as the problem emerged over and over again, I gave up and automatized the change. I created one batch file: ...

October 29, 2013 · 1 min · Tero Teelahti

Windows 8 fix: Failed to schedule Software Protection service for re-start - 0x80070005

I have had some weird problems on my Windows 8 laptop, and while fixing those I noticed a recurring Error event on my event log: “Failed to schedule Software Protection service for re-start at 2113-03-24T10:21:45Z. Error Code: 0x80070005.” (Source: Security-SPP, Event ID: 16385) 0x80070005 is a permission denied error. After some searching and trial/error I found the fix from a Technet forum post; Give Network service account full access control rights to the directory: ...

April 17, 2013 · 1 min · Tero Teelahti

How to survive a 12 hour drive with your kids (a nerd edition)

It is again winter holiday time here in Finland, and as our land is mostly flat, you need to travel a long way to reach any hills suitable for real downhill skiing. For me that means ~12 hour drive from my home town Lohja to Finnish Lapland, more specifically Ylläs ski resort. You can get there by train or with an airplane, but as some of our friends live half way there we usually end up driving the whole way. ...

March 13, 2013 · 4 min · Tero Teelahti

Techdays 2013 – SignalR

A week ago we had Microsoft TechDays 2013 at Finlandia Hall, Helsinki. For me this was fifth year in a row talking at Finnish Techdays; once I have talked about Azure, all the other talks have been about web technologies and trends. This time was no exception: I talked about real time web need and patterns, and about SignalR as one implementation tool. I enjoyed talking, and I hope I provoked at least some of the 200 listeners to think beyond the traditional HTTP Request/Response pattern we use to build web apps. ...

March 12, 2013 · 3 min · Tero Teelahti

Web site that narrates input text (for kids)

Last year, when my kids got interested in learning to read and write, I decided to do what I tend to do: bring technology to the table. I created a simple web site that narrates input text, and shows navigable history of the given input on the page. Simple narrating UI for kids. I created this on Finnish only, but changing the language is relatively easy (i.e. only a couple minutes work). If you wish to use this, I just put the source code on GitHub. If you wish to play with the Finnish version, I host it at http://lue.teelahti.fi. For my kids I put this full screen, and it kept them occupied for as long as half an hour (= eternity for kids).

January 30, 2013 · 1 min · Tero Teelahti

TypeScript, the new CoffeeScript?

Today Microsoft’s Anders Hejlsberg introduced TypeScript, which basically is a language that compiles into JavaScript, very similar to CoffeeScript. There are some differences, though: whereas CoffeeScript tries to make writing JavaScript very brief and removes lots of {}-stuff from the language, TypeScript tries to create an efficient type system on top of JavaScript. I have tried to approach CoffeeScript a couple of times, but every time using it for real has had lots of doubts: ...

October 2, 2012 · 2 min · Tero Teelahti

Using PowerShell to narrate text

I visited NDC 2012 and enjoyed the conference a lot. Again. Awesome speaker lineup without too much product group advertisements. Lots of thought provoking lessons. Lots of fun tongue-in-the-cheek style stuff in between. Like Damian Edwards and Rob Conery “fighting” each other with SignalR and Socket.io, respectively (video here). On that cage match Rob used a cool narrator from command line (they used narrators since Damian had lost his voice), and for some reason that fascinated me. ...

July 26, 2012 · 2 min · Tero Teelahti

First impressions of Nokia Lumia 800

I know I’m late to the game but I received my Lumia only yesterday. I’ve had a Windows Phone 7 LG E900 a.k.a LG Optimus 7 for 16 months now and I’ve generally been very happy with it. Even though the Lumia is so much newer, spec-wise it does not add much to my old LG: slightly faster HSPA network, faster processor, and some Nokia software, that’s all. Below I’ve listed some pros and cons of Lumia over LG. ...

February 16, 2012 · 2 min · Tero Teelahti

Problems with Internet Explorer compatibility view

A while ago I blogged about forcing site rendering to be done with Internet Explorer’s latest engine. This feature is very well documented by Microsoft. Not that well documented is that adding the X-UA-Compatible header with value “IE=edge” does only half of the job: it overrides document mode, but not browser mode, and therefore you might end with situation like below - even if you carefully tried to avoid it by placing the meta tag (I know, I just did). ...

January 17, 2012 · 2 min · Tero Teelahti

Different ASP.NET MVC master page for authenticated and unauthenticated users

I guess this is a common problem: you need to have different web site layout for unauthenticated users. In simple cases this is very easy: just use masterPageFile attribute on views. But it gets more complex when you have views that are used in both authenticated and unauthenticated context. Luckily MVC lets you plug into almost anything, and this can be solved with an action filter like this: using System.Web.Mvc; /// <summary> /// A globally registered attribute to change view master /// page based on whether user is authenticated or not. /// Uses magic strings for the file names, could /// be changed to something more elegant. /// </summary> public sealed class SwitchMasterPageFilter : IActionFilter { public void OnActionExecuting( ActionExecutingContext filterContext) { } public void OnActionExecuted( ActionExecutedContext filterContext) { var result = filterContext.Result as ViewResult; if (result != null) { bool authenticated = filterContext.HttpContext .User.Identity.IsAuthenticated; result.MasterName = authenticated ? "~/Views/Shared/Site.master" : "~/Views/Shared/SiteUnauthenticated.master"; } } } Remember to register the filter on your site bootstrapper and you are good to go.

January 11, 2012 · 1 min · Tero Teelahti

SSL, IE8 and strict cache headers (will not work)

Recently I encountered a bug that only some users saw, and which did not reproduce locally on development environment. The setup was: An intranet page has an IFrame …that is dynamically changed to point to an attachment …which is served from MVC action returning FileContentResult This is a pretty common pattern to open files on browser without leaving the current page. And it worked like charm in all browsers, except on Internet Explorer 8 on testing environment, where IE just showed an error message that the address cannot be opened. IE 7 might be affected too, but I did not test on that. ...

December 15, 2011 · 3 min · Tero Teelahti

Disable Internet Explorer compatibility view via web.config

New Internet Explorers have a necessary (?) but annoying feature called “Compatibility view”. I do not need that in my sites since I try to keep my HTML in good shape. Therefore on all projects I want to disable the feature since usually it breaks the layout. Disabling compatibility view can be done by adding a meta tag to HTML head: <meta http-equiv="X-UA-Compatible" content="IE=edge" /> …or, as it turns out, by adding a custom HTTP header with the same content. This HTTP-header-way is much better for me as I can include it in my default web.config changes I use on almost every web project. ...

December 1, 2011 · 1 min · Tero Teelahti

How ASP.NET Web forms feels after 3 years of not using it

I have been an ASP.NET developer since it was invented, and a legacy ASP developer before that. For long I spent most of my time doing ASP.NET Web Forms and it was OK: I remember lots of weird problems that needed extensive trial and error –debugging, but things weren’t that bad. Then ASP.NET MVC came and I got interested. In the (massive) client project I worked for at that time I bent some Web forms concepts to the extreme and didn’t like it too much. MVC felt very light and as it embraced HTML it was very good for the new rising of HTML(5). ...

November 11, 2011 · 3 min · Tero Teelahti

Element cloning problems with jQuery mobile AJAX page transitions

I’m building a site that will mainly be used with mobile browsers (> 60 %), and so I decided to build it mobile first and then adapt to desktop browser widths with CSS media queries. Natural framework choice for easy mobile development is jQuery mobile; now I’ve been playing a couple of nights with it already and mostly have liked the experience: this framework is very convention based, and at least as long as you follow the conventions everything is remarkably easy. ...

August 29, 2011 · 2 min · Tero Teelahti

Fixing some Orchard CMS blog problems

Blog archives part not working when blog is the site home page When you create a new blog in Orchard CMS and set it to be the home page blog archives list (part) refuses to display anything. Reason for this seems to be that Orchard database table called Orchard_Blogs_BlogArchivesPartRecord has a column called BlogSlug, and it defaults to “blog” even though blog is the home page (i.e. slug = “”). A clear bug, but I didn’t want to wait for a fix and just changed the value to null, and list of archived blog posts came to life. ...

August 4, 2011 · 2 min · Tero Teelahti

WP7 Mango update - the good parts

When the Mango update was released with all the warnings about backups of backups, I decided not to go for it. But then, only half a day later, I was in a process of installing the update. Couldn’t resist. It took long but I succeeded not to brick my phone, and now I’m running Mango and mostly like what I see. Here is a list of some of the improvements that I value and see on my daily use from an end user point of view (i.e. not developer). I expect to see even more when applications start to support Mango, and Microsoft polishes the OS before RTM. ...

July 1, 2011 · 3 min · Tero Teelahti

JavaScript bind and curry polyfills

Although I’m a C# guy, I’ve recently really started to like JavaScript. It is so dynamic and “different” that it forces you to really think what you are doing and how do you want it structured – which is a good thing. And if you just want to get things done quick and dirty JavaScript is also a perfect match for that. When I begun to use JavaScript on daily basis I naturally soon learned to use more and more closures and all that they bring with them. For a while I wrote over and over again code like this: ...

June 28, 2011 · 2 min · Tero Teelahti

Blog feed moved to Feedburner

I intended to use Feedburner from the beginning, but I did not find an easy way to modify Orchard (the CMS behind this blog) to link to an external feed. Luckily Bertrand Le Roy came to rescue and created Vandelay Feedburner plugin, which works great. From now on this blog’s feed is hosted at feeds.feedburner.com/Tero-Teelahti; old address still works but if you follow this blog please change to the new location since that will be more reliable in the long run.

May 17, 2011 · 1 min · Tero Teelahti

How-to localize jQuery UI Datepicker within ASP.NET MVC site

JQuery’s date picker UI component is very easy to localize on Javascript level. On this blog post I’ll describe how to ensure that date picker culture follows site’s server side culture. This is pretty trivial to accomplish, but it won’t hurt to document it here. First, you need to pick the translations you need from jQuery UI trunk. Place these files on your script folder and include them on your page (or master page), here I’m using my favorite static content bundler SquishIt to combine and minify scripts: ...

May 16, 2011 · 1 min · Tero Teelahti

Disable submit buttons on form submit with jQuery.validate and ASP.NET MVC 2

I had a very common requirement to fill: when user clicks form submit button (or enter on keyboard) the button needs to be disabled in order to prevent double submits. Double submits could of course be filtered at server side with various timestamp mechanisms, but this was not what I was after this time. The first option that came into my mind was of course just to subscribe into form submit and disable buttons there like this: ...

April 29, 2011 · 2 min · Tero Teelahti

Controller dependency missing on test? Try MvcContrib TestControllerBuilder

Ever faced this situation: You have nice and easy controller method, say: public ActionResult Demonstrate(string id) { this.Repository.Demonstrate(id); string url = this.Url.Action(MVC.Errors.Suck(id)); return this.Redirect(url); } Then you go and create test for it (or created the test before, whatever suits you): [TestMethod] public void Demonstrate_ValidInput_Redirects() { // Arrange var controller = new MyDemonstratingController(); // ... mock something here // Act controller.Demonstrate("kaboom"); // Assert // ... test that everything was called } …only to get NullReferenceException, since you did not set everything up that is needed by the UrlHelper class (controller’s Url property). ...

April 26, 2011 · 1 min · Tero Teelahti

Selecting MVC action method based on any named form value

Yesterday I blogged about using form button names to select action methods on an ASP.NET MVC controller. After using that attribute for a while I realized that I can make a generalization out of that: why not use any form value in the action method selection process? This way I can avoid code like this: [HttpPost] public ActionResult Fruit(SampleModel model) { if (!ModelState.IsValid) { return View(model); } if (model.IsApple) { // Do something EatApple(model); } else { // Do something else SmashOthers(model); } TempData["Message"] = "Saved"; return RedirectToAction("Index"); } That is not too bad, but when more choices are introduced it gets worse and worse (i.e. more if-then-else’s). Solution for this is very similar with the ButtonAttribute approach: introduce an attribute that takes form element name, and list of accepted values. If there is a match the action method is selected, otherwise the search continues. Usage example: ...

March 26, 2011 · 4 min · Tero Teelahti

Selecting MVC action method based on the button clicked

Very common problem in form-heavy solutions is to be able to have one HTML form, but two different submit buttons for it. Think “Save” and “Delete”: <div id="buttons"> <button name="Save">Save</button> <button name="Delete">Delete</button> </div> On controller side this poses a problem: these actions do very different tasks; Save usually validates data and saves it, Delete does not validate and deletes (and so forth). They might also have different access rights. So having these on one action breaks (at least my) principles. Fortunately ASP.NET MVC has a thing called ActionMethodSelectorAttribute that you can extend. With that you can divide the logic into separate action methods, like: ...

March 25, 2011 · 3 min · Tero Teelahti

IIS 7.x cache optimizations

I find myself searching for this information over and over again for each web site I develop, so I guess I must blog this topic to remember it from now on. IIS 7 has a very powerful caching framework, but some of the defaults are in my opinion not very well thought for modern web applications. For example: by default Javascript files are not compressed with GZIP, and cache location for static content is not public by default. So, if you use T4MVC, SquishtIt, or any other means to link to your static files with a timestamp then you might want to use settings along these lines: ...

March 16, 2011 · 2 min · Tero Teelahti

Applying zebra striping with jQuery tablesorter and tablesorterPager plugin

A small but annoying bug I found today (and seems that someone else is having the same problem): when using jQuery.tablesorter) plugin together with tablesorterPager, applying the pager clears some properties from the table; In this case namely zebra striping. After initialization first table page is not striped, but next ones are after the first table page change. I found some crazy complex solutions, like creating new widgets to replace the built in “zebra”, but the good enough solution ended up being lot easier: asking tablesorter to reapply widget: ...

March 3, 2011 · 1 min · Tero Teelahti

How to shoot yourself in the foot with an IoC container

In the project I recently worked for our solution’s web interface froze every now and then. This problem had been going on for a while, but every time the problem went away by itself without any intervention. No problem, until the issue escalated even to developer workstations, making them slow. Investigation The problem was easily pinpointed to be at the service layer (IIS WAS hosted). Investigation was started by adding more application pools, and immediately the responsiveness of the service increased. The main reason being that worker processes were restarted, but we did not know it then. Gladly we knew that this was not a fix, just a temporary cure, there was still something badly wrong. ...

March 1, 2011 · 3 min · Tero Teelahti

Hello world!

I started to actively follow blogs about 6 years ago. I still remember the first blog I regularly followed was Brad Abrams’s blog. I followed blogs because they were interesting, they showed me a world outside my current company, and they contained lots of technical tidbits. Also, at that time they were the fastest way to spread information and helped to understand what’s cool right now. Looking at my blog reader subscriptions now I have 75 blogs that I follow. Although Twitter has taken over blogs in many ways, I still think blogs have their place. ...

February 27, 2011 · 2 min · Tero Teelahti