从localhost运行应用程序时,数据库连接正常工作。从dev服务器登录失败

时间:2023-01-19 23:44:30

I have an application which connects to a database, retrieves a username from a user's table and matches it against the username retrieved with System.Security.Principal.WindowsIdentity.GetCurrent.Name

我有一个连接到数据库的应用程序,从用户的表中检索用户名并将其与使用System.Security.Principal.WindowsIdentity.GetCurrent.Name检索的用户名进行匹配。

On my localhost, everything works fine. The database exists on the development server but the application lies on my localhost. All of my authorization and authentication techniques are running smoothly.

在我的本地主机上,一切正常。数据库存在于开发服务器上,但应用程序位于我的localhost上。我的所有授权和身份验证技术都运行顺畅。

However, when I publish my application to the development server, I'm faced with the following error.

但是,当我将我的应用程序发布到开发服务器时,我遇到了以下错误。

Cannot open database requested in login 'databaseName'. Login fails.
Login failed for user 'DevelopmentServerName\ASPNET'. 

I can't put my finger onto what would cause this. Any help would be greatly appreciated.

我不能把手指放在导致这种情况的原因上。任何帮助将不胜感激。

Thanks!

Edit: Here is the connection string!

编辑:这是连接字符串!

  <add name="connectionStringName" connectionString="Initial Catalog=myDatabase;Data Source=DevelopmentServerName;Integrated Security=True"
     providerName="System.Data.SqlClient" />

Also, for context. This authentication needs to grab the user's Windows username and match it against the username in the database. Users will have the Computername\Myname username built into the database (if they are authorized to use the required section of the program, that is).

另外,对于上下文。此身份验证需要获取用户的Windows用户名,并将其与数据库中的用户名进行匹配。用户将在数据库中内置Computername \ Myname用户名(如果他们被授权使用程序的必需部分,即)。

Thanks again :)

再次感谢 :)

4 个解决方案

#1


It appears that your application is attempting to connect to the database under the ASPNET account, which may have limited permissions on the development server, as opposed to logging in on your own (you local machine may actually be using your windows identity). I can see two potential solutions.

您的应用程序似乎正在尝试连接到ASPNET帐户下的数据库,该帐户可能在开发服务器上具有有限的权限,而不是您自己登录(您本地计算机实际上可能正在使用您的Windows身份)。我可以看到两种可能的解决方案

  1. Make sure to add into the system.web section of your web.config file.

    确保添加到web.config文件的system.web部分。

  2. Check with the system administrator and the SQL administrator to make sure the ASPNET account has proper authorization to connect to the database, if indeed your environment allows this account to connect.

    如果您的环境允许此帐户连接,请与系统管理员和SQL管理员联系,以确保ASPNET帐户具有连接到数据库的正确权限。

Adding some additional code to your question, such as your connection string may help things out as well.

在您的问题中添加一些额外的代码,例如您的连接字符串也可以帮助解决问题。

EDIT: Okay, you are indeed using IntegratedSecurity, so typically with this kind of setup (using impersonation), you need to make sure you are getting prompted to add your Username and Password to authenticate against.

编辑:好的,你确实在使用IntegratedSecurity,所以通常使用这种设置(使用模拟),你需要确保提示你添加你的用户名和密码进行身份验证。

We have a similar setup, and to do this, we have to go to the IIS settings for the virtual directory, select the Directory Security tab, and click the Edit button under Anonymous access and authentication control.

我们有类似的设置,为此,我们必须转到虚拟目录的IIS设置,选择目录安全性选项卡,然后单击匿名访问和身份验证控制下的编辑按钮。

Make sure Anonymous access is unchecked, and you may will most likely need to enable the proper authentication for your environment. Unfortunately we're still using Basic authentication (clear text) here, but Integrated Windows authentication may will work for you too. It depends on your environment.

确保未选中“匿名访问”,您可能很可能需要为您的环境启用正确的身份验证。不幸的是,我们仍在使用基本身份验证(明文),但集成Windows身份验证可能也适用于您。这取决于您的环境。

I'm adding this comment to the main post since this seemed to have done the trick...

我正在将这个评论添加到主帖中,因为这似乎已经成功了...

I just found this post which may help you get the proper configuration setup to handle what you need based on your IIS environment.

我刚刚发现这篇文章可能会帮助您获得正确的配置设置,以根据您的IIS环境处理您需要的内容。

#2


The answer may lay with your connection string. My guess would be that you are using integrated authentication to log into the database. This works fine when it's your machine because the application is using your credentials. When you publish to the development server you would be using the aspNet user and wouldn't have the right credentials to login. I would either add this user to your database server or change your connection string to use SQL authentication.

