简体   繁体   English

C# 方法适用于本地 Web 服务器,但不适用于 azure Web 应用程序。 找不到文件错误

[英]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.

相关问题 测试对于本地Web应用程序运行太慢。 使用C#Selenium WebDriver - Tests are running too slow for local web app. using C# Selenium WebDriver Azure Web 应用程序。 指定的 CGI 应用程序遇到错误,服务器终止该进程 - Azure Web App. The specified CGI application encountered an error and the server terminated the process C#Web API可在本地计算机上运行,​​但不能在服务器上运行 - C# Web API works on local machine but not on server C#Asp.NET内部Web应用程序:从其他本地服务器复制文件 - C# Asp.NET Internal Web App: Copy file from a different local server 如何使用C#Web方法在服务器上保存文件 - how to save file on server using C# Web method C# 如何解决 Web 客户端上传文件“远程服务器返回错误:(405)方法不允许。”? - C# How to solve Web Client Upload file “The remote server returned an error: (405) Method Not Allowed.”? 在Azure上部署的Web无法访问.less文件(错误代码404)。 本地IIS部署可以正常工作 - Deployed web on Azure cannot access a .less file (error code 404). Local IIS deployment works without error 使用C#创建Azure Web应用程序 - Create an Azure Web App Using C# 在Azure Web应用中发布出现服务器错误 - Published in Azure web app appears a server error Twilio SMS 无法通过部署到 Web 服务器的 ASP.NET MVC C# web 工作(但在本地测试环境中工作正常) - Twilio SMS not working via ASP.NET MVC C# web deployed to Web Server (but works fine in local test environment)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM