I have created a simple website (about 100 pages, but no databases or other fancy features) in .NET Core 1.0 and upon publishing it on my hosting provider’s server I find that it is having trouble consistently loading its pages correctly. I am reaching out to this forum because neither I nor my hosting provider can identify the source of the problem, and I am unable to find anything in the .NET Core documentation that addresses it.
I apologize for the length of this post, but I hope by providing the full story I will make my questions easier to answer.
My development computer is a Mac running OS X El Capitan. I began by downloading and installing .NET Core and Visual Studio Code. I then used Yeoman to create a web application with the following specifications:
?What type of application do you want to create?Web Application Basic [without Membership and Authorization]
?Which UI framework would you like to use?Bootstrap (3.3.6)
?What's the name of your ASP.NET application?MW356
From there, development was a simple matter of replacing the sample application’s views, controllers, and static files with new ones, and using dotnet restore and dotnet run to test the app locally. Because my website did not require logging, error reporting, or the use of environment variables, I removed the references to those things from my_layout.cshtml, project.json, program.cs and startup.cs files. (I wonder now if I may have removed too much; more on that below.) All this was done without apparent incident, and the app ran just fine on my Mac.
It was then time to publish the site, which is a replacement for an old version with the same URL that was hosted by a provider who does not support .NET Core. I contracted with a new company (new to me, that is) that bills itself as “Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States” for a hosting plan that promised to meet my requirements. According to their help desk, the server is running IIS 8.5 on Windows Server 2012 R2 64-bit.
Neither my hosting provider’s help desk personnel nor the .NET Core documentation I was able to find online could provide answers to what seemed to me to be the natural questions I faced at that point, namely how exactly I should publish the app locally and which files I should upload to the host afterward. My new hosting provider could only say, publish your project and upload your files to us. (When I asked how to publish, they said “Push the Publish button in Visual Studio,” and when I asked which files I should upload, the answer I got was “All of them.”) Unable to find any specific guidance, I took a guess: I randotnet publish (without specifying any options) on the Mac and uploaded the contents of my project’s /bin/Debug/netcoreapp1.0/publish folder to the host. They took it from there, setting up the site under a temporary IP address because my domain name was still registered to the old hosting provider. The site appeared to run perfectly, so I went ahead and arranged to have the domain name, www.midwest356.org, transferred to the new host. And that is when things went bad.
No sooner had that been done than the site began intermittently failing to load, both on my own devices and on those of my users, including Macs, Windows PCs, iPhones and Android phones running a variety of browsers. Sometimes it loads properly. Sometimes it fails with a message along the lines of this one that I get on my Mac: Safari can’t open the page “localhost” because the server unexpectedly dropped the connection. This sometimes occurs when the server is busy. Wait for a few minutes, and then try again. And sometimes it loads the page partially, failing to load one or more image or CSS files, so that the page comes up missing some images and/or its Bootstrap navigation bar.
This happens unpredictably. A page can load correctly and then fail to load seconds later when a refresh is attempted. Some users report never having any trouble using the site, some tell me they cannot reach it at all.
No one at my host provider’s help desk can tell me what is wrong. They tell me that they cannot reproduce the problem, that whenever they access the site it works perfectly. At the same time, they suspect that my code has something wrong with it, and they may be right. I see three possible explanations of what is happening:
- Maybe there is something I need to change in one of the many configuration files in my project. Maybe I deleted something that I should have kept in the project. Unfortunately, nothing in any of the Microsoft documentation I have seen addresses how to set up a web app to be handed off to third party hosting provider.
- Perhaps the problem is related to the fact that I, along with other users of the site that have run into the same failures, used my computer in the past to access the old version of the site under a presumably different IP address. Perhaps there are DNS problems, which unfortunately are beyond my limited expertise.
- Perhaps the server is, as the message says, too busy, in which case the solution would be to upgrade to a higher-level hosting plan.
In an effort to rule out the first of these, I have revisited my project code, starting over with a fresh copy of the Yeoman-generated sample project. This time, thinking that I might have inadvertently removed something critical the first time around, I have left everything unchanged except for the views, the controllers, and the static files. In the_Layout.cshtml file I have changed only the code that defines the navigation bar. The app runs perfectly on my Mac with these changes.
After recounting this long tale of woe, and I thank you for patiently wading through it, I have these question for you, the .NET Core experts:
- Has anyone else run into this kind of problem, and if so were they able to solve it, and if so how?
- Is the sample app as generated by Yeoman suitable to be published locally with a simple call todotnet publish, after which the files generated by that call can be uploaded as is to my host’s server? In other words, does the idea of staying as close as possible to the sample app make sense?
- Why do the browsers say that they cannot load localhost? (I say browsers plural because I have received similar messages from Safari on both the Mac and the iPhone and from Chrome on the iPhone,) Why is a browser looking for localhost when I give it a www URL?
- If a website does not do anything other than display text and images, can it dispense with logging, error reporting and environment variables? What should such an app’s configuration files contain?
- Also, is there documentation somewhere where I have not looked that provides guidance to these issues—particularly the settings in the project.json, program.cs, startup.cs, and perhaps other files—and the general process of deploying a simple .NET Core web app to the web via a commercial hosting provider other than Azure from a home computer than is not running Visual Studio?