Configure Namespace Reservation

When you try to run your server outside of Visual Studio or Visual Studio Code, you might see an Access Denied exception occur. This will happen when not use a localhost or loopback IP address without either running the app as an administrator or configure namespace reservations for your URI.

tip

For development purposes, assuming you are an administrator on your local Windows instance, you can simply run your IDE or command line as administrator.

Configure Namespace Reservations#

For obvious reasons, counting on your application to be running under an admin account in production is unwise. In these instances, you'll want to configure a namespace reservation.

These reservations can be made by using the netsh utility command add urlacl.

$ netsh http add urlacl url=http://+:1234/ user=DOMAIN\user

It's important that the value of the url argument is an exact match with a prefix added to the server, or the exception will still be thrown.

server.Prefixes.Add("http://+:1234/");
note

This documentation does not cover Windows operating systems earlier than Vista. For help with XP or Server 2003, see the documentation for Httpcfg.