简体   繁体   中英

ASP.NET Core 3.1 - Code behind string with accent character issue on IIS server

I have a strange issue with a string that contains accented characters in the code behind of a razor page in .NET Core 3.1.

When I run the code in VS2019 or my local IIS, everything works fine, the string is displayed and injected in SQL using the characters like "é" and "ô" fine. But once we migrate the code on the development IIS, the accent characters are changed to unrecognized characters " " where accented character should be. I use the same database for the 3 situations.

The cshtml page are using UTF-8 encoding, but I doubt it matters since the issue is in the code behind as I understand...

Let's say I have some function OnPost:

public IActionResult OnPostChangeValue(int objectKey, string newvalue)
{
     someInterface.someFunction($"Rôle de déploiement: {newvalue}");

     return Page();
}

The newvalue is coming from the razor page when a button is clicked, a string with some value is posted. The button is part of a table inside a form, built using ajax for datatables.

<button type="submit" class="btn btn-danger" formaction="./Page?objectKey=' + row.objectKey + '&newvalue=SomeText&handler=ChangeValue">SomeText</button>

Then in the interface implementation code I have added a logger to get the value before the SQL injection to validate if the issue was with SQL or the code itself. NOTE: This class reside in another project/dll that is referenced by the default project.

public someFunction(string message)
{
    ILogger.logWarning(message);

    using (IDbConnection connection = new SqlConnection(config.GetConnectionString("someDbString")))
            {
                connection.Execute("dbo.someStoredProcedure @Message", new {Message = message});
            }
}

When the code is run on the development server/IIS, the entry are "R le de d ploiement: ...". But if the same code/build is run from Visual Studio or my local IIS (release publish), the entry are "Rôle de déploiement: ..." as expected.

My question is: how can I fix that and/or is there a setting on IIS/Windows server that could prevent from using accents characters in the code behind?

Thanks!

EDIT: Added more information

EDIT2: I have been able to reproduce the issue on my local IIS. We are using Azure DevOps to build and release the webapps on our IIS servers. I have downloaded the Azure Build (which I assumed was the same as I've obtained locally with VS2019) and now I have the issue. So it seems it is caused by something to be found when using the Azure DevOps build...

The issue was in Azure DevOps with the agent used by the pipeline to build the release.

I changed:

vmImage: 'ubuntu-latest'

To:

vmImage: 'windows-2019'

In the pipeline confiuration and now the code compile as expected with the accent in the string. I could probably use 'windows-latest' instead but it is now resolved.

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