我是相当新的JwtSecurityTokens,我试着去了解它,并furhtermore整个不同的方面claimsidentity和claimprincipal,但这是另一个故事。
我尝试使用以下代码在C#中生成令牌:
private const string SECRET_KEY = "abcdef";
private static readonly SymmetricSecurityKey SIGNING_KEY = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(SECRET_KEY));
public static string GenerateToken(string someName)
{
var token = new JwtSecurityToken(
claims: new Claim[]
{
new Claim(ClaimTypes.Name, someName),
},
notBefore: new DateTimeOffset(DateTime.Now).DateTime,
expires: new DateTimeOffset(DateTime.Now.AddMinutes(60)).DateTime,
signingCredentials: new SigningCredentials(SIGNING_KEY, SecurityAlgorithms.HmacSha256)
);
return new JwtSecurityTokenHandler().WriteToken(token);
}
Run Code Online (Sandbox Code Playgroud)
我遵循了有关YouTube的教程,但是不确定我是否了解JwtSecurityToken中的不同部分。另外,当我通过控制器执行代码以尝试返回令牌时,它返回一个错误,提示:“ IDX10603:解密失败。尝试的密钥:'[PII被隐藏]'”。
任何帮助表示赞赏。
我正在我的网站上开发一个功能,用户应该能够使用 ckeditor 5 和 textarea 编辑他或她自己的主题。textarea 被放置在一个模态中。但是,当我尝试在用户按下按钮时预填充 textarea 时,textarea 内没有任何内容。我尝试了以下方法:
var editor;
ClassicEditor
.create(document.querySelector('#edit-reply-modal'))
.then(editor => {
editor = editor;
})
$(".toggle-edit-modal").click(function(e) {
e.preventDefault();
editor.setData("<p>Testing</p>"));
$("#edit-reply-modal").html("<p>Testing</p>");
});
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。
我对ASP.NET Core相当陌生,现在我正试图了解UrlHelper的总体工作方式。
在我的控制器中,我想为同一控制器中的另一个动作创建一个绝对URL,例如http://localhost:PORT/api/controller/action。现在的问题是,我该怎么办?
我尝试了以下方法:
var urlHelper = new UrlHelper(new ActionContext());
var url = urlHelper.Action("ACTION", "CONTROLLER");
Run Code Online (Sandbox Code Playgroud)
此外,这些不同的上下文是ActionContext什么样的?
与许多其他网站一样,我想在第一页加载时向用户显示一个模态窗口,说明该网站使用 cookie。当用户关闭模态并重新加载页面时,模态不应再次出现。
我对 Laravel 中的 cookie 相当陌生,我知道它可以通过这个实现。我如何实现这一目标?我可以想象在用户的浏览器中设置 cookie,如果它存在,我不会显示模态。
提前谢谢你。