此处将为大家介绍关于@NotNull注释无法按预期方式工作的详细内容,并且为您解答有关notnull注解不生效的相关问题,此外,我们还将为您介绍关于AllowAnonymous在WebAPI中无法按预
此处将为大家介绍关于@NotNull注释无法按预期方式工作的详细内容,并且为您解答有关notnull注解不生效的相关问题,此外,我们还将为您介绍关于AllowAnonymous 在 Web API 中无法按预期工作、Angular 5%管道digitInfo无法按预期工作、Angular2动画:: Easings无法按预期工作、c# – MEF导入无法按预期工作的有用信息。
本文目录一览:- @NotNull注释无法按预期方式工作(notnull注解不生效)
- AllowAnonymous 在 Web API 中无法按预期工作
- Angular 5%管道digitInfo无法按预期工作
- Angular2动画:: Easings无法按预期工作
- c# – MEF导入无法按预期工作
@NotNull注释无法按预期方式工作(notnull注解不生效)
我有一个终结点实现,即将一个对象传递给参数列表。我正在尝试使用@NotNull批注来验证该对象是否为null。
@POST @Path("path") public Response endpointMethod(@NotNull @ApiParam(value = "abc", required = true) Object object) { return Response.status(Status.OK).build(); }
如果该对象被验证为非null,则端点将仅返回200
OK响应。但是,当我使用指定的路径向该终结点发出请求时,体内没有任何内容时,不会引发任何错误。相反,我能够检索200响应(即使我在返回响应之前检查对象是否为null,也表明是这种情况)。
有人可以指导我如何以正确的方式验证对象是否为空吗?
答案1
小编典典如果您对类路径具有bean验证依赖项(org.glassfish.jersey.ext:jersey-bean-
validation:2.22.2),则应由框架来选择它并立即使用。
还要确保您的@NotNull批注来自javax.validation.constraints包
AllowAnonymous 在 Web API 中无法按预期工作
如何解决AllowAnonymous 在 Web API 中无法按预期工作?
在 ASP.NET CORE 3.1 服务器端 Blazor 应用中,我无法让 AllowAnonymous 用于 post 类型的请求 Web API。 get 请求没有任何问题。
连同解决方案一起工作,请告诉我所需的安全性。也许我在试验中降低了安全性以使发布请求工作。
每一个 post 请求都会出现这 3 个日志:
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
....
services.AddIdentity<ApplicationUser,ApplicationRole>()
.AddDefaultUI()
.AddEntityFrameworkStores<EpisodeContext>();
services.AddMvc(options=> {
options.RespectbrowserAcceptHeader = true; })
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddRazorPages();
services.AddServerSideBlazor().AddCircuitOptions(option => { option.DetailedErrors = true; });
services.AddScoped<AuthenticationStateProvider,RevalidatingIdentityAuthenticationStateProvider<ApplicationUser>>();
services.AddHttpContextAccessor();
services.AddAuthorization(config =>
{
config.FallbackPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
config.AddPolicy("RequireAdministratorRole",policy => policy.RequireRole("admin"));
});
...
}
public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
API 控制器:
[AllowAnonymous]
[Route("api/[controller]")]
[ApiController]
[Produces("application/json")]
public class DailyContentController : ControllerBase
{
[HttpPost("likeepisode"),AllowAnonymous]
public async Task<bool> LikeEpisode(string episodenumber)
{
bool result = await _CDService.LikeEpisode(episodenumber);
return result;
}
}
Plesk 主机设置:
Web 应用防火墙
解决方法
我已经能够通过在托管设置中将首选域设置为无来阻止意外重定向:
Angular 5%管道digitInfo无法按预期工作
{{0.7 | percent:'1.2-5'}}
我按预期得到了这个:70.00%
但是,当我这样做时:
{{0.07 | percent:'1.2-5'}}
我得到7.00000%而不是预期的7.00%
我只是做错了什么或者这是Angular中的一个错误?
解决方法
{{0.7 | percent:'1.2'}} --> 70.00% {{0.07 | percent:'1.2'}} --> 7.00%
Angular2动画:: Easings无法按预期工作
// component.ts import {Component,Directive,Input} from '@angular/core'; import {trigger,state,style,transition,animate} from '@angular/core' @Component({ selector: 'expandable',template: '<div *ngIf="isExpanded" @animate="'slide'"><ng-content></ng-content></div>',animations: [ trigger('animate',[ state('slide',style({ overflow: 'hidden',height: '*' })),transition('slide => void',[animate('200ms ease-out',style({ height: 0 }))]),transition('void => slide',[style({ height: 0 }),animate('200ms ease-out',style({ height: '*' }))]) ]) ] }) export class SimExpandable { private _expanded: boolean = false; @Input('expanded') set expanded(value: string | boolean) { this._expanded = (value === 'true' || value === true); } get isExpanded(): boolean { return this._expanded } }
该组件部分工作正常.然而,动画并不完美.我已经将组件配置为使用缓出动画,但实际上,组件是线性动画的.
我尝试过使用缓出,eaSEOut,缓出立方,eaSEOutCubic,easy-in-out,easeInOut,bounce和许多其他排列,但该组件仍然是线性动画.我真的需要为我的组件使用缓出.任何帮助将非常感激.
解决方法
CSS properties transition and animation allow you to pick the easing
function. Unfortunately,they don’t support all easings and you must
specify the desired easing function yourself (as a Bezier curve).
Easings.net
似乎有4种默认类型的缓动应该有效.
>线性
>轻松
>安慰
>缓解
>轻松进出
这些工作直接,但差异是微妙的
对于更有效的缓动类型,您必须使用贝塞尔曲线,它允许您创建自己的缓动.例如,下面是“easeInOutBack”
cubic-bezier(0.680,-0.550,0.265,1.550)
使用Angular动画功能时
animate("1500ms 2000ms cubic-bezier(0.680,1.550)",style({transform: "translateX(-100%)"}))
您可以导航到这个bezier curver generator,它可以让您创建自己的缓动.
c# – MEF导入无法按预期工作
[Export(typeof(Mod))] public class CoreMod : Mod { [ImportingConstructor] public CoreMod() { //here goes my constructor } } [Export(typeof(Mod))] public class AnotherMod : Mod { [ImportingConstructor] public AnotherMod() { //here goes my constructor } }
CoreMod在我的主程序集中,AnotherMod在外部程序集中. Mod是另一个程序集,它们都引用它们.
在我的应用程序中,我有一个类,它试图通过MEF加载Mods:
class ModManager { [ImportMany(typeof(Mod))] public static IEnumerable<Mod> Mods { get; set; } public List<Mod> LoadedMods { get; set; } public ModManager() { AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(CoreMod).Assembly)); catalog.Catalogs.Add(new DirectoryCatalog( Path.GetDirectoryName( new Uri(Assembly.GetExecutingAssembly() .CodeBase).LocalPath))); var container = new CompositionContainer(catalog); container.ComposeParts(this); LoadedMods = Mods.ToList(); } }
在我看来应该满足所有导入,但它仍然无法导入任何东西(Mods为null).我究竟做错了什么?
解决方法
class ModManager { [ImportMany(typeof(Mod))] public IEnumerable<Mod> Mods { get; set; } public List<Mod> LoadedMods { get; set; } CompositionContainer _container; public ModManager() { AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(CoreMod).Assembly)); catalog.Catalogs.Add(new DirectoryCatalog( Path.GetDirectoryName( new Uri(Assembly.GetExecutingAssembly() .CodeBase).LocalPath))); _container = new CompositionContainer(catalog); this._container.ComposeParts(this); this.LoadedMods = this.Mods.ToList(); } }
关于@NotNull注释无法按预期方式工作和notnull注解不生效的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于AllowAnonymous 在 Web API 中无法按预期工作、Angular 5%管道digitInfo无法按预期工作、Angular2动画:: Easings无法按预期工作、c# – MEF导入无法按预期工作的相关知识,请在本站寻找。
本文标签: