设为首页收藏本站

Scripts 学盟

 找回密码
 加入学盟

QQ登录

只需一步,快速开始

查看: 1773|回复: 1
打印 上一主题 下一主题

错误 137 在应用程序级别之外使用注册为 allowDefinition='MachineTo [复制链接]

Rank: 2

跳转到指定楼层
1#
嘟嘟 发表于 2011-7-18 17:29:12 |只看该作者 |倒序浏览
本帖最后由 嘟嘟 于 2011-7-18 17:31 编辑

今天做程序报了个错误:
自己遇到并解决:
"错误        137        在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误。        F:\djx_\Test\TestExt\UI\Scripts\web.config        30"        NND,让我找了20分钟的错误!终于找到了罪恶的根源-----------------------------------web.config  文件   不小心被我拖到别的目录下边,没在根目录下导致了错误!!!!


网上别的解决方法总结一下:
  原因:如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误。

1、若IIS中没有应用程序名,先创建,若还不行把C:\WINDOWS\Microsoft.NET\work\v2.0.50727\CONFIG\machine.config中的所有allowDefinition="MachineToApplication"改为allowDefinition="Everywhere"

2、在网站对应的虚拟目录上右键,选属性,然后在应用程序名后点创建。



另例一:

在ASP.NET2.0中,如果根目录允许匿名用户访问,而根目录下的一个页面(如Index.aspx)必须要登录(假设登录页面为login.aspx)后才能访问,根目录下的web.config文件必须这样配置:

<?xml version="1.0"?>
<configuration>
<appSettings>
</appSettings>
<connectionStrings>
</connectionStrings>
<system.web>
        <compilation debug="true"/>
        <authentication mode="Windows"/>
           <authentication mode="Forms">
                <forms loginUrl="login.aspx" protection="All" path="/" timeout="30"/>
            </authentication>
        <authorization>
     <!--允许匿名-->
    <allow users="?"/>
    </authorization>
</system.web>
<location path="Info.aspx">
    <system.web>

<!--认证项配置(在为一个单独页面指定认证信息时,authentication节只能从这个目录继承,不能单独设置)-->
      <!--
      <authentication mode="Forms">
        <forms name=".www.cnpp.info" loginUrl="login.aspx" protection="All" path="/" timeout="30"/>
      </authentication>
      -->

<!--用户访问控制-->
        <authorization>
        <!--阻止匿名-->
        <deny users="?"/>
      </authorization>
    </system.web>
</location>
</configuration>

也就是在需要认证的页面配置节中不能配置authentication项,只能在在根目录中配置authentication项,Info.aspx从根目录继承. 否则会出现这样的错误: "在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误 "



另例二:

我想让用户在访问我的程序的Admin文件夹下的页面时需要登录,而在访问其他页面时则不需要,也就是说Admin文件夹下的文件拒绝匿名访问.
   下面是配置根目录下的web.config文件中关于授权验证的配置
   <system.web>
         <authentication mode="Forms">
             <forms loginUrl="Admin/Login.aspx"></forms>
         </authentication>
         <authorization>
             <allow users="*"/>
         </authorization>
   </system.web>
   <location path="Admin">
         <system.web>
             <authorization>
                 <deny users="?"/>
             </authorization>
         </system.web>
   </location>
   注意location节,location节不需要<authorization>节了,假若加了的话,便会出现"在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' "这样的错误了,若在子文件下添加配置文件时也要注意相同的问题.
1

查看全部评分

分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
分享分享0 收藏收藏0
哈哈哈大笑三声!

Rank: 8Rank: 8

2#
那个谁 发表于 2011-7-19 13:23:04 |只看该作者
好好。。。好不错。顶

使用道具 举报

您需要登录后才可以回帖 登录 | 加入学盟

手机版|Scripts 学盟   |

GMT+8, 2024-5-7 01:53 , Processed in 1.056305 second(s), 12 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部