答案可能在于您的连接字符串。我的猜测是你使用集成身份验证登录数据库。这是因为应用程序正在使用您的凭据,因此它适用于您的计算机。当您发布到开发服务器时,您将使用aspNet用户,并且没有正确的凭据登录。我要么将此用户添加到您的数据库服务器,要么更改您的连接字符串以使用SQL身份验证。

#3


It could be a firewall setting that's preventing your server from seeing your database.

它可能是防火墙设置阻止您的服务器看到您的数据库。

It might also have something to do with your connection string. If you're using anything besides a username/password combo in your web.config file, you will probably require additional configuration to convince the database server to let you connect.

它也可能与您的连接字符串有关。如果您在web.config文件中使用除用户名/密码组合之外的任何内容,则可能需要其他配置来说服数据库服务器让您连接。

#4


It seems that what you want to do is impersonate the caller of the web page. You need to add a line to your web.config to do this:

看来你想要做的就是冒充网页的来电者。您需要在web.config中添加一行来执行此操作:

<identity impersonate="true" />

See this article for an explanation.

请参阅此文章以获得解释。

#1


It appears that your application is attempting to connect to the database under the ASPNET account, which may have limited permissions on the development server, as opposed to logging in on your own (you local machine may actually be using your windows identity). I can see two potential solutions.

您的应用程序似乎正在尝试连接到ASPNET帐户下的数据库,该帐户可能在开发服务器上具有有限的权限,而不是您自己登录(您本地计算机实际上可能正在使用您的Windows身份)。我可以看到两种可能的解决方案

  1. Make sure to add into the system.web section of your web.config file.

    确保添加到web.config文件的system.web部分。

  2. Check with the system administrator and the SQL administrator to make sure the ASPNET account has proper authorization to connect to the database, if indeed your environment allows this account to connect.

    如果您的环境允许此帐户连接,请与系统管理员和SQL管理员联系,以确保ASPNET帐户具有连接到数据库的正确权限。

Adding some additional code to your question, such as your connection string may help things out as well.

在您的问题中添加一些额外的代码,例如您的连接字符串也可以帮助解决问题。

EDIT: Okay, you are indeed using IntegratedSecurity, so typically with this kind of setup (using impersonation), you need to make sure you are getting prompted to add your Username and Password to authenticate against.

编辑:好的,你确实在使用IntegratedSecurity,所以通常使用这种设置(使用模拟),你需要确保提示你添加你的用户名和密码进行身份验证。

We have a similar setup, and to do this, we have to go to the IIS settings for the virtual directory, select the Directory Security tab, and click the Edit button under Anonymous access and authentication control.

我们有类似的设置,为此,我们必须转到虚拟目录的IIS设置,选择目录安全性选项卡,然后单击匿名访问和身份验证控制下的编辑按钮。

Make sure Anonymous access is unchecked, and you may will most likely need to enable the proper authentication for your environment. Unfortunately we're still using Basic authentication (clear text) here, but Integrated Windows authentication may will work for you too. It depends on your environment.

确保未选中“匿名访问”,您可能很可能需要为您的环境启用正确的身份验证。不幸的是,我们仍在使用基本身份验证(明文),但集成Windows身份验证可能也适用于您。这取决于您的环境。

I'm adding this comment to the main post since this seemed to have done the trick...

我正在将这个评论添加到主帖中,因为这似乎已经成功了...

I just found this post which may help you get the proper configuration setup to handle what you need based on your IIS environment.

我刚刚发现这篇文章可能会帮助您获得正确的配置设置,以根据您的IIS环境处理您需要的内容。

#2


The answer may lay with your connection string. My guess would be that you are using integrated authentication to log into the database. This works fine when it's your machine because the application is using your credentials. When you publish to the development server you would be using the aspNet user and wouldn't have the right credentials to login. I would either add this user to your database server or change your connection string to use SQL authentication.

答案可能在于您的连接字符串。我的猜测是你使用集成身份验证登录数据库。这是因为应用程序正在使用您的凭据,因此它适用于您的计算机。当您发布到开发服务器时,您将使用aspNet用户,并且没有正确的凭据登录。我要么将此用户添加到您的数据库服务器,要么更改您的连接字符串以使用SQL身份验证。

#3


It could be a firewall setting that's preventing your server from seeing your database.

它可能是防火墙设置阻止您的服务器看到您的数据库。

It might also have something to do with your connection string. If you're using anything besides a username/password combo in your web.config file, you will probably require additional configuration to convince the database server to let you connect.

它也可能与您的连接字符串有关。如果您在web.config文件中使用除用户名/密码组合之外的任何内容,则可能需要其他配置来说服数据库服务器让您连接。

#4


It seems that what you want to do is impersonate the caller of the web page. You need to add a line to your web.config to do this:

看来你想要做的就是冒充网页的来电者。您需要在web.config中添加一行来执行此操作:

<identity impersonate="true" />

See this article for an explanation.

请参阅此文章以获得解释。