41

This has been asked before but was closed as "Not a real question"

https://stackoverflow.com/questions/7450813/how-to-run-a-site-with-administrative-privileges-in-iis-express-7-5

However I think it is a genuine question as I also need to do this, there are MS documents explaining how to "Run IIS Express without Administrative Privileges" but as this is how it runs by default the need for this article quite frankly baffles me. However I have no idea on how to run it with Admin privileges.

When I try to start my VS2012 website I get the following error message from IIS express: "Cannot start the website because administrative privileges are required to bind to the hostname or port", and links are provided to the MS documents about running it without admin privileges.

What I'm ultimately trying to do is run my dev sites locally as http ://vs2012:nnnnn, this is so I can attach fiddler debugger (due to the bypass of proxies in IE when localhost is used)

This used to work fine, this morning I did a reinstall of windows and have now hit a brick wall!

Does anyone know how to give IIS express admin privileges as indicated in the error message?

Yahoo Serious
  • 3,728
  • 1
  • 33
  • 37
Morvael
  • 3,478
  • 3
  • 36
  • 53

14 Answers14

68

For Visual Studio 2015 and 2012 this solution will work.

  1. Go to Solution Explorer in Visual Studio, right click the web project and select "Unload Project"
  2. Next on the same project, right click and select ‘Edit Project File‘
  3. Find the
    <DevelopmentServerPort>0</DevelopmentServerPort><IISUrl>http://localhost:56058/</IISUrl>
    xml tags and and remove them.
  4. Reload the project and run.

Images to follow:

enter image description here

Undo
  • 25,519
  • 37
  • 106
  • 129
Charitha Goonewardena
  • 4,418
  • 2
  • 36
  • 38
27

I've worked it out.

I switched Visual Studio to running with Administrative Privileges and also found the .exe for IIS Express and set that to always run with administrative privileges. I'm not 100% sure the second was needed but did them both anyway.

I hope this helps some one else who's had this same issue.

EDIT

(19/08/2013)

This only seemed to work in Windows 7, On Windows 8 I eventually just gave up and now use the full blow IIS for all my dev work.

EDIT

(07/06/2018)

@Tarostar (Comment below), got this working on Windows 10 VS2017 and a number of others have got it to work on Windows 8 prior to that using the same method. So possible I was doing something wrong on my Windows 8 box.

Morvael
  • 3,478
  • 3
  • 36
  • 53
  • 7
    Just to clarify, I only needed to ensure VS was running as Administrator and it worked. – moribvndvs Apr 03 '13 at 21:05
  • 12
    Maybe this can save some time, my IIS Express is located here: `C:\Program Files (x86)\IIS Express\IISExpress.exe`. – Yahoo Serious Apr 12 '13 at 11:40
  • Confirming that this works in Windows 8 for Visual Studio 2013 - I ran VS as Administrator and IIS Express was automatically elevated as well. – Nick Coad Dec 03 '14 at 02:45
  • This worked for me on Windows 8.1, but I needed to at a Firewall rule that allowed connection from my LAN. Only then I could connect to the server. – Raphael Ahrens Jan 12 '15 at 13:05
  • Running Visual Studio as admin (right click menu) solves the problem as described before the edit as per June 2018 with Win10 and VS2017, all patched with the latest. I got "iis express cannot start the website because administrative privileges are required to bind to the hostname or port" when I needed to map localhost to a domain name in the hosts file in order to debug a cookie issue. As this is a .net core 2.0 project I specify the hostname in the applicationUrl in launchSettings.json. Thanks to Morvael for figuring it out (but you should probably remove the edit). – Tarostar Jun 06 '18 at 09:01
11

In my case, the site was working without admin privileges and at some point stopped and worked only with admin.

Port number was higher than 1024 which does not require admin privileges, but Visual Studio 2015 refused to run a site without admin permissions.

I figured out that, it was because of it was added in

netsh http show urlacl

which showed me

Reserved URL            : http://*:15888/
        User: \Everyone
            Listen: Yes
            Delegate: No
            SDDL: D:(A;;GX;;;WD)

So for my case, I have removed it from this list and it worked again. Here is the command for removing:

netsh http delete urlacl http://*:15888/
6

Although a bit late, and not an answer to the asked question 'how to run with administrative privileges', this might be a solution to the stated problem/error:

Cannot start the website because administrative privileges are required to bind to the hostname or port

As mentioned in running-iis-express-from-the-command-line, the port number used may require these administrative privileges:

you must have Administrator user rights if you want to run IIS Express on ports numbered 1024 or less.

So if you could run on a port number higher than 1024, you might not need administrative privileges at all.

