Thoughts, tips, and tricks on software development. .NET | C# | Azure
05 October 2017
In this post we are going to see how to deploy a web application on your development machine. The end goal is to have a web application running on the development machine outside of the context of Visual Studio and which is accessible to other devices on a local network.
Before we get started, we need to make sure that IIS is installed on our machine. Here are the steps to do that in Windows 10:
Now it’s time to deploy the web project. What will happen is that we will copy the files and folders that are necessary to run the solution to a separate folder that IIS knows about. After some configuration, IIS will take care of making the web application accessible even without Visual Studio.
There are two parts to the equation: first is setting up IIS, and second is publishing from Visual Studio.
Here are the steps to set up IIS:
We are now ready from the IIS side of things. Next, we need to copy our project files over to the folder we just created. That can be done manually or through the Visual Studio publishing functionality.
Here are the steps to publish to IIS through Visual Studio:
You can now browse to the site by opening a browser and typing http://localhost:[portNumber]/, where [portNumber] should be replaced by whatever port number you put in during IIS setup. If you did not change the port number, you can leave this blank.
The next time you Publish through Visual Studio, you will no longer see the setup window. Visual Studio will remember your settings and you can publish by clicking on the Publish button.
Here are some common IIS errors and how to solve them. I will update this list as I remember or encounter more errors:
Detail: The requested page cannot be accessed because the related configuration data for the page is invalid.
Look at the config error and follow the appropriate solution:
Config error: This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=”Deny”), or set explicitly by a location tag with overrideMode=”Deny” or the legacy allowOverride=”false”.
Solution: Open the “Turn Windows features on or off” window. Go to Internet Information Services > World Wide Web Services > Application Development Features. Check all except CGI and click OK.
A couple of things to look at here.
First, make sure that the image is included in the Visual Studio project before publishing. That is to say, that the image file is visible on Solution Explorer inside the appropriate folder. During development, the images will show just fine even if they’re not included in the Visual Studio project, as long as they exist on the file system. But during publishing, Visual Studio will only copy over files that are included in the project, and any images that are not part of the project will not get copied over.
Second, make sure that all references to images are relative paths, and not absolute paths.
Now we have a web app that can be accessed on a browser without Visual Studio. We can take this step further by making the web app available over our local network. This is useful in scenarios involving mobile development, where you want to see how your website looks on an actual mobile device or you want to test access of Web API calls.
Here are the steps to do that in Windows 10:
At this point, the web app should be accessible over the network. On another network computer, open a browser and go to the address http://[hostIPAddress]:[portNumber], where [hostIPAddress] is the IP address of the computer hosting the application and [portNumber] is the port number you used during IIS setup.
To obtain the host computer’s IP address, open a command prompt on the host computer and type ipconfig. Look for the IPv4 address. There may be multiple IPv4 addresses; which one is correct depends on your network configuration.
In this post we looked at how to deploy a web application to your development machine. The operating system is Windows 10 and the Visual Studio version is 2017. The end goal was that we had a web app running standalone, meaning it could be accessed even if Visual Studio was closed. We also made the web app accessible from other devices on the same network.