c# - IIS 服务器上的 Double.ToString() 格式与开发不同

标签 c# asp.net-mvc

我遇到了这个奇怪的问题。
在 Controller 中:

Model ses = new Model();
ses.Latitudine = ses.Sesizare.Locatie.HotSpotLocatie.First().HotSpotLatD;
ses.Longitudine= ses.Sesizare.Locatie.HotSpotLocatie.First().HotSpotLatD;

在模型中:

public class Model
{
    public double Latitudine {get; set;}
    public double Longitudine {get; set;}
}

在 View 中:

<h4><span class="glyphicon glyphicon-globe"></span> <a style="color:white" target='_blank' href='@("http://maps.google.com/maps?q=" + Model.Latitudine + "," + Model.Longitudine)'>Locatia:</a> </h4>

现在在 Visual Studio 中调试 View 呈现如下:

<h4><span class="glyphicon glyphicon-globe"></span> <a style="color:white" target="_blank" href="http://maps.google.com/maps?q=45.65933,25.561595">Locatia:</a> </h4>

http://maps.google.com/maps?q=45.65933,25.561595 (链接可用)

发布后我得到:

<h4><span class="glyphicon glyphicon-globe"></span> <a style="color:white" target="_blank" href="http://maps.google.com/maps?q=45,65933,25,561595">Locatia:</a> </h4>

http://maps.google.com/maps?q=45,65933,25,561595 (链接不可用)

开发和生产在同一台机器上。

在我的另一个 Controller 中:

 Latitude = t.LocatieGPS.Latitude.ToString();

这里的结果在生产和开发中都使用了 DOT。

这是生产 WebConfig:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <!--
    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5.1" />
      </system.Web>
  -->
  <system.web>
    <compilation targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    ....
  </connectionStrings>
  <appSettings>
    <add key="owin:AppStartup" value="GestiuneServiceWeb.Startup,GestiuneServiceWeb" />
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
</configuration>

最佳答案

这是机器文化造成的。您可能不想更改整个应用程序的区域性,因此只需指定您希望如何格式化小数。

InvariantCulture 使用点作为小数点分隔符:

@("http://maps.google.com/maps?q=" + Model.Latitudine.ToString(CultureInfo.InvariantCulture) + "," + Model.Longitudine.ToString(CultureInfo.InvariantCulture))

关于c# - IIS 服务器上的 Double.ToString() 格式与开发不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28087303/

相关文章:

c# - 为什么 Visual Studio 甚至在 Assets 文件夹之外创建 .meta 文件?

c# - ADO 异常操作数类型冲突

asp.net-mvc - MVC Web API Angular App ('http://localhost:4200' 已被 CORS 策略阻止)

c# - Web API 反序列化正在将 int 转换为字符串,我该如何防止呢?

c# - 在类库中包含 View

asp.net-mvc - 将 MVC 网站部署到 Azure

c# - 转换 : Unable to cast object of type 'System.DBNull' to type 'System.String'

c# - Polly 不会抛出一些异常?

c# - 如何在jquery对话框窗口弹出之前将数据绑定(bind)到图表?

asp.net-mvc - 是否保证每个请求只能使用一次 ASP.NET Controller ?