在ASP.NET核心2.X我是用静态方法GetExpressionText的ExpressionHelper类IHtmlHelper<T>扩展方法:
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
public static class HtmlHelperExtensions
{
public static string GetExpressionText<TModel, TResult>(
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression)
{
return ExpressionHelper.GetExpressionText(expression);
}
}
Run Code Online (Sandbox Code Playgroud)
在ASP.NET Core 3.0中,命名空间Microsoft.AspNetCore.Mvc.ViewFeatures.Internal不再可用。因此,编译器将引发异常:
名称“ ExpressionHelper”在当前上下文中不存在。
什么是ExpressionHelper功能的适当替代品?
我将 ASP.NET MVC Core 7.0 网站升级到 ASP.NET MVC Core 8.0。该站点使用 OpenID Connect 身份提供商进行登录。
更新后,我的sub索赔在集合中丢失了ClaimsPrincipal.Identity.Claims。我会得到:
System.NullReferenceException:“未将对象引用设置为对象的实例。”
当试图获得sub索赔时:
string userId = User.Identity.FindFirst("sub").Value;
Run Code Online (Sandbox Code Playgroud)
经过进一步检查,我注意到该sub声明实际上被重新映射到另一个不同的声明:
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier
尽管在启动配置中删除了默认的 JWT 令牌映射(以前在 ASP.NET Core 7.0 及更早版本中有效),但还是会发生这种情况:
System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
Web.Config 中的成员资格和角色提供者的等效配置是什么:
<appSettings>
<add key="enableSimpleMembership" value="true" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
在 ASP.NET MVC 4 中?
当应用程序从一个URL导航到另一个URL时,Aurelia路由和呈现管道中的执行顺序是什么?
在 Elasticsearch.NET 6.x 中,可以使用以下IElasticClient方法检查索引是否存在:
bool exists = elasticClient.IndexExists("my-index-name").Exists;
Run Code Online (Sandbox Code Playgroud)
在 Elasticsearch.NET 版本 7 中删除了方法。
我正在使用Aurelia构建单页应用程序,并且在加载新路线的视图期间出现错误:
错误[应用程序路由器]类型错误:无法读取未定义的属性'attrToRemove'
Automapper版本8.0.0从ResolveUsing扩展方法中删除了扩展方法,IMappingExpression并将其与MapFrom扩展方法合并。但是,ResolveUsing用MapFrom方法替换后,某些配置会引发异常。
原件ResolveUsing:
CreateMap<SourceType, DestinationType>()
.ForMember(dest => dest.Customer,
opt => opt.ResolveUsing(src => src?.Customer ?? new Customer())
);
Run Code Online (Sandbox Code Playgroud)
替换为MapFrom:
CreateMap<SourceType, DestinationType>()
.ForMember(dest => dest.Customer,
opt => opt.MapFrom(src => src?.Customer ?? new Customer())
);
Run Code Online (Sandbox Code Playgroud)
产生编译错误:
错误CS8072
自动映射器
表达式树lambda不得包含空传播运算符。
当将输入数据作为a发布FormData到ASP.NET Core MVC控制器时,默认情况下将空字符串值强制为这些null值。
但是,当将输入数据作为JSON发送到控制器时,空字符串值保持原样。验证string属性时,这会导致不同的行为。例如,descriptionfield未绑定到null,而是绑定到服务器上的空字符串:
{
value: 1,
description: ""
}
Run Code Online (Sandbox Code Playgroud)
从而使以下模型无效,即使Description不是必需的:
public class Item
{
public int Value { get; set; }
[StringLength(50, MinimumLength = 3)]
public string Description { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这与通过表单提交相同数据时的行为相反。
有没有一种方法可以使JSON的模型绑定行为与表单数据的模型绑定行为相同(默认情况下,空字符串强制转换为null)?
aurelia ×2
c# ×2
asp.net ×1
asp.net-core ×1
automapper ×1
automapper-8 ×1
json.net ×1
nest ×1
roleprovider ×1
web-config ×1