Skip to main content

Posts

Facebook, Internet Explorer, Anti-Forgery Tokens and Cookies

Tricky issue with the above 4 in one app... IE was blocking a session cookie from my ASP.Net MVC web application when hosted in the Facebook IFRAME. The anti-forgery token in ASP.Net (used to protected against spoof form posts known as CSRF attacks) would fail saying the cookie it was checking against couldn't be found. Turns out the issue was that in medium security settings, IE will "block third-party cookies that do not have a compact privacy policy". And as the app is in the IFRAME it is considered third party with respect to Facebook. To resolve I needed two things: 1) an XML file located at /w3c/p3p.xml containing <META xmlns="http://www.w3.org/2002/01/P3Pv1"> <POLICY-REFERENCES> <EXPIRY max-age="10000000"/> </POLICY-REFERENCES> </META> 2) and a header emitted (in server side code, the meta tag equivalent didn't seem to suffice) Response.AppendHeader("P3P", "CP='IDC DS...

Localised Form Validation in ASP.Net MVC

I've recently been working on a web application that required localisation - the display of translated copy depending on which country the user was visiting from. There was a different sub-domain for each country which was used to identify the appropriate one. It was also a requirement that the editor's of the website could update the translated copy from a simple back-office tool. For most of the copy of the website this was fairly straightforward to set up. I had a database table called Texts that contained three columns: Country, Key and Value. And hence by looking up for a particular country and key I could get the text to display. To ensure this was performant in practice what I did for each web request was to look up all the keys and values for the appropriate market and populate a dictionary object. The look-up was cached using so I was only hitting the database when I needed to rather than on every request. I then created a base view model that all other view mo...

Working with Stylecop

I was recently asked to review the use of Stylecop as part of our standard procedures for ASP.Net projects. I'd not used it before, but was fairly happy to consider doing so as code styling has always been one of my pedantic points when reviewing code (including my own!). Have to admit I was less keen once I'd installed it and found it complaining with around several hundred warnings - on a single, not that complex, and - I'd thought - beautifully coded class library. Having uninstalled it, calmed down a bit a couple of weeks later, reinstalled it, and put aside an afternoon to work through one particular solution... came to the conclusion it did have quite a lot of value. Although no individual change was of any great significance, the code certainly felt better once the refactoring effort had been completed - and we'd expect over time that any best practices it enforced we weren't adhering too, would become normal coding style. So our plan is to use it on...

Codegarden 2012 and Umbraco 5

Last week I attended Codegarden – the annual conference for the developers using the open source .Net CMS Umbraco held in Copenhagen. It’s probably fair to say that it’s not a typical technical conference. Rather more beer, bingo and unicyclists dressed as Darth Vadar playing the bagpipes than you might usually find. Those aspects weren’t completely unexpected though. It was our first time at the conference but we’d had prior notice of the Danish take on Monty Python surrealist humour found during some of the “extra-curricular” sessions. What was more of a surprise though was the announcement in the keynote – that they were scrapping development of the new version of Umbraco . I have been following the progress of version 5 quite closely – working with it with colleagues in test projects and making some small contributions to its development. Although after its release a few months ago some issues were becoming apparent from reports of those using it; to take a call to aban...

An Entity Framework Stale Data Gotcha

For ASP.Net MVC development I've been working for a while with a setup using Entity Framework Code First and Castle Windsor for providing IoC container services. I recently ran into a weird bug that may be obvious to some... but given I wasted an hour or so working it out figured it was worth a blog post. The issue was that for a certain operation I was getting stale data out of Entity Framework. With the help of the very useful Entity Framework Profiler which was reporting an ObjectContext being shared across threads I tracked it down to my implementation of a custom membership and role provider. For most use of the IoC container I have a custom controller factory, that handles resolving the dependent types. But there are some parts of the application that need access to classes managed through the container, but that aren't within the context of a controller. Custom membership and role providers are examples of these. With Castle Windsor (and other IoC container...