如何在IIS 7下为ASP.Net MVC应用程序的匿名用户创建本地用户配置文件?

时间:2022-06-04 05:30:19

I've been experimenting with ASP.Net MVC, and have come across a problem that is probably not specifically MVC related. But I cannot get the authentication in the default MVC application (the one created by the wizard when you create a new MVC project) to work properly under IIS 7 on Windows 7.

我一直在尝试ASP.Net MVC,并遇到了一个可能与MVC无关的问题。但是我无法在默认的MVC应用程序(在创建新的MVC项目时由向导创建的应用程序)中获得身份验证,以便在Windows 7上的IIS 7下正常工作。

If I run under the Visual Studio environment, it works, but if I switch the settings to run under IIS instead, I get the following exception trying to submit the login or registration:

如果我在Visual Studio环境下运行,它可以工作,但如果我将设置切换为在IIS下运行,我会尝试提交登录或注册时遇到以下异常:

Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.

由于无法检索用户的本地应用程序数据路径,无法生成SQL Server的用户实例。请确保用户在计算机上具有本地用户配置文件。连接将被关闭。

I believe that this is because the website runs under my own account in Visual Studio, but under the IUSR account in IIS. Google searches on the exception message have been unhelpful so far.

我相信这是因为该网站在我自己的Visual Studio帐户下运行,但在IIS中的IUSR帐户下运行。到目前为止,谷歌对异常消息的搜索一直没有帮助。

So, can one create a local user profile for the IUSR account? If so, how? Is there something else I should be doing to get the SQLExpress engine to work under the anonymous account in IIS 7?

那么,可以为IUSR帐户创建本地用户配置文件吗?如果是这样,怎么样?我还应该做些什么来让SQLExpress引擎在IIS 7中的匿名帐户下工作吗?

I also tried configuring the IIS website to use my account, but since this is my home machine, my account doesn't have a password, and it appears that IIS won't let a website be configured to use an account without a password. Or, since this is my first experience with IIS 7, and configuration feels very different than IIS 5/6, I am just missing the right setting that will let me configure the account to use for anonymous access.

我也尝试配置IIS网站以使用我的帐户,但由于这是我的家庭计算机,我的帐户没有密码,并且似乎IIS不会让网站配置为使用没有密码的帐户。或者,由于这是我第一次使用IIS 7,并且配置与IIS 5/6非常不同,我只是错过了正确的设置,可以让我配置用于匿名访问的帐户。

EDIT: Some additional information. If I empty the App_Data folder and try again from IIS, SQLExpress attempts to create my database and fails, but the exception message has further information with the following suggestions.

编辑:一些额外的信息。如果我清空App_Data文件夹并从IIS再次尝试,SQLExpress会尝试创建我的数据库并失败,但是异常消息包含有以下建议的更多信息。

SQLExpress database file auto-creation error:

SQLExpress数据库文件自动创建错误:

The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:

连接字符串使用应用程序App_Data目录中的数据库位置指定本地Sql Server Express实例。提供程序尝试自动创建应用程序服务数据库,因为提供程序确定数据库不存在。要成功检查应用程序服务数据库是否存在并自动创建应用程序服务数据库,必须满足以下配置要求:

  1. If the applications App_Data directory does not already exist, the web server account must have read and write access to the applications directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
  2. 如果应用程序App_Data目录尚不存在,则Web服务器帐户必须具有对应用程序目录的读写权限。这是必要的,因为如果Web服务器帐户尚不存在,它将自动创建App_Data目录。

  3. If the applications App_Data directory already exists, the web server account only requires read and write access to the applications App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the applications App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server accounts credentials are used when creating the new database.
  4. 如果应用程序App_Data目录已存在,则Web服务器帐户仅需要对应用程序App_Data目录的读写访问权限。这是必要的,因为Web服务器帐户将尝试验证应用程序App_Data目录中是否已存在Sql Server Express数据库。从Web服务器帐户撤消对App_Data目录的读取访问将阻止提供程序正确确定Sql Server Express数据库是否已存在。当提供程序尝试创建现有数据库的副本时,这将导致错误。需要写访问权限,因为在创建新数据库时会使用Web服务器帐户凭据。

  5. Sql Server Express must be installed on the machine.
  6. 必须在计算机上安装Sql Server Express。

  7. The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.
  8. Web服务器帐户的进程标识必须具有本地用户配置文件。有关如何为计算机和域帐户创建本地用户配置文件的详细信息,请参阅自述文档。

