我需要使用随机数字和字母生成令牌。但是,错误消息告诉我使用 RandomNumberGenerator ,它只会给我随机数,这没有帮助。
错误信息
“RNGCryptoServiceProvider”已过时:“RNGCryptoServiceProvider 已过时”。要生成随机数,请使用 RandomNumberGenerator 静态方法之一。
当前使用的代码
private static string RandomString()
{
int length = 256;
const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder res = new StringBuilder();
using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
{
byte[] uintBuffer = new byte[sizeof(uint)];
while (length-- > 0)
{
rng.GetBytes(uintBuffer);
uint num = BitConverter.ToUInt32(uintBuffer, 0);
res.Append(valid[(int)(num % (uint)valid.Length)]);
}
}
return res.ToString();
}
Run Code Online (Sandbox Code Playgroud)
如何更改上面的代码以使用未过时的包?
我正在尝试使用“node main.js”运行我的程序,但是,它不断出现错误“SyntaxError: Unexpected token {”
D:\Visual Studio Code Projects\ts-hello>node main.js
D:\Visual Studio Code Projects\ts-hello\main.js:1
import { LikeComponent } from './like.component';
^
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:721:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Run Code Online (Sandbox Code Playgroud)
我曾尝试将 tsconfig.json 文件更改为 "module": "commonjs",但是,这不起作用。我什至卸载并重新安装了节点并从头开始。
import{LikeComponent} from './like.component';
let component = new LikeComponent(10, true);
component.onClick();
console.log(`likesCount: ${component.likesCount}, isSelected: ${component.isSelected}`);
Run Code Online (Sandbox Code Playgroud)
它应该将程序正确输出到命令提示符上。
我正在使用 ASP.NET core,我读过它已将控制器和 API 合并为一。我已成功地使 JSON 数据正常工作,但是视图无法正常工作。它只是说找不到该页面。我可以查看主页,但是,这是作为 MVC 控制器而不是 API 控制器创建的。
namespace ScheduleWebApp.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class StaffHoursWorkedController : Controller
{
public IActionResult Index()
{
return View();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试进行迁移。迁移完成,但是,当我尝试更新数据库时,我收到此错误消息
无法将 NULL 值插入表“aspnet-ScheduleWebApp-20190525082521.dbo.Students”列“scheduleDateAndTimeid”;列不允许为空。更新失败。
我有两个模型类,一个称为student,另一个称为scheduleDateAndTime.
我创建了一个带有student模型映射的 DTO,并向scheduleDateAndTime
移民
public partial class AnotherMigrationTwoTWOTwotwo : DbMigration
{
public override void Up()
{
DropForeignKey("dbo.Students", "scheduleDateAndTime_id", "dbo.ScheduleDateAndTimes");
DropIndex("dbo.Students", new[] { "scheduleDateAndTime_id" });
RenameColumn(table: "dbo.Students", name: "scheduleDateAndTime_id", newName: "scheduleDateAndTimeid");
AlterColumn("dbo.Students", "scheduleDateAndTimeid", c => c.Int(nullable: false));
CreateIndex("dbo.Students", "scheduleDateAndTimeid");
AddForeignKey("dbo.Students", "scheduleDateAndTimeid", "dbo.ScheduleDateAndTimes", "id", cascadeDelete: true);
}
public override void Down()
{
DropForeignKey("dbo.Students", "scheduleDateAndTimeid", "dbo.ScheduleDateAndTimes");
DropIndex("dbo.Students", new[] { "scheduleDateAndTimeid" });
AlterColumn("dbo.Students", "scheduleDateAndTimeid", c => c.Int());
RenameColumn(table: "dbo.Students", name: "scheduleDateAndTimeid", newName: "scheduleDateAndTime_id"); …Run Code Online (Sandbox Code Playgroud) asp.net ×2
c# ×2
.net ×1
.net-6.0 ×1
asp.net-core ×1
ecmascript-6 ×1
javascript ×1
typescript ×1
view ×1