Double.ToString()格式在IIS服务器上不同于开发

时间:2015-01-22 11:10:35

标签: c# asp.net-mvc

我有这个奇怪的问题。
在控制器中:

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;}
}

在视图中:

<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调试中,视图呈现为:

<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 (链接无法使用)

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

在另一个控制器中我有:

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

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

这是Production 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>

2 个答案:

答案 0 :(得分:5)

这是由机器的文化引起的。您可能不希望更改整个应用程序的文化,因此只需指定格式化小数的方式。

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

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

答案 1 :(得分:2)

这可能与您在IIS中使用的文化有关。要在您的情况下重写此项,而不在其他任何地方更改文化,您可以按如下方式格式化链接:

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

这会将数字转换为字符串,并使用“InvariantCulture”的设置输出,该设置将使用点而不是逗号。