IIS Express GUI

Looking for a admin GUI so I can start/stop IISExpress websites I quickly found iisexpressgui on codeplex/ which is by Matteo Tontini and iis express manager. They both do pretty much the same thing. They also both only pick up only the first binding for a site, so if you've got two -- for instance one for http and one for https -- then you might need to edit your %Documents%\IISExpress\config\applicationhost.config to choose the one you want to use.

Mono MVC System.UnauthorizedAccessException Access to the path “/Library/Frameworks/Mono.framework/Versions/…/etc/mono/registry” is denied

Is an error you are likely to see if you run a Visual Studio MVC template in Mono. There are two options for fixing it.

  • Do this from the command line:
    sudo mkdir /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry
    sudo chmod g+rwx /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry

    (replacing 3.2.5 with your mono version, which you get at the command line with mono --version)

  • Or delete the reference to Microsoft.Web.Infrastructure.dll from the project and delete it from the bin directory too.

The important difference is that deleting Microsoft.Web.Infrastructure.dll will stop your project working on .Net, so the registry access is simpler for cross-platformers. Another option for cross-platform project files would be something like this in the .csproj file:

<Target Name="AfterBuild">
    <Delete Files="$(WebProjectOutputDir)\bin\Microsoft.Web.Infrastructure.dll" Condition=" '$(OS)' != 'Windows_NT'" />
  </Target>

I prefer the 'grant access to the registry approach' myself but it does mean having to re-run the 2 line script for every new version of mono.

Visual Studio Template ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588

If you use the VS template to create a new 'internet' web application, then the template includes code for Asp.Net simple membership. But the template is written for SqlExpress. If you instead have a full SQL Server install on your machine it won't work.

The first exception you might see when debugging in visual studio is,

Exception has been thrown by the target of an invocation.

or if you aren't debugging you might see

The system cannot find the file specified

neither of which help at all.

so first, change the connection string in web.config to use your local SQL Server:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication1-20140225162244;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication1-20140225162244.mdf" providerName="System.Data.SqlClient" />

changing the connectionString's Data Source property to Data Source=.;

Now you might get the same or a different exception message:

The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588

but the linked page doesn't tell you how to fix it.

The inner exception is more helpful:

Directory lookup for the file "c:\...etc...\MvcApplication1\App_Data\aspnet-MvcApplication1-20140225162244.mdf" failed with the operating system error 5(Access is denied.).
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

Which tells you that the login account under which SQL Server is running doesn't have write permissions to the directory in which you write you code. It does have write permissions in the SQL Server data directory, for instance C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA so you'd think that by looking at that directory to see what user it runs under you'd be able to give it permissions.

Almost. The Explorer GUI Security tab showed me a usergroup called 'MSSQLSERVER' but if you try to give permissions to that group you'll find it doesn't exist. More helpful is the command line:

cacls "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL"

which, if you look carefully at the output,

C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL 
    CREATOR OWNER:(OI)(CI)(IO)F
    NT AUTHORITY\SYSTEM:(OI)(CI)F
    BUILTIN\Administrators:(OI)(CI)F
    BUILTIN\Users:(OI)(CI)R
    NT SERVICE\MSSQLSERVER:(OI)(CI)R

shows you that you the actual name is NT SERVICE\MSSQLSERVER

So I gave modify permissions on my App_Data directory to NT SERVICE\MSSQLSERVER (I carefully copy-pasted the full name) and it worked.

Serving Asp.Net MVC4 pages on Mono with xsp. That is, with xsp4

I couldn't see why the command-line xsp command didn't work until I realised there is an not-very-well-advertised xsp4. At which point I guess the 2 in xsp2 means .Net 2 rather than, say, xsp version 2. So now I know that:

To run an Asp.Net 4 or 4.5 web application you need xsp4; whereas to run an Asp.Net 2 (or 3 or 3.5) app you need xsp2.

man xsp4 returns nothing, but the switches all seem to be the same as you'll find with man xsp. So to run your MVC4 web app from the command line, cd to the web app directory and just run xsp4.