[英]C# method works in local web server but not in azure web app. File not found error
I'm using a library called FirmadorXadesNetCore to sign xml files.我正在使用一个名为 FirmadorXadesNetCore 的库来签署 xml 文件。 I have imported it using the nuget package manager in VS2019 and I'm using version 1.1.0.
我在 VS2019 中使用 nuget 包管理器导入了它,我使用的是 1.1.0 版。
The problem occurs when calling line调用线路时出现问题
parametros.Signer = new FirmaXadesNetCore.Crypto.Signer(cert);
Running the web app using a local IIS Server, it works ok, but using Azure Web App it throws an error "File not found".使用本地 IIS 服务器运行 Web 应用程序,它工作正常,但使用 Azure Web 应用程序会引发错误“找不到文件”。
The cert variable loads the certificate correctly in both environments, so I'm not sure what the problem is. cert 变量在两种环境中都正确加载了证书,所以我不确定问题是什么。
Any insight would be appreciated.任何见解将不胜感激。
I think this error occurred because the .xml
file was not found.我认为发生此错误是因为未找到
.xml
文件。
The reason is that when the program is released, only the default files and folders will be included, and the customized ones will not be included.原因是程序发布时,只会包含默认的文件和文件夹,不会包含自定义的文件和文件夹。 You need to modify the
.csproj
to achieve.您需要修改
.csproj
才能实现。
Solution steps:解决步骤:
1. Check whether the .xml
file exists through kudu. 1.通过kudu检查
.xml
文件是否存在。
2. If it does not exist, modify the content of the published file by modifying the .csproj
file. 2.如果不存在,通过修改
.csproj
文件来修改发布文件的内容。
The modified sample code is as follows:修改后的示例代码如下:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ResolvedFileToPublish Include="test.xml">
<RelativePath>TextFile.txt</RelativePath>
</ResolvedFileToPublish>
</ItemGroup>
</Project>
For more details, You can check my answer in another post .有关更多详细信息,您可以在另一篇文章中查看我的答案。
I contacted Microsoft Azure support, and it turns out that the local cert store is used in order to read the certificate.我联系了 Microsoft Azure 支持,结果是使用本地证书存储来读取证书。
I have been using a Free tier for testing purposes and Microsoft pointed me out that the free tier or shared tier are not allowed to access the cert store.我一直在使用免费层进行测试,微软指出免费层或共享层不允许访问证书存储。 The solution was to upgrade to at least a basic plan.
解决方案是升级到至少一个基本计划。
Here is the link on how to load the certificates and it states it works for basic plans and above https://docs.microsoft.com/en-us/azure/app-service/configure-ssl-certificate-in-code#load-certificate-from-file这是有关如何加载证书的链接,它说明它适用于基本计划及以上https://docs.microsoft.com/en-us/azure/app-service/configure-ssl-certificate-in-code#从文件加载证书
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.