0
votes

We have an ASP.NET MVC application on our company network. It runs on two machines (one for IIS and one for SQL Server) - everything worked fine with Windows authentication and double hopping.

Now I implemented session variables and every time I want to open our application, there is a login error:

Login failed for user 'DOMAIN\MACHINENAME$'

On my test machine (Visual Studio and SQL Server on the same machine) everything worked fine with session variables.

How is it going again that the IIS will take the user credentials instead of itself.

1
1) Use a domain service account as application pool identity. 2) Grant that account access to the database.Lex Li

1 Answers

0
votes

When we use the integrated security in the database connection string, the application hosted in the IIS/IIS Express will try to connect the database with the current login Windows account. If the Visual Studio and SQL Server are on the same machine, the database connection string with integrated security will work fine Cause that both these two applications (Web application and the SQL server) are running under the same windows account. When the web application is hosted in IIS/IIS Express and the database connection way is integrated security, the default credential is used to connect the database is the windows account which is running the IIS/IIS Express.
I recommend that we could change the way to connect the SQL server in the database connection string, such as the SQL Authentication.

Data Source=mysqlserver;User ID=sa;Password=123456;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False

Alternatively, to avoid using the current windows account of the webserver to connect the database, it is available to change the application pool identity to another domain account, the premise is that the Windows account should be able to log in to the SQL server.
For more details about the Application pool identity.
https://docs.microsoft.com/en-us/iis/manage/configuring-security/application-pool-identities
Feel free to let me know if the problem persists.