问题
I'm trying to setup Identity Server 4 Auth server in ASP.NET Framework 4.7.2 WEB API, but I can't get it working. I'm not able to add appBuilder.UseIdentityServer() in the Startup class.
My understanding is that the IdentityServer4 is compiled as DotNet Standard 2.0 and the ASP.NET Framework 4.7.2 is compatible with DotNet Standard 2.0, so IDS4 should be able to be used inside 4.7.2 project. Correct me if I'm wrong please.
Is it possible to use IdentityServer4 like that? What am I doing wrong here?
This is my startup 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);
}
}
Here is a link to my project:
I've been looking for solution for couple of days, but I can't find anytning helpful. Excuse me if I've missed something.
Thanks.
回答1:
In case the question is about .NET Framework, but not ASP.NET version, it is possible to use .NET 4.7.2.
The TestApi3.csproj
has to look like:
<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>
Then it should work based on ASP.NET CORE MVC, not MVC 5.
来源:https://stackoverflow.com/questions/55459716/cant-add-identityserver4-to-asp-net-framework-4-7-2-api-owin