asp.net登录控件始终使用本地sqlserver,但只能在托管服务器上间歇使用

时间:2014-07-08 08:15:42

标签: asp.net

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

为了解决我的数据库连接问题,我添加到了我的一个页面,以便我可以在不登录的情况下访问它。在我访问访问数据库的页面之后,如果我进入登录页面,那么我可以登录。在我看来,我的登录控件不允许访问数据库,但我的页面上的listview控件是,然后一旦sqlDataSource打开连接,登录控件就可以进行身份​​验证。我浪费了一个星期!!!救命! 我对SQLDataSources以及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>

1 个答案:

答案 0 :(得分:0)

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

<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(不知道我从哪里开始)它似乎工作。