Lance Larsen - .NET Architect Madison Wisconsin

All posts in .NET

Needed to add MP4 video support to an ASP.NET website project. 

Found that adding the following made that work great when I deployed to Azure.

<!-- ====================================================================== -->
<!-- Required to have Videos show up when deployed to Azure  -->
<!-- ====================================================================== -->
<staticContent>
  <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
</staticContent>

Alas, when I refreshed the cache on my browser – all of my CSS and Javascript files would not load, with the dreaded 500 errors.

So apparently, as soon as you add any <staticContent> settings – you need to add all possible settings.  Counter intuitive, so wanted to share the a comprehensive non-trivial fix that worked for me.

If there’s a better way to do this – love to hear it…  Also may be a better way to do this in ASP.NET Core – but for now this is a pre-Core project.

Here’s the solution, hope it helps someone else.  Good coding :)

<!-- ====================================================================== -->
<!-- Required to have Videos show up when deployed to Azure  -->
<!-- ====================================================================== -->
<staticContent>
  <!-- Set expire headers to 30 days for static content-->
  <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00"/>
  <!-- use utf-8 encoding for anything served text/plain or text/html -->
  <remove fileExtension=".css" />
  <mimeMap fileExtension=".css" mimeType="text/css; charset=UTF-8" />
  <remove fileExtension=".js" />
  <mimeMap fileExtension=".js" mimeType="text/javascript; charset=UTF-8" />
  <remove fileExtension=".json" />
  <mimeMap fileExtension=".json" mimeType="application/json; charset=UTF-8" />
  <remove fileExtension=".rss" />
  <mimeMap fileExtension=".rss" mimeType="application/rss+xml; charset=UTF-8" />
  <remove fileExtension=".html" />
  <mimeMap fileExtension=".html" mimeType="text/html; charset=UTF-8" />
  <remove fileExtension=".xml" />
  <mimeMap fileExtension=".xml" mimeType="application/xml; charset=UTF-8" />
  <!-- HTML5 Audio/Video mime types-->
  <remove fileExtension=".mp3" />
  <mimeMap fileExtension=".mp3" mimeType="audio/mpeg" />
  <remove fileExtension=".mp4" />
  <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
  <remove fileExtension=".ogg" />
  <mimeMap fileExtension=".ogg" mimeType="audio/ogg" />
  <remove fileExtension=".ogv" />
  <mimeMap fileExtension=".ogv" mimeType="video/ogg" />
  <remove fileExtension=".webm" />
  <mimeMap fileExtension=".webm" mimeType="video/webm" />
  <!-- Proper svg serving. Required for svg webfonts on iPad -->
  <remove fileExtension=".svg" />
  <mimeMap fileExtension=".svg" mimeType="images/svg+xml" />
  <remove fileExtension=".svgz" />
  <mimeMap fileExtension=".svgz" mimeType="images/svg+xml" />
  <!-- HTML4 Web font mime types -->
  <!-- Remove default IIS mime type for .eot which is application/octet-stream -->
  <remove fileExtension=".eot" />
  <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
  <remove fileExtension=".otf" />
  <mimeMap fileExtension=".otf" mimeType="font/otf" />
  <remove fileExtension=".woff" />
  <mimeMap fileExtension=".woff" mimeType="font/x-woff" />
  <remove fileExtension=".crx" />
  <mimeMap fileExtension=".crx" mimeType="application/x-chrome-extension" />
  <remove fileExtension=".xpi" />
  <mimeMap fileExtension=".xpi" mimeType="application/x-xpinstall" />
  <remove fileExtension=".safariextz" />
  <mimeMap fileExtension=".safariextz" mimeType="application/octet-stream" />
  <!-- Flash Video mime types-->
  <remove fileExtension=".flv" />
  <mimeMap fileExtension=".flv" mimeType="video/x-flv" />
  <remove fileExtension=".f4v" />
  <mimeMap fileExtension=".f4v" mimeType="video/mp4" />
</staticContent>

imageWe live in AWESOME times… Hololens + new Mixed Reality Headsets, oh my!

