Thomas Woelfer
Thomas Woelfer

Reputation: 623

TransformWebConfig task failed unexpectedly - access denied

I have added a web.config file to my net6 website which is hosted on azure. The web.config file should be transformed like documented here: ( https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations )

i'm using the web config in order to define a redirect rule for iis. (redirecting request to one domain to another domain.)

Now, when i try to publish the website, i receive an error that says "TrasnformWebConfig task failed unexpectedly". After searching for the cause i found this is caused by the web.config file in the "out" directory beeing read-only.

Now, i did look for answers to this problem and the one answer given quite often is, one should disable "WebConfigTransforms" altogether. (e.g.: "The "TransformWebConfig" task failed unexpectedly" on dotnet publish)

However, when i do this, the final web.config file placed on the server only contains "my" parts, not the parts that are needed for a core website to run at all. (visual studio (?) generates and publishes the 'default' parts that are needed for the site to function at all. if these parts are missing, the site is unuseable.) So, disabling the transformation altogether does not seem to be an option.

After some more fiddling, i found that the problem goes aways if i a check out my web.config file. If it is checked out from source control (i use tfs on vs online), it's also not read-only in the out directory and the transform works.

So i "quick" workaround is to check out the web.config before publishing. I don't think this should be necessary though. So how do i make this work without checking out the file?

Upvotes: 1

Views: 947

Answers (1)

SuryasriKamini-MT
SuryasriKamini-MT

Reputation: 925

I see that you have already tried disabling WebConfigTransforms, However, you can try the below workarounds to resolve the error :

Solution 1 :

Delete the following line in your csproj file.

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

Solution 2:

There is a bug related to UpperCases. In csproj file , try changing InProcess with lowercase

<AspNetCoreHostingModel>inprocess</AspNetCoreHostingModel>

Solution 3:

In your web.config , file try adding this line of code:

<handlers>
  <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>

Reference :
The "TransformWebConfig" task failed unexpectedly - System.Exception: The acceptable value for AspNetCoreModuleHostingModel property is either

Upvotes: -1

Related Questions