0

First time experimenting with creating an ASP.NET Core 8 web application in Visual Studio Code. I chose .NET 8 because it's the newest version. I am deploying it via Azure App Services. I am very familiar with Visual Studio and deploying to a regular web server, so I know the players.

First example: I created a simple one-page app in Visual Studio Code, deployed it through App Services, and I had to add home.html to the default documents, then my page showed up fine.

Second example: I used Visual Studio Code to create a simple ASP.NET Core web app (side note, doing this without needing full Visual Studio is pretty sweet, I have to admit).

.NET 8 places all the web pages in the Pages folder. Index.cshtml is my default page. I deploy to App Services, I get a page not found error.

  • I added Index.cshtml to default documents. No luck.
  • I added Pages\Index.cshtml to default documents. No luck.

When I added a dummy index.html page and redeployed, it was able to see that page. But if I manually change the url to Pages/index.cshtml, I still get a page not found error.

I am used to having default.aspx in the root directory. What .NET did seems the new version of out of the box, creating a Pages folder, so what am I missing here?

UPDATE: I am very familiar with Visual Studio and ASP.NET from about five years ago. Maybe an easier question is, which template from .NET 8 should I select to have a "classic" ASP.NET site? Or is MVC my only option? Should I use ASP.NET 4.8 instead?

7
  • 1
    How have you configured razor pages in your program / startup code? What does your request pipeline have in it? asp.net-core is very different to asp.net, the request pipeline must be explicitly configured and will only handle request in the way you tell it to. Commented Apr 30 at 3:13
  • If I want to use a template that is just like regular asp.net, which template should I choose? Commented Apr 30 at 11:46
  • @CigarDoug Did you try setting the default doc in Web.config file? Commented Apr 30 at 12:00
  • which template from .NET 8 should I select to have a "classic" ASP.NET site? Or is MVC my only option? Should I use ASP.NET 4.8 instead? You are looking for .NET Core or ASP.Net App ? Commented Apr 30 at 12:01
  • I don't know what .NET Core is, really. I just want to create an ASP.NET app. The last time I created one was in 2017 or so. Just .html and .cs files, no MVC. Commented Apr 30 at 16:58

2 Answers 2

2

How do I set default document for an ASP. NET Core 8 web app in Azure App Services?

The Index.cshtml under the Pages folder indicates that you are using an ASP.NET Core Web App with Razor Pages. Razor Pages rely on URL-based routing instead of serving static content, so configuring a default document in Azure App Service is not necessary.

Refer this MS Doc to Know Default Documentation in Azure Web Apps.

you don't need to access .cshtml files directly like Pages/Index.cshtml. It maps URLs to the appropriate pages automatically.

https://<YourAppName>.azurewebsites.net -> / (Index.cshtml)
https://<YourAppName>.azurewebsites.net/Privacy ->   /Privacy(Privacy.cshtml)

NET 8 places all the web pages in the Pages folder. Index.cshtml is my default page. I deploy to App Services, I get a page not found error

Make Sure that Razor Pages are properly configured in your Program.cs file by adding the following lines:

builder.Services.AddRazorPages();
app.MapRazorPages();

Program.cs:

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();

Check all necessary files are deployed to Azure Correctly using Kudu console.

enter image description here

https://<YourWebAppName>.scm.canadacentral-01.azurewebsites.net/DebugConsole

which template from .NET 8 should I select to have a "classic" ASP.NET site? Or is MVC my only option? Should I use ASP.NET 4.8 instead?

To get Classic Asp. Net pages Like Default.aspx you can use Asp .Net Web Form Site as shown below.

enter image description here

enter image description here

Sample Output:

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for answering my questions directly. I don't see Asp .Net Web Form Site as a option in Visual Studio Code. I may have to just bite the bullet and use MVC, since I am starting over with C# after several years away.
1

The cshtml files are served as part of razor views. Your startup app would have a default route to a controller and default view. You should look further at using ASP.Net Core mvc here: https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-8.0

1 Comment

I reviewed what you shared. It does not relate in any way to the project .NET generated. I have several .cshtml files, no controllers, no MVC related code in my project at all. I just need to tell the app to make Index.cshtml my default page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.