2

I've written and ASP.net MVC web application that needs to be installed as a "normal" application (or as close to it as possible). By which I mean, I need to have a "double click on exe file and the webappp opens in default browser" behavior, or as close to that as possible.

Being used to Java, I stupidly thought that I could use and embedded webserver to run it, but after a bit of research (correct me if I'm wrong here) it seems this cannot be done (only ASP.net Core can do that, but I'm using the traditional .NET Framework) and the web app needs to be run in either IIS or IIS Express.

So, after more research, this page:

https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-from-the-command-line

seems to suggest that launching a site from a specific folder via IIS Express is possible, by using a command like:

iisexpress.exe /path:"C:\Program Files\MyWebsite\bin"

where the path above contains my compiled ASP.net MVC website.

This, however, doesn't seem to work. When I issue that command I get the following output:

c:\Program Files\IIS Express>iisexpress.exe /path:"C:\Program Files\MyWebsite\bin"
Copied template config file 'c:\Program Files\IIS Express\AppServer\applicationhost.config' to 'C:\Users\MyUser\AppData\Local\Temp\iisexpress\applicationhost20179188941639.config'
Updated configuration file 'C:\Users\MyUser\AppData\Local\Temp\iisexpress\applicationhost20179188941639.config' with given cmd line info.
Starting IIS Express ...
Successfully registered URL "http://localhost:8080/" for site "Development Web Site" application "/"
Registration completed
IIS Express is running.
Enter 'Q' to stop IIS Express

So basically IIS Express starts, but it's not running my website from the folder I specified, it runs some (presumebly) default empty website, called "Development Web Site". I checked some urls, and I can confirm that is not my website, but just an empty shell with no pages or anything else.

What am I missing here? How do you start a website in IIS Express via command line? Do I have to "register" the website first somehow?

EDIT: After a bit more research, I found out I can register a website explicitly by doing:

appcmd.exe add site /name:MySite /physicalPath:"C:\Program Files\MyWebsite\bin" /bindings:http://localhost:8081

and then start it with:

iisexpress.exe /site:MySite

This however doesn't solve the problem: when I browse to the website via browser all I get are 404 errors, there's no content at all.

One thing I also must point out: since an ASP.net website is compiled into a DLL file, I don't understand how simpy registering/starting it using a path to a FOLDER would work... how would IIS Express understand which DLL to load the site from? Seems like there are some crucial pieces missing here...

4
  • You can look at this doc: learn.microsoft.com/en-us/iis/extensions/using-iis-express/…. By default IIS Express uses configuration in applicationhost.config, change the configuration using given switches. Commented Sep 18, 2017 at 8:21
  • @TetsuyaYamamoto: thanks, but is there any tutorial/example of how to write such a configuration file? I've had a look at the default one and it's gigantic! I've no idea how to start creating my own... any pointers? Commented Sep 18, 2017 at 8:37
  • 1
    Follow the instructions on these articles: learn.microsoft.com/en-us/iis/get-started/… & learn.microsoft.com/en-us/iis/get-started/…. The given resources are plenty enough to build your own applicationhost.config file. Commented Sep 18, 2017 at 8:47
  • @TetsuyaYamamoto: thanks for the link, upvoted. Although I didn't need it in the end, it seems my initial approach was working, I was just pointing to the wrong path (see my answer below) Commented Sep 18, 2017 at 9:13

1 Answer 1

4

After further tinkering, I figured it out. I was pointing to the /bin directory of the website. Instead, you have to point to the parent directory, the one that contains the Web.config file.

So, in my case, I changed:

iisexpress.exe /path:"C:\Program Files\MyWebsite\bin"

to:

iisexpress.exe /path:"C:\Program Files\MyWebsite"

and now it works correctly

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.