在 Blazor 中使用普通的单页剃刀组件。我可以IJSRuntime在页面顶部像这样注入:
@inject IJSRuntime JSRuntime
Run Code Online (Sandbox Code Playgroud)
如果我为组件在 .razor.cs 文件后面创建了一个代码,我如何将类似的内容IJSRuntime注入到代码隐藏文件中?
Consider this code:
_dbContext.Messages
.GroupBy(m => new
{
MinId = m.SenderId <= m.RecipientId ? m.SenderId : m.RecipientId,
MaxId = m.SenderId > m.RecipientId ? m.SenderId : m.RecipientId
})
.Select(gm => gm.OrderByDescending(m => m.SentAt).FirstOrDefault());
Run Code Online (Sandbox Code Playgroud)
By this I group all dialogues of users by their Id's no matter who sent the message. Then I order messages by SentAt date inside the groups and select one last message out of each dialogue. The thing is that this code worked and more over it translated …
c# linq-to-entities entity-framework-core .net-core-3.1 ef-core-3.1
我正在尝试将一个项目从 asp.net Core 2.2.6 迁移到 asp.net core 3.0 在我的启动中,我有
services.AddMvc(options =>
{
options.Filters.Add(new CorsAuthorizationFilterFactory("default"));
})
Run Code Online (Sandbox Code Playgroud)
当我更新到 netcoreapp3.0 时,我收到以下错误 The type or namespace name 'CorsAuthorizationFilterFactory' could not be found (are you missing a using directive or an assembly reference?)
有谁知道什么相当于asp.net core 3?
我们将使用下面的正则表达式来获取单词前的数字。
例子 :
838123 someWord 8 someWord 12 someWord
(\d+)\s*someWord
但有时数字和单词之间会出现任何内容。请参见下面的示例行。
前任:
43434 of someword 12 任何东西someword 2323 new someword
如何使用正则表达式获取该单词之前的确切数字?
请给我你的建议。
EF Core 2.1+ 支持值转换。您可以使用内置函数EnumToStringConverter<>自动将枚举转换为字符串,反之亦然。
我正在连接到现有数据库,并希望将其中一列转换为枚举,所以EnumToStringConverter<>似乎正合我意。但是,数据库也不在我的控制范围内(我只有读取访问权限),因此如果有人在表中插入一行字符串值与我的任何枚举定义都不匹配,会发生什么情况?
我最好希望将任何未知值映射到枚举值,但除了手动创建自己的对象(在其中实现我自己的手动解析所有字符串值并映射它们)Unknown之外,我找不到任何有关如何执行此操作的文档ValueConverter到适当的枚举值。这看起来有点麻烦并且增加了额外的维护,所以我非常希望在这里进行一些自动化...这意味着如果在数据库中找到未知的字符串值,EFCore 会自动将其映射到我的自定义Unknown枚举值。
这可能吗?
我有一个客户试图从我们的 Web 应用程序访问他们的日历。一切都适用于我们所有的其他客户,所以我不确定这里有什么不同,除了这个客户在澳大利亚并且使用非 gmail.com 电子邮件地址。
客户能够授权我们的应用程序,我们确实为用户获得了一个 oauth 令牌。我们请求访问日历并且客户授予了它。当我们请求所有日历的列表时,我们会收到无效的授权消息。
下面是我们用来访问他们日历的代码。被调用的方法是 GetAllWritableCalendars。
public class GoogleCalendarAdapter : ICalendarAdapter {
#region attributes
private readonly ISiteAuthTokenQueryRepository _tokenRepo;
private readonly GoogleCalendarSettings _settings;
private const string APPNAME = "SomeAppName";
private const string ACL_OWNER = "owner";
private const string ACL_WRITER = "writer";
#endregion
#region ctor
public GoogleCalendarAdapter(ISiteAuthTokenQueryRepository tokenRepo,
GoogleCalendarSettings settings) {
_tokenRepo = tokenRepo;
_settings = settings;
}
#endregion
#region methods
private GoogleAuthorizationCodeFlow BuildAuthorizationCodeFlow() {
return new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer() {
ClientSecrets = BuildClientSecrets(),
Scopes = BuildScopeList()
});
} …Run Code Online (Sandbox Code Playgroud) 我有一个包含 char 属性的对象。对于我的测试,我需要将该属性设置为除 I 或 R 之外的任何内容。是否有任何东西,理想情况下是 AutoFixture 原生的,我可以做的比我想出的代码更简洁、更简洁?
这是对象的表示
public class MyObject
{
public char MyProperty {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用的解决方案
MyObject = _fixture.Create<MyType>();
if ((new char[] { 'I', 'R' }).Contains(MyObject.MyProperty))
MyObject.MyProperty = new Generator<char>(_fixture).Where(c => !new char[] { 'I', 'R' }.Contains(c)).First();
Run Code Online (Sandbox Code Playgroud) 我目前正在使用 VSCode 处理 .net 核心 api 项目,并且我想将 ASP.NET 核心身份验证和授权与 cookie 集成。
我试图添加services.AddAuthentication();和services.AddAuthorization();在Startup.cs。我还在[Authorize]我的UsersController.cs.
[Authorize]
[Route("api/Users")]
[ApiController]
public class UsersController : ControllerBase
Run Code Online (Sandbox Code Playgroud)
问题是当我启动我的应用程序时,即使我没有创建用户或角色,我仍然可以访问我的 API。( https://localhost:5001/api/Users)
我尝试设置launchSettings.json如下:
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:49086",
"sslPort": 44343
}
Run Code Online (Sandbox Code Playgroud)
但我仍然可以访问我的 API。如果没有用户或角色,如何拒绝访问?
我肯定错过了一些东西,但我不知道是什么。
预先感谢您的帮助!
如何删除身份 core3 preview4 中的任何 ILookupNormalizer 注入?
我使用身份 2.2 并且不能在 ApplicationUserManager 上使用 ILookupNormalizer。我的挛缩 ApplicationUserManager :
public ApplicationUserManager(
IApplicationUserStore store,
IOptions<IdentityOptions> optionsAccessor,
IPasswordHasher<TblUsers> passwordHasher,
IEnumerable<IUserValidator<TblUsers>> userValidators,
IEnumerable<IPasswordValidator<TblUsers>> passwordValidators,
ILookupNormalizer keyNormalizer,
IdentityErrorDescriber errors,
IServiceProvider services,
ILogger<ApplicationUserManager> logger,
IHttpContextAccessor contextAccessor,
IUsedPasswordsService usedPasswordsService)
: base((UserStore<TblUsers, TblOrganizationChart, AbfaContext, int, TblUserClaim, TblUserOrganizationChart, TblUserLogin, TblUserToken, TblRoleClaim>)store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger)
Run Code Online (Sandbox Code Playgroud)
当我在 AddCustomServices 上添加 ILookupNormalizer 时,出现以下错误:
来自程序集“Project.Core,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”的“Project.Core.Identity.CS.CustomNormalizers”类型中的方法“NormalizeName”没有实现。
删除“services.AddScoped();”后 我有这个错误:
来自程序集“Project.Core,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”的“Project.Core.Identity.ApplicationUserManager”类型中的“方法”“NormalizeKey”没有实现。“
我不需要使用 Normalizer。
如何解决这个问题?
我不能在 .NET Core 3.1 中使用像在 .NET Core 2.2 中那样的简单路由。
.NET Core 3.1 中路由的最后更改是什么?
我有一个User列表和Branch列表。一个Branch可以有多个User。我需要在指定一些属性User,从Branch基础上BranchId。这是我的课。
用户:
public class User
{
public Guid Id { get; set; }
public bool Active { get; set; }
public Guid BranchId { get; set; }
public string BranchName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
分支:
public class Branch
{
public Guid Id { get; set; }
public bool Active { get; set; }
public string BranchName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的,
foreach (var …Run Code Online (Sandbox Code Playgroud) var paymentTypes = _context
.BursaryTransactions
.Select(c => c.PaymentType)
.ToList();
string[] obj = paymentTypes
.ToArray();
var a = obj[1];
Run Code Online (Sandbox Code Playgroud)
第一行检索表中字符串形式的付款类型列表,BursaryTransactions第二行将该列表转换为数组。
然而,第一行的列表包含类似的字符串,例如
- 乌特梅邮报
- 学费
- 学费
- 乌特梅邮报
- 形式
- 形式
我想过滤这些列表并仅检索出现多次的项目的一次出现。然后将新列表转换为数组。
c# ×12
.net ×9
asp.net-core ×3
.net-core ×2
linq ×2
asp.net ×1
asp.net-mvc ×1
autofixture ×1
blazor ×1
ef-core-3.1 ×1
enums ×1
performance ×1
razor ×1
regex ×1