记录使用ABP VNEXT的一些问题

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");
    }
  1. 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]才可以使用

其余踩的坑慢慢更新…

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值