Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View not found after publish to Azure

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.

like image 432
Koopakiller Avatar asked Sep 08 '16 16:09

Koopakiller


People also ask

How do I publish from Visual Studio to Azure 2022?

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.

How do I publish a Visual Studio code to Azure?

Right-click on the project in Solution Explorer and select Publish. In the Publish dialog: Select Azure. Select Next.

How do I publish my MVC application to Azure?

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.


1 Answers

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: enter image description here

like image 156
Jambor - MSFT Avatar answered Sep 29 '22 06:09

Jambor - MSFT