我有一个 Blazor WebAssembly 托管解决方案(客户端和服务器)设置,使用 IdentityServer 进行身份验证。我想做两件事......
Server Startup.cs 目前有
public void ConfigureServices(IServiceCollection services)
{
....Condensed
services.AddControllersWithViews();
services.AddRazorPages();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataContext dataContext)
{
.....Condensed
app.UseRouting();
app.UseIdentityServer();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
}
最佳答案
创建 WebAssembly 解决方案时,请务必选中“ASP.Net Core Hosted”框。
这将创建三个项目:客户端、共享和服务器。
在服务器项目中,您将找到一个 Controllers 文件夹。继续添加一个 Controller ,例如 DummyController.cs
namespace BlazorWASM4.Server.Controllers
{
[ApiController]
[Route("[controller]")]
public class DummyController : Controller
{
public IActionResult Index()
{
return View();
}
}
}
然后右键单击您的 Controller 方法索引并单击“添加 View ”。然后像这样实现 View (Index.cshtml),例如:<h1>Dummy Page</h1>
运行项目并导航到 localhost:port/Dummy您应该会看到您的新页面显示出来。
关于asp.net-mvc - 如何在 Blazor WebAssembly 托管解决方案上配置 MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67321457/