Web.config Authentication Error

£可爱£侵袭症+ 提交于 2019-12-13 13:25:45

问题


I am using SQLServer2005 and VS2008. My connection string in web.config is:

add name="library" connectionString="Data source=KMT; Initial Catalog=Library;Integrated Security=SSPI"

Here, KMT is my server name, Library is my database.

When I run my page through VS2008 localhost, it's fine. However, when viewing through IIS it shows an error message like "login failed for user, 'KMT/ASP.NET'". My sqlserver authentication mode is windows and it's ok in web.config. What will be the solution?


回答1:


Using "Integrated Security" means logging in to the database with the identity of the user running the process. When you run the local VS web server, it runs as your login. But in IIS, the web server worker process runs as a predefined user account. Your worker process identity must have rights to your SQL Server and database.

Check the properties of your App Pool in IIS. If you are running as Network Service for example, go into SQL and create a new user, enter Network Service as the Windows user name, and grant that user rights to your database.




回答2:


one of my friends helped me to solve this problem as i executed the SQL to add ASPNET as a login to my DB and setup DA permissions

exec sp_grantlogin N'MACHINE\ASPNET' exec sp_defaultdb N'MACHINE\ASPNET', N'Database' use Database exec sp_grantdbaccess N'MACHINE\ASPNET', N'ASPNET' exec sp_addrolemember N'db_owner', N'ASPNET'

here MACHINE is machine name and database is my database name. but through this the ASPNET user has total control over that DB.




回答3:


VS2008 uses your credentials to authorize to the db, IIS is using different account. Make sure the IIS account has enough permissions.




回答4:


If you use Integrated Security=SSPI, the credentials of the current user (in VS that would be YOU) are used to connect to SQL Server.

From an IIS app, the user associated with the IIS service is used for log in.

Solutions:

  • Assign the IIS service a special user that's allowed to connect to SQL

  • Use SQL Server authentification to access the database, and stored username/password in the connection string




回答5:


Were you planning to use the ASP.NET system account or the users windows account?

If the latter you need impersonation. That works if SQL and IIS are on the same machine, otherwise it is a double hop and requires a non trivial amount of work to set up delegation.




回答6:


If the server is windows 2003 you can give the Network Service the permissions to access to SQL Server



来源:https://stackoverflow.com/questions/1349218/web-config-authentication-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!