简体   繁体   中英

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. I have imported it using the nuget package manager in VS2019 and I'm using version 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".

The cert variable loads the certificate correctly in both environments, so I'm not sure what the problem is.

Any insight would be appreciated.

I think this error occurred because the .xml file was not found.

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.

Solution steps:

1. Check whether the .xml file exists through kudu.

2. If it does not exist, modify the content of the published file by modifying the .csproj file.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM