Transform Webconfig任务出乎意料的失败 - 访问被拒绝

发布于 2025-02-10 03:19:15 字数 983 浏览 0 评论 0原文

我已经在Azure托管的Net6网站中添加了一个Web.config文件。 web.config文件应像在此处一样转换:< Web-config-transrymations“ rel =“ nofollow noreferrer”> https://learn.microsoft.com/en-us/aspnet/web-forms/web-forms/overview/deployment/visual-studio-studio-studio-web-deployment/web-config-transformations )

我正在使用Web配置来定义IIS的重定向规则。 (将请求重定向到一个域。)

现在,当我尝试发布网站时,我收到一个错误,上面写着“ TrasnformWebConfig任务意外失败”。搜索原因后,我发现这是由“ out”目录beeing heolly读取中的web.config文件引起的。

现在,我确实在寻找这个问题的答案,并且经常给出的一个答案是,应该完全禁用“ webconfigtransforms”。 (例如:” /a>)

但是,当我这样做时,放置在服务器上的最终web.config文件仅包含“我的”零件,而不是核心网站完全运行的零件。 (Visual Studio(?)生成并发布该网站所需的“默认”部分。如果缺少这些部分,则该站点是无法使用的。)因此,,完全禁用转换似乎不是一个选择。

经过更多的摆弄后,我发现如果IA查看我的Web.config文件,问题就会出现。如果从源控件中检查了一下(我在网上使用TFS),则它在OUT目录和转换工作中也不是读取的。

因此,我“快速”的解决方法是在发布前查看web.config。我认为这不是必需的。那么,如何在不查看文件的情况下进行此工作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄与心 2025-02-17 03:19:16

我看到您已经尝试禁用webconfigtransforms,但是,您可以尝试以下解决方法来解决错误:

解决方案1:

删除csproj中的以下行文件。

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

解决方案2:

有一个与大写有关的错误。在csproj文件中,尝试更改inprocess使用小写

<AspNetCoreHostingModel>inprocess</AspNetCoreHostingModel>

解决方案3:

web.config中,文件代码线:

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

参考
the“ transformwebconfig” AspnetCoreModuleHostingModel属性的价值是

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文