deralbert
deralbert

Reputation: 1043

Azure does not see Index.cshtml

I'm trying to publish my ASP.NET Core application on Azure service. This works, but when I try to use the application functionality, I get the message

Your App Service app is up and running.

Moreover, in my wwwroot folder I don't have any .html files. I only have an Index.cshtml file, which is located in the Views/Home-folder in my application, all another files are .css, .js, etc.

When I run the application in Visual Studio in Debug mode, immediately opens the page in browser that was generated from Index.cshtml. But after the application is published in Azure, this does not happen.

What can I do to make Azure see Index.cshtml?

Upvotes: 0

Views: 1780

Answers (4)

Fellow7000
Fellow7000

Reputation: 231

2 cents from my side as I just stuck for a while with this.

The problem was that yesterday I'd been playing around with deploying to Ubunut / Ngnix and today I decided to try Azure.

BUT I forgot to comment (disable) the following lines in my Startup:

//for nginx server
app.UseForwardedHeaders(new ForwardedHeadersOptions
         {
           ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
          });

and that costed me almost half of the day to find the issue.

I also put the routing in the following way

    app.UseStatusCodePages();

    app.UseAuthentication();

    app.UseMvc(routes => {
        routes.MapRoute(
        name: "default",
        template: "{controller=Pages}/{action=Index}");
    });

Now looks like it works on Azure :)

Upvotes: 0

Bruce Chen
Bruce Chen

Reputation: 18465

AFAIK, a default route would be added to Configure method of your Startup.cs file as follows:

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});

I also created my .Net Core 2.0 MVC application to check this issue, it could work as expected on local side and my azure web app.

Moreover, in my wwwroot folder I don't have any .html files.

Views under Web Application and Web Apllication MVC would be compiled into {your-webapplication-assemblyname}.PrecompiledViews.dll, you could leverage ILSpy to check your DLLs.

For your issue, I would recommend you clear the web content in your web app via KUDU, or modify the publish settings and choose Remove additional files at destination under File Publish Options, then redeploy your application to Azure Web App to narrow this issue.

Upvotes: 1

Ashokan Sivapragasam
Ashokan Sivapragasam

Reputation: 2189

Are you finding index.cshtml in your web package? In case if you get index.cshtml in your final web package, you may need to add index.cshtml file type to the following in..

..YourAzureWebApp --> Application Settings --> Default Documents

enter image description here

Upvotes: 1

deralbert
deralbert

Reputation: 1043

I found out what the problem was. There are two types of applications, as presented below in the picture: Web Application and Web Apllication MVC. I worked with the second type of application. When I selected the first type and published the application, Azure immediately found the required index.html. I just had to choose Web Application.

But why does not it work with the second type of application (Web Apllication MVC)? I still do not know the answer to this question.enter image description here

Upvotes: 0

Related Questions