1.在测试环境中不想使用关于openiddict 不想使用https 使用http协议处理
首先在接口服务器端 AddJwtBearer 的 options.RequireHttpsMetadata = false
然后在授权服务端添加
context.Services.AddOpenIddict()
.AddServer(option =>
{
option.UseAspNetCore().DisableTransportSecurityRequirement();
});
2.在使用openiddict 中携带token去请求主服务器可能会出现
IDX20803: Unable to obtain configuration from: ‘xxxxx/.well-known/openid-configuration’
需要在主服务器端配置如下代码
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12;
3.ABP在使用hangfire配置登录账号和密码时 注意使用的授权Nuget包是
Hangfire.Dashboard.BasicAuthorization
不是Hangfire.Dashboard.Authorization 注意区别
如果使用Hangfire.Dashboard.Authorization提示 对类型“IAuthorizationFilter”的引用声称该类型是在“Hangfire.Core”中定义的,但未能找到.
4.在ABP7.0中获取到的token去请求接口可能会出现The audience ‘empty’ is invalid需要添加
context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters() //去除掉受众校验
{
ValidateAudience = false
};
})
5.ABP中用户表扩展字段(abpusers)
有2种方式
(1)不需要扩展字段来进行条件查询 注意使用这个方法必须要实现IHasExtraProperties 接口 IdentityUser已经默认实现, 这里不在赘述
user.SetProperty("Title", "My Title")
.SetProperty("IsSuperUser", true);
(2)需要扩展字段来进行条件查询
① 首先在Domain项目下定义你要扩展的字段,如:
public class CusUser
{
public string? Title { get; set; }
public bool? IsSuperUser { get; set; }
}
②在Domain.Shard中定义常量
public class CustomizeUser
{
public const string TitlePropertyName = "Title";
public const string IsSuperUserPropertyName = "IsSuperUser";
}
③ 在EntityFrameworkCore下面EfCoreEntityExtensionMappings文件新增
OneTimeRunner.Run(() =>
{
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityUser, string?>(
nameof(CusUser.Title),
(entityBuilder, propertyBuilder) =>
{
propertyBuilder.HasComment("标题");
}
);
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityUser, bool?>(
nameof(CusUser.IsSuperUser),
(entityBuilder, propertyBuilder) =>
{
propertyBuilder.HasComment("是否是超级用户");
}
);
});
④ 进行数据库迁移
Add-Migration
Update-Database
⑤在Domain.Shared项目下 ModuleExtensionConfigurator 这个文件新增
private static void ConfigureExtraProperties()
{
ObjectExtensionManager.Instance.Modules().ConfigureIdentity(identity => {
identity.ConfigureUser(user =>
{
user.AddOrUpdateProperty<string?>(CustomizeUser.Title, options =>
{
options.Attributes.Add(new StringLengthAttribute(50));
});
user.AddOrUpdateProperty<bool?>(CustomizeUser.IsSuperUser, options =>
{
});
});
});
}
⑥ 进行查询
var whereName = "ABCD"
(await userRepository.GetQueryableAsync()).Where(u => EF.Property<Guid?>(u, CustomizeUser.TitlePropertyName).Contains(whereName))
查询到的Title 和 IsSuperUser 在ExtraProperties 这个属性里
6.ABPVnext格式化返回日期datetime
接口返回的日期都是带T的, 前端不好显示
在SignBaoAppHttpApiHostModule 这个文件中新增
private void ConfigureDateTimeFormat()
{
Configure<AbpJsonOptions>(options => options.OutputDateTimeFormat = "yyyy-MM-dd HH:mm:ss");
}
- C#将XML转为JSON(带有CDATA)
public static JObject XmlToJson(this XmlDocument xmlDoc)
{
JObject json = new JObject();
foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
{
if (node is XmlElement)
{
if (node.HasChildNodes && node.FirstChild is XmlCDataSection)
{
json[node.Name] = new JValue((node.FirstChild as XmlCDataSection).Value);
}
else
{
json[node.Name] = new JValue(node.InnerText);
}
}
}
return json;
}
8.在ABPVnext中使用Func委托时需要在方法上添加[DisableValidation]才可以使用
9.在使用EF Core时可能会出现生成的SQL匹配不上数据库当前版本导致报错,可以使用如下代码来实现连接SQLSERVER时兼容性问题。
options.UseSqlServer(options => options.UseCompatibilityLevel(120));
UseSqlServer(configuration.GetConnectionString("Default"), option => option.UseCompatibilityLevel(120));
其余踩的坑慢慢更新…