Yahoo Serious
  • 3,728
  • 1
  • 33
  • 37
  • 2
    Unfortunatly if you don't want to bind your website to localhost you always need Administrator user rights, regardless of the chosen port number. – Aurril Jul 09 '13 at 07:38
  • @Aurril: Thanks for the info. Is this valid for all 'external' bindings, even if you use local addresses, like the local IP-range? Do you have a reference/link, I can add to the answer? – Yahoo Serious Jul 09 '13 at 14:18
  • As far as I recall, all adresses outside the 127/8 block will require admin privileges. See http://www.iis.net/learn/extensions/using-iis-express/running-iis-express-without-administrative-privileges section "RUNNING SITES LOCALLY". – Aurril Jul 10 '13 at 07:22
6

This is not a way to give admin privileges to ISS but a solution to error in the post. I started seeing this error one morning, and solved this by closing Mobile hotspot of my computer. Apparently something about sharing your internet with other devices might result in "Can not start the website because administrative privileges are required to bind to the hostname or port" error.

numan
  • 71
  • 1
  • 4
4

1)find CSPROJ file. which is inside your project file 2)CSPROJ File is open in notepad(Drag to notepad) 3)search two line (by press Ctrl+F and type frist words eg:)

<DevelopmentServerPort>0</DevelopmentServerPort>
<IISUrl>http://localhost:57680/</IISUrl>

4)DELETE two line. 5)save the CSPROJ file .

shebin c babu
  • 1,069
  • 8
  • 7
2

I know it might be too late but none of the other work arounds worked for me. So this is what I did. I'm using Web API 2 and the IIS Express didn't fire up from time to time and after I would load the project in a new solution it would work. However, I found a better solution. In the csproj file remove these two nodes under WebProjectProperties and you will be all set.

  • DevelopmentServerVPath
  • IISUrl
Daniel
  • 3,322
  • 5
  • 30
  • 40
2

I solved (worked around) this error by just turning off my VPN.

Not sure why having the vpn running was causing the error, "Cannot start the website because administrative privileges are required to bind to the hostname or port".

Andrew
  • 18,680
  • 13
  • 103
  • 118
1

this worked for me!

In VS you can right click the project, select Unload Project, and then right click again and select Edit ProjectName.csproj.

Remove the DevelopmentServerPort and IISUrl tags.

After that, you can right click the project and select Reload Project to start working again. Removing the DevelopmentServerPort and IISUrl tags causes VS to re-generate a port number and the project works well after that.

Another thing I did was to open my Documents\IISExpress\Config\applicationHost.config file and delete the old sites, but I’m not sure it was necessary

Anil P Babu
  • 1,235
  • 3
  • 26
  • 47
  • Credits : http://geekswithblogs.net/WinAZ/archive/2014/09/11/binding-failure-error-ndash-cannot-start-the-website-because-administrative.aspx – Oswin Sep 22 '16 at 07:49
1

One small addition to the method suggested by Morvael - even if you are getting the error after assigning admin privileges to Visual Studio and IISExpress, try restarting the system after that. Worked for me.

WaughWaugh
  • 1,012
  • 10
  • 15
0

You can alter the file at:

%userprofile%\Documents\IISExpress\config\applicationhost.config

Go to this part of the file:

<system.applicationHost>
     <applicationPools>
          <applicationPoolDefaults managedRuntimeLoader="v4.0" >

And add a tag for your application pool specifying the username and password it should run under:

<processModel userName="Uname" password="Pword" />
vulcan raven
  • 32,612
  • 11
  • 57
  • 93
Louis Somers
  • 2,560
  • 3
  • 27
  • 57
0

Chiming in from 2018...I was having this problem on VS 2017 and getting the same error message. To fix it, I changed my Project Url in the project configuration from http://localhost:10243 to http://localhost:10244. Once I confirmed that I wanted to create the virtual directory, I was able to launch my project in the browser. I am NOT running VS in admin mode. Hope this helps!

midoriha_senpai
  • 177
  • 1
  • 16
0

I ended up solving this issue by right clicking on Visual Studio and clicking 'Run as administrator'.

user2531854
  • 856
  • 3
  • 13
  • 32
0

Want to keep URL and not use admin privileges?

Receiving a new URL is not always desirable, for example when there are other applications using the web app as service under the given URL. What helped me in this case was to remove all contents under:

%userprofile%\Documents\IISExpress

and restart.

Why you should not use admin privileges?

In short: Running programs with admin privileges poses a security risk and should be avoided if possible.

from: https://learn.microsoft.com/en-us/visualstudio/ide/user-permissions-and-visual-studio?view=vs-2022 literally the first sentence:

For reasons of security, you should run Visual Studio as a typical user whenever possible.

from: https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/handling-url-binding-failures-in-iis-express

This occurs because IIS Express does not have sufficient privileges to perform these types of tasks. You can run IIS Express as an administrator to bypass these restrictions, but this is not a good practice for security reasons.

Why you still might need to use admin privileges?

Also from: https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/handling-url-binding-failures-in-iis-express

Administrative privileges are required in order to perform the following tasks:

  • Use a reserved port such as 80 or 443.
  • Serve requests for external traffic.
  • Configure a custom SSL certificate.
  • Run SSL using a port outside the range of 44300 to 44399.
bTab
  • 199
  • 2
  • 12