ASP.NET核心默认模板项目因HTTP错误404或异常而失败
我对ASP.NET Core MVC或Razor Applaunch.json
有问题。
我使用默认模板来创建一个具有默认设置的项目:
- ASP.NET Core Web应用程序-DOT NET 6
- ASP.NET CORE WEB APP MVC -DOT NET 6
这是我的Applaunch.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:18583",
"sslPort": 44326
}
},
"profiles": {
"WebApplication12": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7081;http://localhost:5081",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
和Program : .cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
启动控制台后表明听端口的毫无问题:
但我对我的ASP.NET核心MVC项目有一个例外:
我得到404的Razor页面:
所有配置都是默认模板配置。
有人遇到同样的问题吗?
I have a problem with ASP.NET Core MVC or Razor applaunch.json
.
I use a default template to create a project with default settings:
- ASP.Net Core Web App - Dot Net 6
- ASP.Net Core Web App MVC - Dot Net 6
This is my applaunch.json
:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:18583",
"sslPort": 44326
}
},
"profiles": {
"WebApplication12": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7081;http://localhost:5081",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
And program.cs :
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
After launch console shows that no problem with listening to ports :
But I get an exception for my ASP.NET Core MVC projects:
And I get 404 for Razor Pages:
All configurations are default template configurations.
Did anyone experience the same problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用
microsoft.aspnetcore.mvc.razor.runtimecompilation
软件包解决了问题,并添加以下服务:for asp.net core剃须刀模板
和MVC项目模板:
第二个解决方案是使用<<代码> dotnet运行手表在开发人员电源外壳或命令行中。
I solved the problem by using
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
package and adding the following service:For ASP.NET Core Razor template
And for the MVC project template:
The second solution is to use
dotnet run watch
either in Developer Power Shell or Command-Line.