I have created an ASP.NET MVC Core project and registered some custom folders to search for Views. I did this with a custom IViewLocationExpander
class like this:
public class AppsViewLocationExpander : IViewLocationExpander
{
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context,
IEnumerable<string> viewLocations)
{
yield return "/MyViewLocation/A/Views";
//and so on...
}
And used this class in Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new AppsViewLocationExpander());
});
}
Inside the MyViewLocation/A/Views folder are some *.cshtml files and a local debug session proceeded without any error. Now I published the web app to Azure, and I got a 500 Internal Server Error. I Attached Visual Studio to debug this error and got this message:
System.InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/MyViewLocation/A/Views/Index.cshtml
What did I wrong? Do I have to add the Views-Folder in some other place too?
EDIT:
I modified my project.json at my initial setup, but this does not help with my Azure problem. But probably it was necessary to find the views during my local debugging.
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"MyViewLocation/**/Views",
"appsettings.json",
"web.config"
]
},
EDIT 2:
I uploaded manually the *.cshtml files onto the FTP server. Nevertheless They are still not found.
Create or open an Azure cloud service project in Visual Studio. In Solution Explorer, right-click the project, and, from the context menu, select Convert > Convert to Azure Cloud Service Project. In Solution Explorer, right-click the newly created Azure project, and, from the context menu, select Publish.
Right-click on the project in Solution Explorer and select Publish. In the Publish dialog: Select Azure. Select Next.
Publishing the MVC applicationOpen the MVC project's solution in Visual Studio. Right-click the project in the Solution Explorer and select Publish.... Select Microsoft Azure App Service and choose Select Existing. Click Publish.
System.InvalidOperationException: The view 'Index' was not found. The following locations were searched: /MyViewLocation/A/Views/Index.cshtml
The error message shows that there are some files missing when deploy to Azure. I have tested this scenario in my local, every things works fine. If you encounter this problem, I would recommend to publish the folder again like the following:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With