I've pretty extensively confirmed that the first three suggestions have been satisfied. The fourth seems to be the cause of my problems, but I can't figure out how to do that. And although the suggestion claims there is a readme document that describes it, I have not been able to find that document.

我已经非常广泛地确认前三个建议已经得到满足。第四个似乎是我的问题的原因,但我无法弄清楚如何做到这一点。虽然该建议声称有一个描述它的自述文件,但我无法找到该文件。

3 个解决方案

#1


I got this problem as well running under medium trust. The process that creates the database requires at least High trust. You can check this by looking in your Web.Config for

我遇到了这个问题以及在中等信任下运行。创建数据库的过程至少需要高信任度。您可以通过查看Web.Config来查看

<trust level="TrustLevel" />

If there is no trust specified in your Web.Config, try adding it and set it to either Full or High. If this doesn't work, there is a machine.config in your IIS which you would need to modify.

如果Web.Config中未指定信任,请尝试添加它并将其设置为“完全”或“高”。如果这不起作用,则IIS中有一个machine.config,您需要修改它。

That being said, the best route I have found to solve this is to just use aspnet_regsql.exe to create the necessary tables and then change the connection string in your Web.Config to look at it directly.

话虽这么说,我发现解决这个问题的最佳途径是使用aspnet_regsql.exe来创建必要的表,然后更改Web.Config中的连接字符串以直接查看它。

#2


I solved "The directory 'LocalApplicationData' does not exist." error when running an SSIS package through an SQL Job by ensuring the SQL SSIS service and SQL Server Agent service were running under the same account as the swql job was set to use!

我解决了“目录'LocalApplicationData'不存在。”通过确保SQL SSIS服务和SQL Server代理服务在swql作业设置为使用的同一帐户下运行时,通过SQL作业运行SSIS包时出错!

This in my case was a domain account.

在我的情况下,这是一个域帐户。

#3


Solution: Try UNINSTALLING any updates before you started experiencing the issue. I spent countless hours - wasted hours that I will never get back in my life - reading and following every solution possible without success. I uninstalled all SQL Server updates and now everything works fine.

解决方案:在开始遇到问题之前,请尝试卸载所有更新。我花了无数个小时 - 浪费了几个小时,我将永远无法回到我的生活中 - 阅读并遵循每一个解决方案都可能没有成功。我卸载了所有SQL Server更新,现在一切正常。

#1


I got this problem as well running under medium trust. The process that creates the database requires at least High trust. You can check this by looking in your Web.Config for

我遇到了这个问题以及在中等信任下运行。创建数据库的过程至少需要高信任度。您可以通过查看Web.Config来查看

<trust level="TrustLevel" />

If there is no trust specified in your Web.Config, try adding it and set it to either Full or High. If this doesn't work, there is a machine.config in your IIS which you would need to modify.

如果Web.Config中未指定信任,请尝试添加它并将其设置为“完全”或“高”。如果这不起作用,则IIS中有一个machine.config,您需要修改它。

That being said, the best route I have found to solve this is to just use aspnet_regsql.exe to create the necessary tables and then change the connection string in your Web.Config to look at it directly.

话虽这么说,我发现解决这个问题的最佳途径是使用aspnet_regsql.exe来创建必要的表,然后更改Web.Config中的连接字符串以直接查看它。

#2


I solved "The directory 'LocalApplicationData' does not exist." error when running an SSIS package through an SQL Job by ensuring the SQL SSIS service and SQL Server Agent service were running under the same account as the swql job was set to use!

我解决了“目录'LocalApplicationData'不存在。”通过确保SQL SSIS服务和SQL Server代理服务在swql作业设置为使用的同一帐户下运行时,通过SQL作业运行SSIS包时出错!

This in my case was a domain account.

在我的情况下,这是一个域帐户。

#3


Solution: Try UNINSTALLING any updates before you started experiencing the issue. I spent countless hours - wasted hours that I will never get back in my life - reading and following every solution possible without success. I uninstalled all SQL Server updates and now everything works fine.

解决方案:在开始遇到问题之前,请尝试卸载所有更新。我花了无数个小时 - 浪费了几个小时,我将永远无法回到我的生活中 - 阅读并遵循每一个解决方案都可能没有成功。我卸载了所有SQL Server更新,现在一切正常。