javadoc表示File.pathSeparatorChar
:
与系统相关的路径分隔符.此字段初始化为包含系统属性path.separator的值的第一个字符.此字符用于分隔作为路径列表给出的文件序列中的文件名.在UNIX系统上,此字符是
:
; 在Microsoft Windows系统上它是;
.
但这看起来很奇怪,因为分号不是Windows路径的禁用字符(对于引用,这些是\
/
:
*
?
"
<
>
|
Windows资源管理器的重命名功能).
例如,使用以下代码:
String test = "C:\\my;valid;path" + File.pathSeparator + "C:\\Windows";
String[] tests = test.split(File.pathSeparator);
Run Code Online (Sandbox Code Playgroud)
tests
将包含C:\\my
valid
path
C:\\Windows
,这不是它所期望的.
所以问题是:为什么这个字符不是冒号,就像在Unix上一样?我可以强制我的代码使用冒号,但这似乎打败了在JDK中保持常量的目的.
编辑:Reimeus解释了为什么它不能成为Windows上的冒号(它是驱动器分隔符),但我真正感兴趣的是它不是一个不能出现在路径中的字符的原因,例如|
.
我正在实现一个 Roslyn 分析器,我想根据 csproj 中某些属性的设置方式采取不同的操作。
目前,我通过在使用分析器导入的 props 文件中设置“AdditionalFiles”节点来实现此目的。这指向 .csproj,然后我手动对项目文件进行 xml 解析,查找我关心的属性。
<ItemGroup>
<AdditionalFiles Include="$(ProjectPath)" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
private void AnalyzeAdditionalFiles(CompilationStartAnalysisContext context)
{
ICompilationStartAnalysisContextWrapper wrappedContext = this.compilationStartAnalysisContextWrapperFactory.Create(context);
if (wrappedContext.GetAdditionalTexts()
.Any(addtionalFile => <xml parse and validate csproj>))
{
context.RegisterSyntaxNodeAction(this.AnalyzeSyntaxNode, PossibleSyntaxKinds);
}
}
Run Code Online (Sandbox Code Playgroud)
我被告知可能有一种一流的受支持方法来执行其中一个或两个操作,而不需要感觉像黑客版本的:
这可能吗?理想情况下,我会寻找道德上的等价物
AnalysisContext.Project.Properties["MyCustomProp"]
Run Code Online (Sandbox Code Playgroud) 我有一个kendoui网格列出索赔.其中一列是贷方,它是贷方表的外键引用.我想要的是能够在网格中显示贷方名称而不是其id引用.
我已按如下方式设置贷方数据源
var dsLenders = new kendo.data.DataSource({
transport: {
read: {
url: "../data/lenders/",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation === "read") {
return options;
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
并且网格看起来像这样
$("#gridClaims").kendoGrid({
dataSource: claimData,
autoSync:true,
batch: true,
pageable: {
refresh: true,
pageSizes: true
},
filterable: true,
sortable: true,
selectable: "true",
editable: {
mode: "popup",
confirmation: "Are you sure you want to delete this record?",
template: $("#claimFormPopup").html()
},
navigable: true, // enables keyboard navigation in the grid
toolbar: ["create"], // …
Run Code Online (Sandbox Code Playgroud) 在我的 Azure Linux Web 应用程序中,我尝试使用证书对外部提供商执行 API 调用。该调用失败了,但在 Windows 应用服务计划上部署相同的代码时它工作正常。等效的 cURL 命令行是:
curl --cert-type p12 --cert /var/ssl/private/THUMBPRINT.p12 -X POST https://www.example.com
Run Code Online (Sandbox Code Playgroud)
调用失败并出现以下错误:
curl: (58) could not load PKCS12 client certificate, OpenSSL error error:140AB18E:SSL routines:SSL_CTX_use_certificate:ca md too weak
Run Code Online (Sandbox Code Playgroud)
该问题是由 OpenSSL 1.1.1d 引起的,默认情况下要求安全级别为 2,而我的证书是使用 RSA 加密的 SHA1 进行签名的:
openssl pkcs12 -in THUMBPRINT.p12 -nodes | openssl x509 -noout -text | grep 'Signature Algorithm'
Signature Algorithm: sha1WithRSAEncryption
Signature Algorithm: sha1WithRSAEncryption
Run Code Online (Sandbox Code Playgroud)
在普通的 Linux VM 上,我可以编辑/etc/ssl/openssl/cnf
更改
CipherString = DEFAULT@SECLEVEL=2
Run Code Online (Sandbox Code Playgroud)
安全级别为 1,但在 Azure Linux Web 应用程序上,我对该文件所做的更改不会保留。
所以我的问题是:如何更改 …
我正在尝试CustomRequestCultureProvider
在我的本地化管道中实现 a ,以从数据库中检索用户文化。为了识别用户,我需要ClaimsPrincipal
,但由于某种原因,即使用户已通过身份验证,context.User.Identity.IsAuthenticated
也始终为 false。
这是相关代码(被截断以突出我的问题:身份验证已经在工作;本地化代码基于本地化教程)。
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[]
{
new CultureInfo("fr"),
new CultureInfo("en"),
};
options.DefaultRequestCulture = new RequestCulture("fr");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
// we insert at 2, because we want to first check the query, then the cookie, then the DB, then the headers
options.RequestCultureProviders.Insert(2, new CustomRequestCultureProvider(async context =>
{
// ----->> ISSUE IS HERE: this is …
Run Code Online (Sandbox Code Playgroud) asp.net-core asp.net-core-localization asp.net-core-identity
我想使用 JSON.NET 访问嵌套值。我知道我可以使用该.SelectToken()
方法来访问嵌套值(例如,请参阅此问题或此问题)。我的问题是我尝试访问的 JSON 的键中带有点:
var json = @"
{
""data.dot"": {
""value"": 5,
}
}";
var jo = JObject.Parse(json);
Console.WriteLine(jo.SelectToken("data.dot.value")); // <-- doesn't work
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 cloud-init 添加 InfluxDB(时间序列数据库)存储库。官方文档wget
指出,要手动安装,必须首先使用(或)下载公钥curl
:
wget -qO- https://repos.influxdata.com/influxdb.key | gpg --dearmor > /etc/apt/trusted.gpg.d/influxdb.gpg
echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/ubuntu bionic stable" > /etc/apt/sources.list.d/influxdb.list
Run Code Online (Sandbox Code Playgroud)
效果很好,现在我想使用 cloud-init 自动执行此操作。
我的问题是我不知道如何在使用之前从提供的 URL 获取密钥。我试过这个:
apt:
sources:
influxdb:
source: 'deb https://repos.influxdata.com/ubuntu $RELEASE stable'
Run Code Online (Sandbox Code Playgroud)
但随后我收到 GPG 错误,指出存储库未签名。
我尝试了以下keyserver
和keyid
键的组合但没有成功:
keyserver: https://repos.influxdata.com/influxdb.key
keyserver: https://repos.influxdata.com
和keyid: influxdb.key
keyserver: https://repos.influxdata.com
和keyid: 05CE15085FC09D18E99EFB22684A14CF2582E0C5
如何获取 GPG 密钥?我可以使用Runcmd
,但如果有替代方案,我宁愿不使用。
我有一个控制器,其中包含一些在许多内部项目中使用的实用程序方法。到目前为止,我一直在每个项目中复制源文件。现在,我想为此控制器创建一个NuGet包,以在内部存储库中使用。
问题出在这个控制器的授权上。我不想[Authorize()]
在控制器类(或其动作)上放置特定的属性,因为授权应由使用该软件包的开发人员选择:在某些项目中,控制器可以被所有人使用,在某些项目中,可以使用只有经过身份验证的用户才能使用,其他用户则可以与自定义策略一起使用。
关于如何达到目的有什么想法?
根据内联文档,ControllerBase.RedirectToAction
获取操作名称和控制器名称:
// Parameters:
// actionName:
// The name of the action.
//
// controllerName:
// The name of the controller.
public virtual RedirectToActionResult RedirectToAction(string actionName, string controllerName);
Run Code Online (Sandbox Code Playgroud)
现在,让我们假设我想重定向到以下操作:
[Route("Whatever")]
public class WhateverController : Controller
{
[HttpGet("Overview")]
public IActionResult Overview()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
当然,我想使用nameof
运算符":
[Route("Home")]
public class HomeController : Controller
{
[HttpGet("Something")]
public IActionResult Something()
{
return RedirectToAction(
nameof(WhateverController.Overview), // action name
nameof(WhateverController) // controller name
);
}
}
Run Code Online (Sandbox Code Playgroud)
但是这个调用因错误而失败 InvalidOperationException: No route matches the …
asp.net-core ×3
c# ×3
azure ×1
azure-linux ×1
cloud-init ×1
foreign-keys ×1
gridview ×1
java ×1
javascript ×1
json.net ×1
kendo-ui ×1
openssl ×1
roslyn ×1