をリダイレクト:ASP.NETコアウェブAPI承認404エラー&力を返す属性私は次のプロジェクトが含まれているasp.netコア2.0ソリューション持っ
- データ:EFコードのためのクラスライブラリ
- のOAuth:としてのIdentityServer4コード
- APIのWebアプリケーションプロジェクトは:私のAPIは空のWebプロジェクトとして作成されたため
は今のOAuthプロジェクトがaspnetidentityで構成され、そのトークンを取得する私ができるよう、細かい作業します認証後、これはそれのためのスタートアップコードです:今、APIプロジェクトに関する問題、私は任意の認可コントローラ/アクションを開くたびにその私に404エラーを与えており、このスタートアップコード
public void ConfigureServices(IServiceCollection services)
{
// connect with normal database
services.AddDbContext<MCareContext>(options => options.UseSqlServer(Configuration
.GetConnectionString("MCareConnection")));
services.AddIdentity<User, IdentityRole>()
.AddEntityFrameworkStores<MCareContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// IS configurations database
var dbConnectionString = Configuration.GetConnectionString("MCareConnection.OAuth");
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.AddIdentityServer()
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(dbConnectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(dbConnectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
})
.AddAspNetIdentity<User>()
.AddDeveloperSigningCredential();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
DatabaseInitializer.InitializeDatabase(app);
loggerFactory.AddConsole();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseIdentityServer();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<MCareContext>(options => options.UseSqlServer(Configuration
.GetConnectionString("MCareConnection")));
services.AddIdentity<User, IdentityRole>()
.AddEntityFrameworkStores<MCareContext>()
.AddDefaultTokenProviders();
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(options =>
{
options.Authority = "http://localhost:60415";
options.ApiName = "mCareApi";
options.RequireHttpsMetadata = false;
});
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
app.UseAuthentication();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
私は上記のコードでこの部分を閉じる場合:いつでもI OP
//services.AddIdentity<User, IdentityRole>()
//.AddEntityFrameworkStores<MCareContext>()
//.AddDefaultTokenProviders();
次に承認が期待通りに仕事を属性が、別の新しい問題、それは、500内部サーバーエラーを示しますそのコンストラクタ
InvalidOperationExceptionが上のUserManagerのUserManagerを期待AccountControllerのような任意のコントローラened:タイプ Microsoft.AspNetCore.Identity.UserManager`1 [MCare.Data.Entities.User]のためのサービスを解決することができませんを アクティブにしようとしたときMCare.Api.Controllers.AccountsController
私が見てきたすべてのプロジェクトは、彼らがそれらの両方を混ぜるので、私は、これはAPIプロジェクトでIdentityServer4プロジェクトを混合せず、起こって、どのようにこの問題を解決することを目的とする理由を知りたいです1つのプロジェクト。
なぜRestPIプロジェクトにAspNetIdentityが必要ですか? – regnauld
アカウントの作成、パスワードのリセット、およびその他のアカウント管理機能 –
あなたのブラウザで許可されたルートを要求する瞬間からログを投稿してください。 – poke