小编TjD*_*haw的帖子

使用React.NET导入意外的令牌

意外的令牌导入

从'react-image-gallery'导入ImageGallery;

我的jsx文件中有关键字的问题.怎么解决?我使用.NET 4.6和React.NET 3.0.与require关键字相同.

ReferenceError:未定义require

c# asp.net reactjs

5
推荐指数
0
解决办法
290
查看次数

在MVC 5中将JWT令牌存储在cookie中

我想在我的MVC应用中进行JWT身份验证。我在Web API中制作了授权Web服务,可以正确返回令牌。之后,我试图将令牌存储在cookie中。

 [HttpPost]
    public async Task<ActionResult> Login(LoginDto loginDto)
    {
        var token = await loginService.GetToken(loginDto);

        if (!string.IsNullOrEmpty(token))
        {
            var cookie = new System.Web.HttpCookie("token", token)
            {
                HttpOnly = true
            };
            Response.Cookies.Add(cookie);
            return RedirectToAction("Index", "Product");
        }
        return View("LoginFailed");
    }
Run Code Online (Sandbox Code Playgroud)

但是现在我想将此令牌添加到每个请求的标头中。因此,我认为动作过滤器将是实现此目标的最佳选择。

public class CustomActionFilter : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var token = filterContext.HttpContext.Request.Cookies.Get("token");

        if (token != null)
            filterContext.HttpContext.Request.Headers.Add("Authorization", $"Bearer {token}");

        base.OnActionExecuting(filterContext);
    }
}
Run Code Online (Sandbox Code Playgroud)

启动

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        AutofacConfig.Configure();
        AreaRegistration.RegisterAllAreas();
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

        ConfigureOAuth(app);
    }

    public …
Run Code Online (Sandbox Code Playgroud)

cookies asp.net-mvc jwt

5
推荐指数
1
解决办法
2602
查看次数

.NET Core - 在集成测试中获取父程序集名称

我有使用Microsoft.AspNetCore.TestHost包托管在内存中的集成测试项目。然后我有用于这些测试的库。我想我的库中获取测试项目的 程序集名称。所以结构看起来像这样。

TestHost --> TestProject --> MyLibrary
Run Code Online (Sandbox Code Playgroud)

我所做的是尝试调用以下方法:

Assembly.GetExecutingAssembly() 返回 MyLibrary 程序集

Assembly.GetCallingAssembly() 返回 MyLibrary 程序集

Assembly.GetEntryAssembly() 返回 TestHost 程序集。

通过将程序集从 TestProject 传递到 MyLibrary ,有什么方法可以在不明确指定的情况下获得它?

编辑

正如@svoychik 所建议的那样,我也尝试Assembly.GetCallingAssembly()直接从调用的方法中TestProject调用,MyLibrary但这会返回:

System.Private.CoreLib,版本=4.0.0.0,文化=中性,

c# .net-assembly .net-core

5
推荐指数
1
解决办法
609
查看次数

当 CPU 处于高压状态时,Akka.NET 具有持久性丢弃消息?

我对我的 PoC 进行了一些性能测试。我看到的是我的演员没有收到发送给他的所有消息,而且表现非常低。我向我的应用程序发送了大约 150k 条消息,这导致我的处理器达到 100% 利用率的峰值。但是当我停止发送请求时,2/3 的消息没有传递给参与者。以下是来自应用洞察的简单指标:

发送的请求数

收到的消息数

为了证明我在 mongo 中持久化的事件数量与我的演员收到的消息数量几乎相同。

蒙戈

其次,处理消息的性能非常令人失望。我每秒收到大约 300 条消息。 每秒消息

我知道默认情况下 Akka.NET 消息传递最多一次,但我没有收到任何错误消息说消息已被丢弃。

