我想通过使用 openid (用于使用 google、yahoo 登录)为 asp.net 和 asp.net mvc 应用程序实现一个登录系统,我在互联网上搜索(并用 google 搜索,也堆叠了 :D)但是,没有什么可做的指导我实施这一点;所有页面都是关于库的(DotNetOpenId、DotNetOpenAuth 等);有人可以帮助我理解和实施这一点吗?没有其他库?谢谢。
我昨天在这里问了一个关于从匿名对象读取属性并将它们写入类的私有字段的问题。问题解决了。这是一个简短的故事:
我有一些json格式的数据。我将它们反序列化为ExpandoObject
,并将它们作为IDictionary<string, object>
to 方法传递。它工作正常,除了Int32
属性。似乎他们变成了Int64
,在哪里?我不知道。
这里又是方法:
private Func<IDictionary<string, object>, dynamic> MakeCreator(
Type type, Expression ctor,
IEnumerable<PropertyToFieldMapper> maps) {
var list = new List<Expression>();
var vList = new List<ParameterExpression>();
// creating new target
var targetVariable = Expression.Variable(type, "targetVariable");
vList.Add(targetVariable);
list.Add(Expression.Assign(targetVariable, Expression.Convert(ctor, type)));
// accessing source
var sourceType = typeof(IDictionary<string, object>);
var sourceParameter = Expression.Parameter(sourceType, "sourceParameter");
// calling source ContainsKey(string) method
var containsKeyMethodInfo = sourceType.GetMethod("ContainsKey", new[] { typeof(string) });
var accessSourceIndexerProp = sourceType.GetProperty("Item"); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码段对我的 JWt 进行签名和编码:
var claims = new Claim[] { new SomeClaimes() };
var scKey = Encoding.UTF8.GetBytes("SOME KEY");
var ecKey = Encoding.UTF8.GetBytes("SOME OTHER KEY");
var tokenDescriptor = new SecurityTokenDescriptor {
Subject = new ClaimsIdentity(claims),
SigningCredentials = new SigningCredentials(
new SymmetricSecurityKey(
scKey),
SecurityAlgorithms.HmacSha512),
EncryptingCredentials = new EncryptingCredentials(
new SymmetricSecurityKey(
ecKey),
// I tryied all possible combination of algorithms here:
SecurityAlgorithms.XXXX,
SecurityAlgorithms.YYYY),
Issuer = "My Jwt Issuer",
Audience = "My Jwt Audience",
IssuedAt = DateTime.UtcNow,
Expires = DateTime.Now.AddDays(7),
};
var tokenHandler = new …
Run Code Online (Sandbox Code Playgroud) 我试图在运行时创建一些表达式来更改给定字典的值。我创建了这个片段,它成功地生成了表达式并将其编译为Action
. 但是调用动作不能修改字典的值,也不会抛出任何错误。这是代码:
public class ChangeDicValue {
public void Change(IDictionary<string, object> dic) {
var blocks = MakeCleaningBlock(dic);
foreach (var block in blocks)
block.Invoke(dic);
}
private List<Action<IDictionary<string, Object>>> MakeCleaningBlock(IDictionary<string , object > dic) {
var allKeys = dic.Keys.ToArray();
var dicType = typeof(IDictionary<,>).MakeGenericType(typeof(string), typeof(object));
var dicContainsMethod = dicType.GetMethod("ContainsKey", new[] {typeof(string)})
?? throw new InvalidOperationException();
var actions = new List<Action<IDictionary<string, Object>>>();
ParameterExpression actionArguments =
Expression.Parameter(dicType, "actionArguments");
foreach (var k in allKeys) {
Expression key = Expression.Constant(k, typeof(string));
Expression target = Expression.Property(actionArguments, "Item", …
Run Code Online (Sandbox Code Playgroud) 我的 DOTNET 6 API 中有一个DbContext
名称:FileManagerContext
public class FileManagerContext : DbContext {
public FileManagerContext(DbContextOptions<FileManagerContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly);
}
}
Run Code Online (Sandbox Code Playgroud)
它非常简单,DbContext
里面有一个简单的实体。无论如何,我appsettings.json
也有这个:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=FM;User=SA;Password=1234;"
},
"AllowedHosts": "*"
}
Run Code Online (Sandbox Code Playgroud)
这是Program.cs
顶级声明中的启动片段:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<FileManagerContext>(
opt => opt.UseSqlServer("name=DefaultConnection"));
Run Code Online (Sandbox Code Playgroud)
我可以在这种情况下使用迁移。一切顺利。我可以添加迁移并且可以成功更新数据库。但是当我运行该应用程序并尝试使用时,DbContext
出现此错误:
System.InvalidOperationException:使用了命名连接字符串,但在应用程序的配置中找不到名称“DefaultConnection”。请注意,仅在使用“IConfiguration”和服务提供程序时才支持命名连接字符串,例如在典型的 ASP.NET Core 应用程序中。有关详细信息,请参阅 https://go.microsoft.com/fwlink/?linkid=850912 。
我也尝试过像这样获取连接字符串:
var cs = builder.Configuration.GetConnectionString("DefaultConnection"); …
Run Code Online (Sandbox Code Playgroud) 我正在使用Eto gui框架.我在他们的源代码中看到了一些魔法语法; 例如:
int x;
int? x;
void func(int param);
void func(int? param);
Run Code Online (Sandbox Code Playgroud)
有什么不同?我很迷惑.而这个符号?
很难谷歌.
首先:我知道关于这个话题已经有很多问题了.但我真的找不到任何解决方案.我的问题是我使用抽象方法从dbset中进行选择.我的代码看起来像这样:
var dbe = (from i in dbEntities where IsEqualRecord(me, i) select i);
Run Code Online (Sandbox Code Playgroud)
这是我的抽象方法deklaration:
protected abstract bool IsEqualRecord(MEntity modelEntities, DEntity databaseEntity);
Run Code Online (Sandbox Code Playgroud)
MEntity
并且DEntity
是通用类型.我已经读过我的where语句无法转换为sql语句.但是我该如何解决这个问题呢?还有其他方法吗?
请不要投票结束这个问题.我已经看了几乎所有关于stackoverflow的类似问题,但我找不到解决方案.
我在服务中有一项业务,我不知道线程需要多长时间才能完成其工作,因此我无法设置确切的时间间隔。或者以另一种方式,我想知道在前一个线程完成工作后如何设置线程启动。
我有一个ComboBox
看起来像这样的:
<ComboBox
ItemsSource="{Binding JobList}"
SelectedValue="{Binding Job,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
DisplayMemberPath="Title"
SelectedValuePath="Id"
IsEditable="True"
StaysOpenOnEdit="True"
/>
Run Code Online (Sandbox Code Playgroud)
它与 my 的绑定ViewModel
如下所示:
public class ViewModel {
// this will fill from a database record for a person
public Job Job {
get { return _job; }
set {
if(value == _job) return;
_job = value;
OnPropertyChanged( () => Job );
}
}
// this will fill from all jobs records in database
public ObservableCollection<Job> JobList
{ /* do same as Job to implementing INotifyPropertyChanged …
Run Code Online (Sandbox Code Playgroud) 如何注册条件装饰的SimpleInjector
?以下是我的定义:
public interface ICommand { }
public interface ICleanableCommand : ICommand {
void Clean();
}
public interface ICommandHandler<in TCommand>
where TCommand : ICommand {
void Handle(TCommand command);
}
public class CleanableCommandHandlerDecorator<TCommand>
: ICommandHandler<TCommand>
where TCommand : ICleanableCommand {
private readonly ICommandHandler<TCommand> _handler;
public CleanableCommandHandlerDecorator(
ICommandHandler<TCommand> handler) {
_handler = handler;
}
void ICommandHandler<TCommand>.Handle(TCommand command) {
command.Clean();
_handler.Handle(command);
}
}
Run Code Online (Sandbox Code Playgroud)
而我正在努力:
container.RegisterManyForOpenGeneric(
typeof(ICommandHandler<>),
AppDomain.CurrentDomain.GetAssemblies()
);
container.RegisterDecorator(
typeof(ICommandHandler<>),
typeof(CleanableCommandHandlerDecorator<>)
// ,context => context.ImplementationType ???
// I want to …
Run Code Online (Sandbox Code Playgroud) .net dependency-injection decorator inversion-of-control simple-injector
c# ×9
.net ×3
.net-core ×3
.net-6.0 ×1
asp.net ×1
asp.net-mvc ×1
c#-8.0 ×1
combobox ×1
decorator ×1
ef-core-6.0 ×1
expression ×1
jwt ×1
lambda ×1
linq ×1
mvvm ×1
openid ×1
quartz.net ×1
reflection ×1
wcf-binding ×1
wpf ×1