我创建了一个具有以下属性的应用程序用户类:
public class ApplicationUser:IdentityUser
{
public string RandomPassword { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我已将启动更新为:
services.AddIdentity<ApplicationUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
但我的迁移为空。我希望 RandomPassword 作为 AspNetUser 表的列。
c# asp.net-mvc asp.net-identity asp.net-core asp.net-core-3.1
我正在寻找一种将配置(选项)中的值注入到验证属性的参数中的方法。
让我印象深刻的场景是脚手架身份用户界面。
它提供了配置有关密码长度的选项的可能性。但生成的注册页面上不尊重更改。这是因为页面上验证属性的值是硬编码的。
有人知道这是否可能吗?
我有一个 Vue 应用程序,我试图在其中设置静默令牌更新。
我的 Oidc 配置如下所示:
var mgr = new Oidc.UserManager({
authority: process.env.VUE_APP_IDENTITY_URL,
client_id: process.env.VUE_APP_CLIENT_ID,
redirect_uri: process.env.VUE_APP_REDIRECT_URI,
scope: 'openid profile',
response_type: 'id_token token',
silent_redirect_uri: process.env.VUE_APP_SILENT_REDIRECT_URI,
userStore: new Oidc.WebStorageStateStore({store: localStorage}),
automaticSilentRenew: true,
filterProtocolClaims: true,
loadUserInfo: true,
})
Run Code Online (Sandbox Code Playgroud)
我还有一个静态的silent-renew.html 页面:
<!DOCTYPE html>
<html>
<head>
<title>Silent Renew Token</title>
</head>
<body>
<script src='oidc-client.min.js'></script>
<script>
new Oidc.UserManager().signinSilentCallback().catch((err) => {
console.log(err);
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我加载应用程序时,静默更新只是无限循环:
我的访问令牌不会再过期一个小时,但它仍在触发事件,我无法深入了解。有谁知道还有什么可能导致这个循环?
javascript asp.net-identity vue.js identityserver4 oidc-client-js
我有一个 ASP.NET Core 沙箱项目。我已经添加了IdentityDbContext。注册页面工作正常。登录/注销页面工作正常。(可以通过为SignInManager.IsSignedIn(User)用户显示的html看到)
我有一个控制器标有[Authorize]:
[Authorize]
public class MyTestController : Controller
{
...
}
Run Code Online (Sandbox Code Playgroud)
当我第一次尝试导航到它时 - 它工作正常(重定向到登录页面)
但成功登录后,它再次重定向回使用相同链接登录: https://localhost:44359/Identity/Account/Login?ReturnUrl=%2FMyTest
这是我的代码Startup.cs:
[Authorize]
public class MyTestController : Controller
{
...
}
Run Code Online (Sandbox Code Playgroud)
以前,我为登录、注销、注册添加了脚手架身份项。没有[Authorize]工作良好的控制器。
在我的startup.cs类中,我检查它是否是DEV环境,并且在我的appsettings.json和appsettings.development.json文件中有很多键值对。
但是我想封装一些仅在 DEV 环境中运行的代码,并且当部署到 UAT、TEST 或 LIVE 时,不会部署代码。
如何才能实现这一目标?
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseMigrationsEndPoint();
}
else
{
app.UseHsts();
}
Run Code Online (Sandbox Code Playgroud)
并有一个类,因为这是我的类中的一个值,用于获取子域运行的 URL(这也是我的 IDENTITY 数据库中的角色的值)
private string SubDomain(HttpContext httpContext)
{
HttpRequest request = httpContext.Request;
string url = request.Headers["Host"];
string subDomainUrl = url.Replace("https://", "").Split('/')[0];
Run Code Online (Sandbox Code Playgroud)
//我希望能够基于 http://localhost:44312/?role=adminUsers 获取我的域 //因此,如果它在本地主机上运行并且角色是管理员用户,则这只会在本地执行,作为远程 URL有http://adminusers.mydomain.com
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<InjectMyClassHere>(); //My class or interface goes here
Run Code Online (Sandbox Code Playgroud)
我希望这一点很清楚。我怎样才能实现这个目标?即让此类仅在 DEV 中执行,而不部署在 UAT、TEST 或 LIVE 环境中
我正在尝试使用ASP.NET Core Identity 2.0在我现有的应用程序中设置身份验证.当我使用自己的数据库模式和类时,我有自己的User类,我不得不创建自定义UserStore和自定义UserManager.
所以我在AccountController中有我的登录功能:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
var result = await _signInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, lockoutOnFailure: false);
if (result.Succeeded)
{
_logger.LogInformation("User logged in.");
return RedirectToLocal(returnUrl);
}
if (result.IsLockedOut)
{
_logger.LogWarning("User account locked out.");
return RedirectToAction(nameof(Lockout));
}
else
{
ModelState.AddModelError(string.Empty, "Connection failed.");
return View(model); …Run Code Online (Sandbox Code Playgroud)