这是代码:集群分片注册:

 services.AddSingleton<ValueCoordinatorProvider>(provider =>
 {
   var shardRegion = ClusterSharding.Get(_actorSystem).Start(
                    typeName: "values-actor",
                    entityProps: _actorSystem.DI().Props<ValueActor>(),
                    settings: ClusterShardingSettings.Create(_actorSystem),
                    messageExtractor: new ValueShardMsgRouter());
                   return () => shardRegion;
 });
Run Code Online (Sandbox Code Playgroud)

控制器:

    [ApiController]
    [Route("api/[controller]")]
    public class ValueController : ControllerBase
    {
        private readonly IActorRef _valueCoordinator;

        public ValueController(ValueCoordinatorProvider valueCoordinatorProvider)
        {
            _valueCoordinator = valuenCoordinatorProvider();
        }

        [HttpPost]
        public Task<IActionResult> PostAsync(Message message)
        {
            _valueCoordinator.Tell(message);
            return Task.FromResult((IActionResult)Ok());
        }
    }
Run Code Online (Sandbox Code Playgroud)

演员:

    public class ValueActor : ReceivePersistentActor
    {
        public override …
Run Code Online (Sandbox Code Playgroud)

akka.net akka.net-cluster akka.net-persistence

4
推荐指数
1
解决办法
443
查看次数

Func委托中的任务<T>和任务

嘿伙计们,我想清理一些代码.我有重载方法.我可以以某种方式简单地使用这个代码并在另一个方法中调用一个方法吗?无法弄清楚如何做到这一点.

private async Task<T> DecorateWithWaitScreen<T>(Func<Task<T>> action)
{
    SplashScreenManager.ShowForm(this, typeof(WaitForm), true, true, false);
    try
    {
        return await action();

    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
        throw;
    }
    finally
    {
        SplashScreenManager.CloseForm(false);
    }
}

private async Task DecorateWithWaitScreen(Func<Task> action)
{
    SplashScreenManager.ShowForm(this, typeof(WaitForm), true, true, false);
    try
    {
        await action();
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
        throw;
    }
    finally
    {
        SplashScreenManager.CloseForm(false);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# func task-parallel-library

3
推荐指数
1
解决办法
743
查看次数

Autofac.Core.Registration.ComponentNotRegisteredException

我试图在我的应用程序中实现CQRS模式.所以我在这里找到了如何从程序集中注册所有命令处理程序:Autofac解决CQRS CommandDispatcher中的依赖关系

但它对我来说效果不佳.这是代码:

        containerBuilder.RegisterAssemblyTypes(assembly)
            .AsClosedTypesOf(typeof(ICommandHandler<>));

        containerBuilder.RegisterAssemblyTypes(assembly)
            .AsClosedTypesOf(typeof(IQueryHandler<,>));
Run Code Online (Sandbox Code Playgroud)

处理工厂

 public class CqrsHandlerFactory : ICqrsHandlerFactory
{
    private readonly IContainer container;

    public CqrsHandlerFactory(IContainer container)
    {
        this.container = container;
    }

    public ICommandHandler<TCommand> GetCommandHandler<TCommand>(TCommand command) where TCommand : class, ICommand
    {
        return container.Resolve<ICommandHandler<TCommand>>();
    }

    public IQueryHandler<TQuery, object> GetQueryHandler<TQuery>(TQuery query) where TQuery : class, IQuery
    {
        return container.Resolve<IQueryHandler<TQuery, object>>();
    }
}
Run Code Online (Sandbox Code Playgroud)

总线

 public class CqrsBus : ICqrsBus
{
    private readonly ICqrsHandlerFactory cqrsHandlerFactory;

    public CqrsBus(ICqrsHandlerFactory cqrsHandlerFactory)
    {
        this.cqrsHandlerFactory = cqrsHandlerFactory;
    }

    public void ExecuteCommand(ICommand …
Run Code Online (Sandbox Code Playgroud)

c# autofac cqrs .net-core

1
推荐指数
1
解决办法
6547
查看次数