No element in the source document matches /configuration/system.web/authorization/
Asked Answered
P

1

9

I have the next issue when transforming my Web.Config:

No element in the source document matches '/configuration/system.web/authorization/allow[@roles='WhateverGroupNameRenamedForProd']'

Here my Web.Config:

 <system.web>
<compilation targetFramework="4.5.2" debug="true" />
<httpRuntime targetFramework="4.5" />
<authorization>
  <allow roles="WhateverGroupName" />
  <deny users="*" />
</authorization>

And the Web.Production.Config:

<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<authorization>
  <allow roles="WhateverGroupNameRenamedForProd" xdt:Transform="SetAttributes" xdt:Locator="Match(roles)"/>
</authorization>

What I'm doing wrong? Thanks in advance :)

Proton answered 31/10, 2016 at 13:14 Comment(0)
P
7

For the ones already interested, I found and fixed the problem: It was basically on the SetAttributes:

My old code:

<allow roles="WhateverGroupNameRenamedForProd" xdt:Transform="SetAttributes" xdt:Locator="Match(roles)"/>

Should be replaced by:

<allow roles="WhateverGroupNameRenamedForProd" xdt:Transform="SetAttributes(roles)"/>

Then you have so specify the attribute name on the SetAttributes, in my case it was "roles".

Proton answered 31/10, 2016 at 13:51 Comment(1)
You have to understand what xdt:Locator=Match(roles) means and so why it didn't work : Find the element in the source file with specified value for roles (i.e. WhateverGroupNameRenamedForProd), then do the transform (SetAttributes). Since the <allow element in your source file had a role value of WhatevetGroupName, it did not match.Laclair

© 2022 - 2024 — McMap. All rights reserved.