简体   繁体   English

Asp.net-当我在IIS上运行网站时,数据库登录失败

[英]Asp.net - When I run my website on IIS, Database login fails

In my website I am accessing my sqlserver database using "windows authencation mode". 在我的网站中,我正在使用“ Windows身份验证模式”访问我的sqlserver数据库。 Everything works fine when I run my website using visual studio. 当我使用Visual Studio运行网站时,一切正常。 but when I hosted my website on IIS, everytime an error message comes that "database login failed". 但是,当我将网站托管在IIS上时,每次都会出现错误消息“数据库登录失败”。

Login failed for user 'HAL\\IUSR_HAL'.(HAL is the name of my webserver) 用户“ HAL \\ IUSR_HAL”的登录失败。(HAL是我的网络服务器的名称)

Should I do some modifications in database properties so that I can login to database through IIS? 是否应该对数据库属性进行一些修改,以便可以通过IIS登录数据库?

如果您在IIS中使用匿名访问,则需要在连接字符串中为有效的sql用户提供用户ID和密码。

After some research i got the answer of this question. 经过研究,我得到了这个问题的答案。

To access the database through a website running on IIS , IIS's IUSR account and ASPNET account should be authenticated and authorized to sqlserver. 若要通过在IIS上运行的网站访问数据库,应对IIS的IUSR帐户和ASPNET帐户进行身份验证并授权给sqlserver。

(ASPNET account is the account of dotnet framework associated with IIS to process asp.net pages.) (ASPNET帐户是与IIS关联以处理asp.net页的dotnet框架的帐户。)

to do this: 去做这个:

open Sqlserver management studio. 打开Sqlserver管理工作室。 go to SECURITY. 转到安全。 then right click on LOGIN and select "new login". 然后右键单击“登录”并选择“新登录”。 press "search" on login name. 在登录名上按“搜索”。 then click "advanced" button. 然后点击“高级”按钮。 Then press "find now" button. 然后按“立即查找”按钮。 then from list appeared select both of the accounts mentioned above.(one at a time) then press ok. 然后从列表中选择上述两个帐户。(一次选择一个),然后按确定。 after selecting the login name go to it's "user mappings" options. 选择登录名后,转到其“用户映射”选项。 then select the database from there and check the desired permissions. 然后从那里选择数据库并检查所需的权限。

now you are done with everything. 现在您已完成所有工作。 press ok. 按确定。

you can access database from ur website. 您可以从您的网站访问数据库。

In your web.config file look for 在您的web.config文件中查找

<system.web> 

and add: 并添加:

<identity impersonate="true" /> 

Check out the following link: 查看以下链接:

http://msdn.microsoft.com/en-us/library/ms998292.aspx http://msdn.microsoft.com/en-us/library/ms998292.aspx

Hope this helps. 希望这可以帮助。

Thanks, Raja 谢谢,拉贾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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