问题描述
我最近在尝试使用 IIS 托管我的 asp.net 站点时遇到了错误.我找到了一个很多人都信誓旦旦的解决方案.
I've recently encountered an error trying to host my asp.net site with IIS. I have found a solution that many swear by.
解决方案:
- 添加对文件夹中的文件具有读取权限的 IIS_IUSRS
- 将 IIS 身份验证方法更改为 BasicAuthentication
- 刷新网站.它会起作用的
(http://vivekthangaswamy.blogspot.com/2009/07/aspnet-website-cannot-read.html)
但是,我应该在 web.config 文件中添加什么?我以前从来没有编辑过它.这是它的当前内容:
What do I add to my web.config file though? I've never had to edit it before. Here is its current contents:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
</system.web>
</configuration>
我的错误是:
配置错误:权限不足,无法读取配置文件
配置文件:?C:Users*****DocumentsVisual Studio2010WebSitesPointsForTimeweb.config
Config Error: Cannot read configuration file due to insufficient permissions
Config File: ?C:Users*****DocumentsVisual Studio2010WebSitesPointsForTimeweb.config
推荐答案
您的 web.config 没有问题.您的网站在一个进程下运行.在 iis 中,您可以定义该进程的身份.您网站的应用程序池所运行的身份(网络服务、本地系统等)应具有访问和读取网络的权限.config 文件.
There is no problem with your web.config. Your web site runs under a process. In iis you can define the identity of that process. The identity that your web site's application pool runs as (Network Services, Local System, etc.), should have permission to access and read web.config file.
更新:
这个更新后的答案与上面的相同,但更长、更简单并有所改进.
首先:您不必更改配置文件中的任何内容.没关系.问题在于 Windows 文件权限.
First of all: you don't have to change anything in your config file. It's OK. The problem is with windows file permissions.
出现此问题是因为您的应用程序无法访问和读取 web.config 文件.
This problems occurs because your application can not access and read web.config file.
使 IIS_IUSRS 组可以访问该文件.只需右键单击 web.config 并单击 properties,在 security 选项卡下,添加 IIS_IUSRS.
Make the file accessible to IIS_IUSRS group. Just right click web.config and click properties, under security tab, add IIS_IUSRS.
那么这个 IIS_IUSRS 是什么东西?
So what is this IIS_IUSRS thing?
您的网站就像一个exe文件.就像任何 exe 文件一样,它应该由用户启动,并根据分配给该用户的权限运行.
Your web site is like an exe file. Just like any exe file, it should be started by a user and it runs according to permissions assigned to that user.
当您的网站在 IIS 中启动时,您网站的应用程序池会与用户(网络服务、本地系统,等等...)(并且可以在 IIS 中更改)
When your site is started in IIS, Application Pool of your web site is associated with a user (Network Services, Local System, Etc. ...) (and can be changed in IIS)
所以当您说 IIS_IUSRS 时,它意味着您的网站任何用户(网络服务、本地系统等...)正在运行.
So when you say IIS_IUSRS, it means any user (Network Services, Local System, Etc. ...) that your site is running as.
正如 @Seph 在下面的评论中提到的:如果您的计算机在域中,请记住IIS_IUSRS 组是一个本地组.还要确保在您尝试查找此用户时检查应将其设置为本地计算机而不是公司域的位置.
And as @Seph mentioned in comment below: If your computer is on a domain, remember that IIS_IUSRS group is a local group. Also make sure that when you're trying to find this user check the location it should be set to local computer and not a corporate domain.
这篇关于由于权限不足,无法读取配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!