To develop for each of those, you need to keep up with the latest and greatest Unity Betas – download them here…

Want to save my fellow Holonauts some time – if you come across the curious problem where when you go to build and run – you’ll now see that the “Unity C# Projects” checkbox is disabled?!?  That’s not right…

The solution to this is to…

1) Open “Player Settings”
2) Expand “Other Settings”
3) Find “Scripting Backend”
4) You’ll see that the default is now “IL2CPP”, change that to “.NET”

Now your “Unity C# Projects” is re-enabled!

Enjoy and go build some awesome Mixed Reality Apps!

image


imageGreetings my Geeks – we have a lot of awesome ASP.NET Core 2.0 news coming out lately…

As always, sharing is caring – so here you go.

Today – after publishing to Azure – ran the default “Register” user page – and got the error message…

Swapping to Development environment will display more detailed information about the error that occurred.

Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.

imageSo did a search for “ASPNETCORE_ENVIRONMENT” – and found the only references in my project were already set to “Development”…  so that wasn’t it…

imageEventually found a clue that that mentioned Azure App Settings – and yup – that’s where this needs to be set.

So click on your Web App –> Applications Settings –> go down to the “App Settings” section and add the “ASPNETCORE_ENVIRONMENT” and “Development” as displayed in the screen shot.

Now you’ll get the error messages as if you were running it locally – and that should help you resolve your issues.

REMEMBER – before you go to use this in production – revert that change.  Don’t want the bad guys to be able to see any error details.

Good coding!

Note: Valid values for “ASPNETCORE_ENVIRONMENT” are “Development”, “Staging” and “Production” – if you have something that’s not one of those, you may get odd behaviors… :)



imageI’m excited to start sharing a lot of research I’ve been doing for my upcoming Hololens development talks…

“Augmented Eyes = Azure Cognitive Services + Hololens”

Where to get started?

Note – everything I’m using including Azure and the Cognitive Services is free, no cost – so don’t hesitate to follow along and get everything setup!  My hope is that you’ll do some really cool stuff and “share-it-back” to our community. :)

1) If you don’t have one – you can sign up for a Free Microsoft Azure Account.

2) Once you have that, login to your Azure Portal.

image

Read more


So pleased that I’ve been able to share the experience of a HoloLens with well over 2000+ people just since //BUILD/ this spring – with likely 1000+ actually being able to experience the amazing view for themselves! (especially demoing four of them at once for 16+ hours at That Conference, the official Summer Camp for Geeks!)

So, now what?  We know what the HoloLens can do…  We know how to “bloom” and “click” – we know the amazing tech specs – we know that RoboRaid is one of the best games of all time – what next?  Simple – HoloLens 201 Tour is in the works!

imageBuilding the Age of Experiences: Hololens + IoT

The Information Age has Evolved, Welcome to the Age of Experiences!

We are living through another critical stage in the evolution of technology, we are at the very beginning of looking at our world through augmented eyes.  We –  and those that follow us — will no longer be satisfied with looking at a flat computer screen at our desks, or even on our mobile devices.  We will come to expect and demand to be immersed within our environment with but a single glance through augmented eyes.

Join Lance Larsen as we explore the technologies that are enabling the Age of Experiences, and how we as developers can unite both the Hololens, IoT devices and sensors to usher in the new age!


imageFYI – here’s a trick so we don’t need to specify our local computer’s name in our web.config connectionString – because if you have multiple developers working on the same code – they each have to have different web.config versions with their individual computer names.

Generally we see…

<connectionStrings>
     <add name=”MyContext” connectionString=”Data Source=MYCOMPUTER; Initial Catalog=MyDatabase; Integrated Security=True; MultipleActiveResultSets=True” providerName=”System.Data.SqlClient” />
</connectionStrings>

What we want…

<connectionStrings>
    <add name=”MyContext” connectionString=”Data Source=.; Initial Catalog=MyDatabase; Integrated Security=True; MultipleActiveResultSets=True” providerName=”System.Data.SqlClient” />
</connectionStrings>



How?

