如何在 IIS 7 下为 ASP.Net MVC 应用程序的匿名用户创建本地用户配置文件?
我一直在尝试 ASP.Net MVC,并且遇到了一个可能与 MVC 无关的问题。 但我无法在默认的 MVC 应用程序(创建新的 MVC 项目时由向导创建的应用程序)中进行身份验证,以便在 Windows 7 上的 IIS 7 下正常工作。
如果我在 Visual Studio 环境下运行,它可以工作,但如果我将设置切换为在 IIS 下运行,尝试提交登录或注册时出现以下异常:
生成用户实例失败 SQL Server 由于失败 检索用户的本地 应用程序数据路径。 请做出来 确保用户有本地用户配置文件 在电脑上面。 连接将 关闭。
我相信这是因为该网站在 Visual Studio 中以我自己的帐户运行,但在 IIS 中以 IUSR 帐户运行。 到目前为止,谷歌对异常消息的搜索没有任何帮助。
那么,可以为 IUSR 帐户创建本地用户配置文件吗? 如果是这样,怎么办? 我还应该做些什么才能让 SQLExpress 引擎在 IIS 7 中的匿名帐户下工作吗?
我还尝试将 IIS 网站配置为使用我的帐户,但由于这是我的家用计算机,因此我的帐户没有密码,而且 IIS 似乎不允许将网站配置为使用没有密码的帐户。 或者,由于这是我第一次使用 IIS 7,而且配置感觉与 IIS 5/6 非常不同,所以我只是缺少正确的设置,无法让我配置用于匿名访问的帐户。
编辑:一些附加信息。 如果我清空 App_Data 文件夹并从 IIS 重试,SQLExpress 会尝试创建数据库并失败,但异常消息包含更多信息和以下建议。
SQLExpress数据库文件自动创建 错误:
连接字符串指定一个 本地 Sql Server Express 实例 使用内的数据库位置 应用程序App_Data目录。 这 提供商尝试自动 创建应用程序服务 数据库因为提供者 确定数据库没有 存在。 以下配置 要求是必要的 成功检查是否存在 应用程序服务数据库和 自动创建应用程序 服务数据库:
- 如果应用程序 App_Data 目录尚不存在,则 Web 服务器帐户必须已阅读并 对应用程序的写访问权限 目录。 这是必要的,因为 网络服务器帐户将 自动创建App_Data 目录(如果还没有) 存在。
- 如果应用程序 App_Data 目录已存在,则 Web 服务器帐户只需要读取和 对应用程序的写访问权限 App_Data 目录。 这是必要的 因为网络服务器帐户将 尝试验证 Sql Server Express 数据库已存在于 应用程序App_Data目录。 撤销对 App_Data 的读取访问权限 来自 Web 服务器帐户的目录 将阻止提供者 正确判断Sql是否 Server Express 数据库已经 存在。 这会导致错误 提供者尝试创建一个 已存在的重复 数据库。 需要写访问权限 因为网络服务器帐户 创建时使用凭据 新数据库。
- 计算机上必须安装 Sql Server Express。
- Web 服务器帐户的进程标识必须具有本地用户 轮廓。 请参阅自述文件 有关如何创建本地用户的详细信息 机器和域的配置文件 帐户。
我已经非常广泛地确认前三个建议已经得到满足。 第四个似乎是我的问题的原因,但我不知道该怎么做。 尽管该建议声称有一个自述文件描述了它,但我一直无法找到该文件。
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.
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:
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.
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.
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?
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.
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.
SQLExpress database file auto-creation
error: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:
- 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.- 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.- Sql Server Express must be installed on the machine.
- 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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在中等信任度下运行时也遇到了这个问题。 创建数据库的过程至少需要高信任度。 您可以通过查看 Web.Config 来检查这一点。
如果您的 Web.Config 中没有指定信任,请尝试添加它并将其设置为“完全”或“高”。 如果这不起作用,您的 IIS 中有一个 machine.config 需要修改。
话虽这么说,我发现解决此问题的最佳途径是仅使用 aspnet_regsql.exe 创建必要的表,然后更改 Web.Config 中的连接字符串以直接查看它。
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
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.
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.
我解决了“目录‘LocalApplicationData’不存在。” 通过确保 SQL SSIS 服务和 SQL Server 代理服务在与 swql 作业设置使用的帐户相同的帐户下运行,通过 SQL 作业运行 SSIS 包时会出现错误!
就我而言,这是一个域帐户。
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!
This in my case was a domain account.
解决方案:在开始遇到问题之前尝试卸载所有更新。 我花了无数的时间——浪费了我一生中永远无法恢复的时间——阅读并遵循每一个可能的解决方案,但没有成功。 我卸载了所有 SQL Server 更新,现在一切正常。
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.