简体   繁体   中英

Login fails after changing Web.Config

After I changed my web.config , I get the error shown below.

Before change:

<connectionStrings>
    <add name="CS1"
         connectionString="Server=S1; Database=DB1; User ID=Admin; Password=AdminPW; Persist Security Info=True; Max Pool Size=200; Connection Timeout=60" />
</connectionStrings>

After change:

<connectionStrings>
    <add name="CS1" 
         connectionString="Data Source=S1; Initial Catalog=DB1; Integrated Security=True;" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

Error:

Login failed for user 'NT AUTHORITY\\ANONYMOUS LOGON'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\\ANONYMOUS LOGON'.

Stack Trace:

[SqlException (0x80131904): Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.]
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager) +1431
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +1085
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +70
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +964
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +109
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1529
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +156
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +258
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +312
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +202
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +413
   System.Data.SqlClient.SqlConnection.Open() +128
   MROWebPartCollection.BLL.Common.DataProvider.ConnectionDB() +263
   MROWebPartCollection.BLL.Provider.MROQ_TBL_USER_PROFILEProvider..ctor() +245
   MROWebPartCollection.ProductWP.CoaCoc.CoaCocUserControl..ctor() +125
   ASP._controltemplates_mrowebpartcollection_productwp_coacoc_coacocusercontrol_ascx..ctor() +16
   __ASP.FastObjectFactory_app_web_coacocusercontrol_ascx_16352c62_o2rjt3li.Create_ASP__controltemplates_mrowebpartcollection_productwp_coacoc_coacocusercontrol_ascx() +31
   System.Web.UI.TemplateControl.LoadControl(IWebObjectFactory objectFactory, VirtualPath virtualPath, Type t, Object[] parameters) +282
   System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath) +120
   MROWebPartCollection.ProductWP.CoaCoc.CoaCoc.CreateChildControls() +96
   System.Web.UI.Control.EnsureChildControls() +130
   System.Web.UI.Control.PreRenderRecursiveInternal() +66
   System.Web.UI.Control.PreRenderRecursiveInternal() +276
   System.Web.UI.Control.PreRenderRecursiveInternal() +276
   System.Web.UI.Control.PreRenderRecursiveInternal() +276
   System.Web.UI.Control.PreRenderRecursiveInternal() +276
   System.Web.UI.Control.PreRenderRecursiveInternal() +276
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6881

If you're using integrated security then the app pool active directory account must be granted access to your SQL Server database. Here are some tips:

  1. The account you use must be an active directory account that is valid on both the web server and the database server. A local account will work if you are on the same machine.
  2. In order to assign an identity to your web site, find the app pool in IIS (site settings under App Pool), then find the Application Pool identity property in the app pool settings. Set the Application Pool identity to your selected active directory account.
  3. In SQL Server, create a SQL user that maps to your active directory account
  4. Once you've created the user, you can grant that user access to your database

Of course each one of these steps has a number of details to pay attention to.

I should also note that all of the instructions above assume that you want to set up the database using a standard login. If, on the other hand, you want to authenticate with SQL Server using the Active Directory credentials of the user who is browsing your site, you'll want to use IIS impersonation instead of the steps outlined above. This article explains the basics of impersonation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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