我使用的是.NET核心3.0.100;Microsoft Visual Studio Community 2019预览版16.4.0预览版1.0;Blazor-server (官方版本)。
我正在尝试将身份验证和授权添加到我的Blazor服务器web应用程序。我在这里https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-3.0&tabs=visual-studio#scaffold-identity-into-an-empty-project上阅读指南
(我也读了这篇https://github.com/aspnet/Identity/issues/1825)
然后右键单击项目,选择Add
\ New Scaffolded Item...
我阅读了ScaffoldingReadme.txt
文件,然后按照指南进行操作。
我按F5进行调试,我捕捉到了错误。
Severity: Error
Error Code: CS0246
Description: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?)
Project: foo
File: C:\Users\donhuvy\Desktop\foo\bar\obj\Debug\netcoreapp3.0\Razor\Pages\Shared\_Layout.cshtml.g.cs
Line: 455
Suppression State: Active
屏幕截图
因为文件\obj\Debug\netcoreapp3.0\Razor\Pages\Shared\_Layout.cshtml.g.cs
位于剃刀类库Microsoft.AspNetCore.Identity.UI (3.0.0)
中,所以我不能编辑它。
如何修复它?
发布于 2019-10-02 23:38:39
这是个问题
生成代码是
Microsoft.AspNetCore.Hosting
@using Microsoft.AspNetCore.Mvc.ViewEngines
@inject IWebHostEnvironment Environment
@inject ICompositeViewEngine Engine
缺少@using
它应该是
@using Microsoft.AspNetCore.Hosting
发布于 2021-07-13 21:13:49
通过在我们的csproj文件(3.1核心应用程序)中添加解决了这个问题:
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
https://stackoverflow.com/questions/58204049
复制相似问题