by Andreas

IE 11 / Windows 8.1 update killed my local sites

imageAfter upgrading to Internet Explorer 11 (included in the recent Windows 8.1 update) my local IIS hosted web applications suddenly died. But only in Internet Explorer – the other browsers (Safari, Chrome and Firefox) were unaffected.

After some research I found out that IE 11 comes with a brand new technology called AppContainer. It’s a protection mechanism that blocks Read and Write access to most of your system, including your IIS hosted sites.

 

There are several ways of getting around this, but I simply turned off “Enhanced Protection Mode” under IE 11 Internet Options. I use Chrome for my daily browsing anyway, and IE is just for verifying browser compatibility of my applications. Remember to restart your browser afterwards.

image

by Njål

File Format/Extension CSV

 

imageHere is a CSV(comma separated values) list I put together with over 10500 file formats and descriptions.

I got the content from various websites – by making a small C# program that screenscraped the content that I wanted to collect.

Download the csv file here.

If you want to include this list directly in your c# code – then grab this this file.

by Aage Andre

Mikrotik RouterOS – Conditional DNS-forward

One of the big pains of having a complete network of L2TP/IPSec-devices is that you have to have DNS servers at each site, or run a central DNS-server which could be slow to reach and the users start complaining about slow internet.
This is a simple config-script to allow you to run your central DNS only on internal domains, and everything else on.. well, any DNS you want.

Notes:
The script creates a new pre-routing connection-mark, checking if the DNS-lookup on the router, port 53 is looking for something with “yourdomain.local”. When it is, it DST-NATs and forwards the packet to your internal DNS without doing anymore processing.

It assumes you use the router/gateway as DNS-server with remote requests enabled in DNS-setup.

 

# The domain you want to be able to look up
:global DOMAIN
yourdomain.local  

# This is needed because the script won't allow a variable and a dash.. so no "$DOMAIN-forward"
:global CONMARK yourdomain.local-forward

# The LAN ip of your router
:global ROUTER 192.168.0.1

# The DNS-server where you look up "yourdomain.local"
:global DNSSERVER
1.1.1.10

 

/ip firewall layer7-protocol add name=$DOMAIN regexp=$DOMAIN
/ip firewall mangle add chain=prerouting dst-address=$ROUTER layer7-protocol=$DOMAIN action=mark-connection new-connection-mark=$CONMARK protocol=tcp dst-port=53
/ip firewall mangle add chain=prerouting dst-address=$ROUTER
layer7-protocol=$DOMAIN action=mark-connection new-connection-mark=$CONMARK protocol=udp dst-port=53
/ip firewall nat add action=dst-nat chain=dstnat
connection-mark=$CONMARK to-addresses=$DNSSERVER
/ip firewall nat add
action=masquerade chain=srcnat connection-mark=$CONMARK

 

 

by Andreas

Aborting AJAX requests in ASP.NET applications

imageI’ve been working on a pretty extensive web application lately, build on top of the .NET framework but with around 80% client side functionality (KnockoutJS, jQuery). There’s a lot of AJAX calls back to the server (naturally.. ) and one of the challenges I faced was that ASP.NET refused to navigate away from a page until all AJAX requests were processed. I did some searching and found out that an AJAX request could be aborted by adding some functionality to the window.onbeforeunload event:

 

By adding some logging to console I could clearly see that as soon as I clicked a link to navigate away this event was called and processed. But still nothing happened until the request had fully been processed – which made me think this had to do with the browser. Wrong assumption, and when writing this it seems very obvious to me why but then again retrospect is an ugly thing.

A bit more research and it turned out that this was all due to ASP.NET session state (which is enabled by default). Because of the session state my site serializes all requests within the same session, so the request for a new page would not be processed until the first one had completed. Turning session state off completely was out of the question, but by changing my .ashx handler (which receives all my ajax requests) to implement the IReadOnlySessionState interface rather than IRequiresSessionState there is no lock on the current session and concurrent requests are made possible.

Something to keep in mind though is that aborting an ajax request obviously doesn’t stop the server from processing it.

by Njål

Windows Azure SQL – Entity Framework 6 Retry Logic

 

One of the biggest drawbacks of using Azure SQL is that the connection towards the database is a lot more fragile and unstable than when you’re using a database server on your LAN. Also – your Azure database is running on servers with several hundred other databases – so the database server might disconnect you at any given time to ensure fairness of service etc.

These are transient errors – meaning that a retry of the query most often will succeed and fix the error.

Microsoft has released several code blocks and guidelines to help developers use this retry logic – http://code.msdn.microsoft.com/windowsazure/SQL-Azure-Retry-Logic-2d0a8401

And luckily – the EntityFramework team has added support for this in version 6 as well.

Here’s how you can get started with EF6 (beta 1) – using the built in SqlAzureExecutionStrategy

 

1. Install EF6 beta by opening the NUGET console in Visual Studio and typing
     PM> Install-Package EntityFramework –Pre

