我正在尝试在 ASP.NET Framework 4.7.2 WEB API 中设置 Identity Server 4 Auth 服务器,但无法使其工作。我无法在 Startup 类中添加 appBuilder.UseIdentityServer()。
我的理解是,IdentityServer4 被编译为 DotNet Standard 2.0,而 ASP.NET Framework 4.7.2 与 DotNet Standard 2.0 兼容,因此 IDS4 应该能够在 4.7.2 项目中使用。如果我错了请纠正我。
可以这样使用IdentityServer4吗? 我在这里做错了什么?
这是我的启动类(class):
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var builder = services.AddIdentityServerBuilder()
.AddInMemoryIdentityResources(
IdentityServerConfig.GetIdentityResources())
.AddInMemoryApiResources(IdentityServerConfig.GetApis())
.AddInMemoryClients(IdentityServerConfig.GetClients());
}
public void Configuration(IAppBuilder appBuilder)
{
HttpConfiguration httpConfiguration = new HttpConfiguration();
WebApiConfig.Register(httpConfiguration);
appBuilder.UseWebApi(httpConfiguration);
}
}
这是一个link到我的项目:
我几天来一直在寻找解决方案,但找不到任何有用的解决方案。如果我错过了什么,请原谅。
谢谢。
最佳答案
如果问题是关于 .NET Framework,而不是 ASP.NET 版本,则可以使用 .NET 4.7.2。
TestApi3.csproj
必须如下所示:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4" Version="2.4.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
</ItemGroup>
</Project>
那么它应该基于 ASP.NET CORE MVC,而不是 MVC 5 工作。
关于asp.net - 无法将 IdentityServer4 添加到 ASP.NET Framework 4.7.2 API OWIN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55459716/