Tuesday, 26 June 2018

Querying an IIS Express site over the LAN

Open this file:


Add this row to the bindings element

<binding bindinginformation="*:yyyy:xxx.xxx.xxx.xxx" protocol="http" />

where yyyy is your chosen port number and xxx.xxx.xxx.xxx is IP address on your network.

Run these two commands in a admin cmd prompt

netsh http add urlacl url=http://xxx.xxx.xxx.xxx:yyyyy/ user=everyone

netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=1914 profile=private remoteip=localsubnet action=allow

Tuesday, 20 February 2018

EF edmx update wizard not responding when updating models from SQL Server 2017

Recently when updating my db-first edmx from my SQL Server 2017 database, the update wizard would hang. I overcame this problem by temporarily changing the compatibility level of the db to 2012 like so:

So far this seems to have no ill-effects.

Saturday, 3 February 2018

Completed 406 Not Acceptable with Devise

I had some trouble after an update of ruby/rails/gems on a something I hadn't worked on for ages. When register a user with Devise it would error with a Completed 406 Not Acceptable with Devise
As usual Stack Overflow came to the rescue, where I found this: "Devise responding to json by default has been removed from version 2.2" The fix was simple, I added this to my confif/application.rb and everything was working fine again:

config.to_prepare do
      DeviseController.respond_to :html, :json

Monday, 22 January 2018

C# casting from parent to child object

For some reason I've never had to do this before (not that I can remember anyway), and it feels like I should have. I have a Child object that inherits from Parent. I want to turn an instance of a Parent object that I already have into a Child. I thought this might just be a simple cast but it doesn't work.

This SO post  was most helpful, and the neatest solution seemed to be this technique, serializing to json, and then back again:

 var serializedParent = JsonConvert.SerializeObject(parentInstance); 
 Child c  = JsonConvert.DeserializeObject(serializedParent);

Tuesday, 5 December 2017

Rebuild all indexes in your database


Wednesday, 4 October 2017

Global error handling in filter attribute MVC Web api

When I inherited the first skeleton iteration of the api I'm working on every action was populated with largely repeated code whose function was to capture and log errors. I centralized all this into an attribute filter class called GlobalExceptionFilterAttribute, inheriting from ExceptionFilterAttribute, that looks a bit like this:

And then applied it to all actions with this line in WebApiConfig.cs:
config.Filters.Add(new GlobalExceptionFilterAttribute());

Then, throughout the app, we can throw different types of error pretty much anywhere and this will ultimately be captured by the filter attribute. So, for instance most of my service layer methods look like this: