我有一个带有EF Core 1.1的.NET Core 1.1 API,并使用Microsoft的vanilla设置使用依赖注入为我的服务提供DbContext.(参考:https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro#register-the-context-with-dependency-injection)
现在,我正在研究使用WhenAll将数据库读取并行化为优化
所以代替:
var result1 = await _dbContext.TableModel1.FirstOrDefaultAsync(x => x.SomeId == AnId);
var result2 = await _dbContext.TableModel2.FirstOrDefaultAsync(x => x.SomeOtherProp == AProp);
Run Code Online (Sandbox Code Playgroud)
我用:
var repositoryTask1 = _dbContext.TableModel1.FirstOrDefaultAsync(x => x.SomeId == AnId);
var repositoryTask2 = _dbContext.TableModel2.FirstOrDefaultAsync(x => x.SomeOtherProp == AProp);
(var result1, var result2) = await (repositoryTask1, repositoryTask2 ).WhenAll();
Run Code Online (Sandbox Code Playgroud)
这一切都很好,直到我在这些DB Repository访问类之外使用相同的策略,并在我的控制器中使用WhenAll在多个服务中调用这些相同的方法:
var serviceTask1 = _service1.GetSomethingsFromDb(Id);
var serviceTask2 = _service2.GetSomeMoreThingsFromDb(Id);
(var dataForController1, var dataForController2) = await (serviceTask1, serviceTask2).WhenAll();
Run Code Online (Sandbox Code Playgroud)
现在当我从我的控制器调用它时,随机我将得到并发错误,如:
System.InvalidOperationException:ExecuteReader需要一个开放且可用的连接.连接的当前状态已关闭.
我相信的原因是因为有时这些线程会尝试同时访问相同的表.我知道这是EF …
我在我的Spring MVC应用程序中使用Spring Security 3.2.3并获得一些意外行为.
根据这里的文档,应该可以${_csrf.token}
在我的html的meta标签中使用:
<meta name="_csrf" content="${_csrf.token}" />
<!-- default header name is X-CSRF-TOKEN -->
<meta name="_csrf_header" content="${_csrf.headerName}" />
Run Code Online (Sandbox Code Playgroud)
从中我使用JQuery提取"内容"的值,并使用AJAX将其放入Request Header.
出于某种原因,Spring Security不会将其"转换"为实际令牌,它只是作为文字字符串"$ {_ csrf.token}"发送到标头中.
${_csrf.token}
根据文档尝试在隐藏输入中使用的替代路径,然后我尝试通过检查输入的值来检查令牌评估的内容,但它仍然只是纯文本"$ {_ csrf.token}".
由于Spring Security似乎没有生效,我是否缺少某种配置?我目前正在使用准系统Spring Security Java配置(而不是xml),如下所示:
import org.springframework.context.annotation.*;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.*;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf();
}
}
Run Code Online (Sandbox Code Playgroud)
我知道配置被调用,因为我在其中放入了一个调试语句,因此我假设CSRF保护确实已启用,因为它应该是默认的.
我意识到语法"$ {}"是JSP表达式语言,我目前正成功地用它来评估Thymeleaf对象的上下文,例如:
th:object="${context}"
Run Code Online (Sandbox Code Playgroud)
所以我尝试在元标记的"内容"前添加"th:",如下所示:
<meta name="_csrf" th:content="${_csrf.token}"/>
Run Code Online (Sandbox Code Playgroud)
但它导致一个例外,无法评估:
评估SpringEL表达式的异常:"_csrf.token"
我认为这里的关键可能是弄清楚如何在我看来正确评估表达式.
我想在给定目录中的所有子目录中初始化存储库.由于其中大约有200个(遗留项目),我想用Powershell自动化它.到目前为止,我有:
$items = Get-ChildItem -Path "."
foreach ($item in $items)
{
if ($item.Attributes -eq "Directory")
{
$git = "C:\Program Files (x86)\Git\cmd\git"
& $git "init"
}
}
Run Code Online (Sandbox Code Playgroud)
显然我错过了一个我在循环中使用每个子目录的行.在目前的形式中,我相信所有这一切都在同一目录(".")中反复调用"git init",那么从每个子目录中调用git init的方法是什么?有没有办法暂时"cd"到找到的每个子目录?
我尝试过天真的样子
& $item.Name + "\git init"
Run Code Online (Sandbox Code Playgroud)
但由于显而易见的原因,它不喜欢这样.
我们安排了一个 Windows 任务来启动一些自定义代码(作为可执行文件),每 15 分钟检查一次文件是否存在。
如果最终找到该文件,我们的服务会对其进行一些处理。问题在于:处理文件后,业务要求任务计划程序停止这些 15 分钟的检查,直到第二天。
有没有办法将逻辑插入到 Windows 任务计划程序中,以便在满足某些条件后停止运行其触发器?或者有更好的方法来构建这个流程吗?
我们使用 Windows Server 2008 R2 Standard SP1 来运行它。
我在GCP项目中设置了Cloud Build触发器,以便通过.yaml文件从Cloud Source Repository部署Cloud Function。一切似乎都已正确设置,并根据官方文档授予了权限,但是当我通过手动运行触发器来测试触发器时,出现以下错误:
错误:(gcloud.functions.deploy)响应错误:状态= [403],代码= [禁止],消息= [缺少对资源[MY_SERVICE_ACCOUNT]的必需的权限iam.serviceAccounts.actAs。请授予角色/iam.serviceAccountUser角色。您可以通过运行“ gcloud iam服务帐户add-iam-policy-binding [MY_SERVICE_ACCOUNT] --member = --role = roles / iam.serviceAccountUser']来完成此操作
现在,首先,因为建议的语法错误(缺少“ member =“的值),所以运行建议的命令甚至无法正常工作。但更重要的是,我已经将该角色添加到错误消息所抱怨的服务帐户中。我尝试从UI和CLI删除它,然后将其重新添加,但始终会显示此错误。
为什么?
google-cloud-platform google-iam google-cloud-iam google-cloud-build
asynchronous ×1
csrf ×1
dbcontext ×1
directory ×1
git ×1
google-iam ×1
powershell ×1
spring-mvc ×1
thymeleaf ×1
windows ×1