Asp.net登录控件总是与本地sqlserver一起工作,但只是间歇性地在托管服务器上工作



我有一个asp.net网站。我使用asp.net登录控件生成的模板和向导。我的表,如AspNetUsers和AspNetRoles是在同一个数据库作为我的数据。当我运行我的网站对本地sqlserver数据库,我可以使用我的登录控件登录,一切工作正常。当我把我的网站转移到GoDaddy(我也尝试了同样的问题在smarterAsp.net),我的登录控制有时工作。其他时候,它只是忽略我,把我带回到默认页面,没有错误消息。如果我重置应用程序池或对web进行更改。配置(这似乎重置应用程序池),我可以再次登录几次。在IE中,它比chrome糟糕得多。在IE中我很少能登录。

为了解决我的数据库连接问题,我添加了一个页面,这样我就可以在不登录的情况下访问它。在我进入访问数据库的页面之后,如果我进入登录页面,我就可以登录了。在我看来,我的登录控件不被允许访问数据库,但是我的页面上的listview控件是,然后一旦连接由sqlDataSource打开,那么登录控件可以进行身份验证。我在这上面浪费了一个星期!!的帮助!对于sqldatasource和aspNet身份验证,我使用了相同的连接字符串。这是我的web.config。可能会有点乱,因为我尝试了各种方法。我只使用"LocalSqlServer"连接字符串。

  <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer" connectionString="Data Source=ServerIP;Initial Catalog=Aveida;Integrated Security=False;User Id=XXXXX; Password=XXXXXX" providerName="System.Data.SqlClient" />
    <remove name = "DefaultConnection"/>
    <add name="DefaultConnection" connectionString="Data Source=ServerIP;Initial Catalog=Aveida;Integrated Security=False;User Id=XXXXX; Password=XXXXXX" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <globalization uiCulture="en-US" culture="he-IL" />
    <customErrors mode="Off" />
    <trust level="Full" />
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Optimization" />
        <add namespace="Microsoft.AspNet.Identity" />
      </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
        <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
      </controls>
    </pages>
    <membership>
      <providers>
        <!--
          ASP.NET Membership is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
        -->
        <clear />
      </providers>
    </membership>
    <profile>
      <providers>
        <!--
          ASP.NET Membership Profile is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
        -->
        <clear />
      </providers>
    </profile>
    <roleManager>
      <!--
            ASP.NET Membership Role is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
        -->
      <providers>
        <clear />
      </providers>
    </roleManager>
    <!--
            If you are deploying to a cloud environment that has multiple web server instances,
            you should change session state mode from "InProc" to "Custom". In addition,
            change the connection string named "DefaultConnection" to connect to an instance
            of SQL Server (including SQL Azure and SQL  Compact) instead of to SQL Server Express.
      -->
    <sessionState mode="Custom" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="LocalSqlServer" />
      </providers>
    </sessionState>
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <location path="SearchLost.aspx">
    <system.web>
      <authorization>
        <allow roles="member,manager" />
        <deny users="*" />
      </authorization>
    </system.web>
  </location>
  <location path="Account/Register.aspx">
    <system.web>
      <authorization>
        <allow roles="manager" />
        <deny users="*" />
      </authorization>
    </system.web>
  </location>
</configuration>

我解决了这个问题。(几个小时后才能给出答案)我改变了

<sessionState mode="Custom" customProvider="DefaultSessionProvider">
 <providers> 
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="LocalSqlServer" /> 
</providers>

变为

<sessionState mode="InProc" > 

我摆脱了customProvider(不知道从哪里开始),它似乎起作用了。

最新更新