Это приложение использует Identity 4 с клиентским mvc-приложением и основным веб-приложением asp.net IDP (провайдер идентификации).
Невозможно получить доступ к представлению действия индекса контроллера.
Как исправить эту проблему ????
Проект IDP Автозагрузка проекта (localhost: 44393)
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddTestUsers(Config.GetUsers())
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryClients(Config.GetClients());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseIdentityServer();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
//app.Run(async (context) =>
//{
// await context.Response.WriteAsync("Hello World!");
//});
}
}
Файл Configure.cs
public static class Config
{
public static List<TestUser> GetUsers()
{
return new List<TestUser>
{
new TestUser
{
SubjectId ="d866oef",
Username ="Kasunjith",
Password="password",
Claims= new List<Claim>
{
new Claim("given_name","Kasunjith"),
new Claim("family_name","Underwood"),
}
}, new TestUser
{
SubjectId ="d866omf",
Username ="BimalJith",
Password="password",
Claims= new List<Claim>
{
new Claim("given_name","BimalJith"),
new Claim("family_name","ViewWord"),
}
},
};
}
// identity-related resources (Scopes)
public static IEnumerable<IdentityResource> GetIdentityResources()
{
return new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile()
};
}
public static IEnumerable<Client> GetClients()
{
return new List<Client>()
{
new Client
{
ClientName="Image Galary",
ClientId="imagegalleryclient",
AllowedGrantTypes = GrantTypes.Hybrid,
RedirectUris = new List<string>()
{
"https://localhost:44335/signin-oidc"
},
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId
},
ClientSecrets =
{
new Secret("secret".Sha256())
}
}
};
}
}
Клиентское приложение (localhost: 44335)
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
}).AddCookie("Cookies",
(options) =>
{
}).AddOpenIdConnect("oidc", options => {
options.SignInScheme = "Cookies";
options.Authority = "https://localhost:44393";
options.ClientId = "imagegalleryclient";
options.ResponseType = "code id_token";
options.SaveTokens = true;
options.ClientSecret = "secret";
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseAuthentication();
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Gallery}/{action=Index}/{id?}");
});
}
}
Мой класс контроллера
[Authorize]
public class GalleryController : Controller
{
public async Task<IActionResult> Index()
{
await WriteOutIdentityInformation();
return View();
}
public async Task WriteOutIdentityInformation()
{
var identityToken = await HttpContext.GetTokenAsync(OpenIdConnectParameterNames.IdToken);
Debug.WriteLine($"Identity token:{identityToken}");
foreach (var claim in User.Claims)
{
Debug.WriteLine($"Claim type:{ claim.Type} -Claim value : {claim.Value}");
}
}
}
первый после входа в систему с использованием имени пользователя и пароля
После перехода на localhost: 44335 / Gallary / index показать эту ошибку