Web.Config中的模拟标记

25 asp.net impersonation web-config

impersonate在Asp.net 4.0网站的web.config中使用标签.

下面是我的Web.Config代码:

<system.web>
    <authentication mode="Windows">
        <identity impersonate="true"                 
            userName="Administrator" 
            password="LALLA$26526"/>
     </authentication>
</system.web>
Run Code Online (Sandbox Code Playgroud)

当我在Visual Studio中运行应用程序时,我收到此错误:

Parser Error Message: Unrecognized element 'identity'.
Run Code Online (Sandbox Code Playgroud)

来源错误:

Line 50:    <system.web>
Line 51:        <authentication mode="Windows">
Line 52:            <identity impersonate="true"             
Line 53:                 userName="Administrator"
Line 54:                 password="LALLA$26526"/>
Run Code Online (Sandbox Code Playgroud)

我哪里错了?

Jac*_*cob 76

identity部分属于该system.web部分,而不是在authentication:

<system.web>
  <authentication mode="Windows"/>
  <identity impersonate="true" userName="foo" password="bar"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)

  • 我高度怀疑在野外有一些糟糕的文档导致每个人都犯同样的错误;下一个遇到这种情况的人,你看到的错误参考是什么?让我们从源头上修复它! (2认同)
  • 你的意思是像 https://msdn.microsoft.com/en-us/library/72wdk8cc(v=vs.85).aspx 这样的糟糕的文档,它说你可以把身份元素放在配置层次结构中的任何地方 (2认同)

M4V*_*1CK 9

identity在之前元素authentication元素

  • 可悲的是,这实际上是问题的正确答案. (5认同)

sha*_*tha 8

您将identity节点作为节点的子authentication节点.那就是问题所在.如在上面的例子中,authenticationidentity节点必须是儿童system.web节点