1) Open your “Sql Server Configuration Manager” application.
2) Expand your “Sql Server Network Configuration”.
3) Right-click on “TCP/IP”.
4) Scroll down to “TCP Dynamic Ports” (which will be blank by default) and enter “0” which enables it. 
5) Restart your SQL service and you’re DONE!

Thanks Travis Feirtag (@therobotgeek) for this trick!


( Download Code )

Was looking for a simple and elegant way to log some metric for methods (mainly method name, start time, stop time and elapsed time) – I’ve done this in PostSharp in my article “Holy Grail of Application Profiling with AOP” – but client wasn’t using them.

I’ve used reflection with success in the past, but was having some issues with Async methods not giving their real method names, was getting “MoveNext” instead — so sleuthed around for an alternative and found some awesome C# attributes that I’d never seen…

[CallerMemeberName] – gets the method name calling the attribute
[CallerFilePathAttribute] – gets the path to the C# file
[CallerLineNumberAttribute] – gets the line of the method in code

Combining those with the C# Stopwatch Class – and using the Dispose patter that I love because you can easily code the “using” statement around what you’re looking at ( see below ) – came up with the following cool code that – as always – I love to share.

Emphasis on elegant, to call this code – you can easily do the following…

using (StopwatchLog.Track())
{
   // Your code here...
}

It collects the information about executing method and logs metrics when the stopwatch log is disposed.

Read more


Event

Dates

Location

Chicago Code Camp

April 26

Grayslake, IL

Kalamazoo X

April 26

Kalamazoo, MI

Azure Developer Camp

April 30

Chicago, IL

ALM Chicago

May 1

Chicago, IL

Virtual Hackathon

May 1- June 5    

Chicago and online

VSLive

May 5-8

Chicago, IL

Code For Rockford Brigade Kickoff

May 10

Rockford, IL

//PUBLISH Hackathon

May 16-17

Chicago, IL

//PUBLISH Hackathon – Milwaukee     

May 16

Milwaukee, WI

SharePoint Saturday

May 17

Addison, IL

GoTo Conference – Chicago

May 20-23

Chicago, IL

Codestock

July 11-12

Knoxville, TN

Iowa Code Camp

July 19

Des Moines, IA

That Conference

August 11-13

Wisconsin Dells, WI

Madison Ruby

August 21

Madison, Wi

Devlink

August 27-29

Chattanooga, TN

Chippewa Valley Code Camp

Fall

Thanks to David Giard {djgiard@hotmail.com} for compiling these!


imageAt the February 2014 MADdotNET (@maddotnet) meeting – had David Manske (@davidemanske) from Centare out to talk on what’s new in Visual Studio 2013!  Couple absolute gems of knowledge were passed on – one of them was “SideWaffle Templates for Visual Studio” – I had never seen this – so figure some others may not have seen this either!

Specifically liked seeing the AngularJS templates… Check them out!


Always loved JavaScript and client side scripting ( where appropriate <grin> ) – so when we had a new green field project to start, looked to what the best-in-class technologies were – settled on AngularJS (@angularjs). 

It is a client-side MVC (Model-View-Controller) pattern and it rocks for making SPA (Single-Page-Applications) that emphasize responsiveness.  Take a look at either the AngularJS site, or there are a couple great AngularJS videos on Pluralsight – specifically “AngularJS Fundamentals” and “AngularJS for .NET Developers”.

I know that I have a ton to learn about AngularJS – and wanted to share what I’m learning along the way…

Specifically, have a page that has a list of items to be displayed – and want to filter them by a parameter based on what the user clicked.  So in AngularJS we can separate showing the items to be displayed into one controller – the “CollectionController” – and the filters to be applied into another controller – the “FilterController”.  Found many examples / discussion on how to communicate between the controller, but some seemed to be way overkill or confusing – so got the following code crafted – and wanted to share as it turned out pretty slick! :)

To boot, have the live code running on JSFiddle – which again, if you haven’t played with is WAY awesome!

http://jsfiddle.net/lancelarsen/qjkyM/

Read more