2. Install the EF6 Template generator – http://visualstudiogallery.msdn.microsoft.com/18a7db90-6705-4d19-9dd1-0a6c23d0751f. This will create the C# code for you – which will handle the communication towards the database

3. Restart Visual Studio

4. Add New Item  -> EDMX file. Connect to Database and/or specify your datamodel. Just like older versions of Entity Framework.

5. Right click in the EDMX editor – and select Add Code Generation Item. Select EF 6.x DbContext Generator.

6.
Compile. You should now have EF6 up and running. Only one crucial part missing – the Azure Retry Logic.

7. Add a class inside your Project with the following code. It will get picked up upon Application Start – and make sure that all the EF Database queries will be retried if they fail.

 

(The example provided here: http://entityframework.codeplex.com/wikipage?title=Connection%20Resiliency%20Spec does not work/compile)

by Joakim

JavaScript file missing from resource bundle (ASP.NET Web Optimization Framework)

I came across some odd behavior related to the Microsoft ASP.NET Web optimization Framework the other day, when I was creating a JavaScript resource bundle in an application I was working on. When I ran the website with optimizations enabled, the script file showed up as part of the bundle, but if I turned optimizations off the script include for the file in question was nowhere to be found.

For the application I was working on, which was only a proof of concept, I had simply copied the minified version of the JavaScript libraries I needed into the Script manually. I then included my libraries in a script bundle like so;

BundleTable.Bundles.Add(newScriptBundle(“~/bundles/jquery”).Include(“~/Scripts/jquery-1.8.2.min.js”));

If you have used this bundling functionality before, you probably know that if you include a JavaScript file in a bundle and you enable optimizations, the file will be minified and added to a single resource together with any other JavaScript files in the bundle. During the minification process the system will look for other files in the directory called exactly the same filename as the file in question only with .min.js at the end instead of only .js. If it finds a file like this, it assumes that this it is a pre-minified version of the file in question and uses it instead of minifying the original file.

However, if you add a file to your bundle that has a name that ends in .min.js (like I did) and optimizations aren’t enabled (e.g. debug is set to true in web.config and BundleTable.EnableOptimizations has not been set to true), this file will be ignored (i.e no script include will be generated for it in your html).

by Andreas

OWA in an iFrame – yes, it’s possible

imageMicrosoft is very clear on one thing when it comes to showing OWA (Outlook Web App) in an iFrame: it is not supported, and you’re on your own (unless you’re using their Sharepoint web parts).

That doesn’t mean it can’t be done, and if you’re happy with the light version (no right-click support, no custom toolbar items and probably other missing features..) it can be done as easy as displaying the following HTML page in an iFrame:

 

The javascript function is called during the body onload event with the mail server url and logon credentials. That’s it, works like a charm!

Now, to make this work for the full version OWA and get the right click support and other features just make sure the web site is running on the same domain as your Exchange server. If your web site is hosted on somesite.someserver.com, and your Exchange is running on mail.someserver.com you should be good to go – despite some console warning messages that so far haven’t proven to cause any issues for me at least. The only change to the above code is to set the “flags” attribute to 0 instead of 1, and this switches from “light mode” to “full mode” (see in-code comment).

by Andreas

Define a #Region in javascript files (Visual Studio 2010 / 2012)

In these times of super responsive client side processing mega javascript extravaganza web applications  you’re more than likely to end up with fairly large .js files in your projects. The standard code file in Visual Studio allows you to define collapsible sections by wrapping them with the #region / #endregion blocks. In javascript files however, you are restricted to collapsible functions only (“#region” is not recognized as anything valid):

image

Well, I just found out that that’s not entirely true. By marking a section of code (regardless of any logical blocks) and hitting CTRL + M + H you’ll define the selection as a region which is collapsible and expandable

image

by Njål

Quick row count from Microsoft SQL Database

 

Recently, I’ve been involved in a cloud provider project where I had to do a row count on a Microsoft SQL Database table with more than 50.000.000 rows in it.

Doing

took about 10 seconds – since it performs a full table scan.

 

Here’s an alternative way (still accurate) of doing it that takes under 1 sec:

 

You can run this from Microsoft Entity Framework as well:

by Njål

The directory specified for caching compressed content is invalid. Static compression is being disabled.

image

 

After adding this in my web.config (Azure Project)…

…IIS refused to serve any static content – such as js and png files. Log entries in Event Viewer said:

The directory specified for caching compressed content
C:UsersxxxAppDataLocaldftmpResourcesb503ce54-3fba-4772-beaa-415d94ffc214temptempRoleTempiisexpressIIS Temporary Compressed Files9ef2ab2d-28fc-4554-a09c-5ba867eb1d19 is invalid.
Static compression is being disabled.

The problem was that .svg files were already added to the staticContent list in my applicationHost.config – but still – the error message shown in the Event Viewer is pretty useless. There is nothing wrong with the directory specified to store compressed content.

So if you suddenly get this error – undo any changes in Web.config (remove all config under staticContent) and restart IIS (Express).