简体   繁体   English

ASP.NET Core 3.1 - IIS 服务器上带有重音字符问题的字符串背后的代码

[英]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.我在 .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.当我在 VS2019 或我的本地 IIS 中运行代码时,一切正常,使用“é”和“ô”等字符在 SQL 中显示和注入字符串。 But once we migrate the code on the development IIS, the accent characters are changed to unrecognized characters " " where accented character should be.但是,一旦我们在开发 IIS 上迁移代码,重音字符将更改为无法识别的字符“ ”,该字符应该是重音字符。 I use the same database for the 3 situations.我在 3 种情况下使用相同的数据库。

The cshtml page are using UTF-8 encoding, but I doubt it matters since the issue is in the code behind as I understand... cshtml 页面使用的是 UTF-8 编码,但我怀疑这是否重要,因为据我了解,问题出在后面的代码中......

Let's say I have some function OnPost:假设我有一些 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.单击按钮时,新值来自 razor 页面,带有某个值的字符串被发布。 The button is part of a table inside a form, built using ajax for datatables.该按钮是表单内表格的一部分,使用 ajax 为数据表构建。

<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.然后在接口实现代码中,我添加了一个记录器来获取 SQL 注入之前的值,以验证问题是出在 SQL 还是代码本身。 NOTE: This class reside in another project/dll that is referenced by the default project.注意:此类驻留在默认项目引用的另一个项目/dll 中。

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: ...".当代码在开发服务器/IIS 上运行时,条目为“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.但是,如果从 Visual Studio 或我的本地 IIS(发布发布)运行相同的代码/构建,则条目为“Rôle de déploiement: ...”,正如预期的那样。

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?我的问题是:我该如何解决这个问题和/或 IIS/Windows 服务器上是否有一个设置可以防止在后面的代码中使用重音字符?

Thanks!谢谢!

EDIT: Added more information编辑:添加了更多信息

EDIT2: I have been able to reproduce the issue on my local IIS. EDIT2:我已经能够在我的本地 IIS 上重现该问题。 We are using Azure DevOps to build and release the webapps on our IIS servers.我们正在使用 Azure DevOps 在我们的 IIS 服务器上构建和发布 web 应用程序。 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.我已经下载了 Azure Build(我认为它与我使用 VS2019 在本地获得的相同),现在我遇到了问题。 So it seems it is caused by something to be found when using the Azure DevOps build...所以它似乎是由使用 Azure DevOps 构建时发现的东西引起的......

The issue was in Azure DevOps with the agent used by the pipeline to build the release.问题出在 Azure DevOps 中,管道使用代理来构建发布。

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.我可能可以改用“windows-latest”,但现在已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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