首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nuget web.config.install.xdt未转换

Nuget web.config.install.xdt未转换
EN

Stack Overflow用户
提问于 2014-09-21 00:50:34
回答 1查看 1.9K关注 0票数 1

当我的NuGet包安装时,我在弄清楚如何转换web.config文件时遇到了问题。它正在进行一些转换,但不是全部。

下面是在安装我的NuGet包时需要修改的未修改的web.config文件:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <authentication mode="None" />  ***** I want this removed *****
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthentication" />  ***** I want this removed *****
    </modules>
  </system.webServer>
</configuration>

下面是我想要的结果:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="MvcMailer.BaseURL" value="" />
    <add key="SecurityGuardEmailFrom" value="info@email.net" />
    <add key="SecurityGuardEmailSubject" value="Your Password has been reset." />
    <add key="SecurityGuardEmailTemplatePath" value="~/MailerTemplates/ResetPassword.html" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/SGAccount/Login" timeout="2880" />
    </authentication>
  </system.web>
  <system.webServer>
    <modules>
    </modules>
  </system.webServer>
</configuration>

这是MVC应用程序中转换后的web.config文件,这是不正确的:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="MvcMailer.BaseURL" value="" />
    <add key="SecurityGuardEmailFrom" value="info@email.net" />
    <add key="SecurityGuardEmailSubject" value="Your Password has been reset." />
    <add key="SecurityGuardEmailTemplatePath" value="~/MailerTemplates/ResetPassword.html" />
  </appSettings>
  <system.web>
    <authentication mode="None" />  ***** Not removed when it should be *****
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/SGAccount/Login" timeout="2880" />
    </authentication>
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthentication" />  ***** Not removed when it should be *****
    </modules>
  </system.webServer>
</configuration>

这是我的web.config.install.xdt文件:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <authentication mode="None" xdt:Transform="Remove" xdt:Locator="Match(mode)" />
    <authentication mode="Forms" xdt:Transform="Insert">
      <forms loginUrl="~/SGAccount/Login" timeout="2880" />
    </authentication>
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthentication" xdt:Transform="Remove" xdt:Locator="Match(name)" />
    </modules>
  </system.webServer>
</configuration>

我已经阅读了Nuget.org站点上有关如何使用XDT转换的所有文档,它甚至可以在测试站点https://webconfigtransformationtester.apphb.com/上使用,但它不能工作。

我被难住了。对如何实现这一点有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2014-09-22 09:06:03

下面是成功处理该任务的新web.config.install.xdt的外观:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="SecurityGuardEmailFrom" value="info@email.net" xdt:Transform="Insert" />
    <add key="SecurityGuardEmailSubject" value="Your Password has been reset." xdt:Transform="Insert" />
    <add key="SecurityGuardEmailTemplatePath" value="~/MailerTemplates/ResetPassword.html" xdt:Transform="Insert" />  
  </appSettings>
  <system.web>
    <authentication mode="Forms" xdt:Transform="SetAttributes" />
    <authentication mode="Forms">
      <forms loginUrl="~/SGAccount/Login" timeout="2880" xdt:Transform="Insert" />
    </authentication>
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthentication" xdt:Transform="Remove" />
    </modules>
  </system.webServer>
</configuration>

我没有尝试删除原始的身份验证元素,而是更改了mode属性,然后插入了forms元素。一旦它正确工作,其余的似乎就会自动解决。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25951129

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档