将Web.Config移植到ASPNET5 [英] Porting a Web.Config to ASPNET5

查看:123
本文介绍了将Web.Config移植到ASPNET5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将项目升级到ASPNET5.我在升级web.config文件时遇到了麻烦.

I upgrading my project to ASPNET5. I'm hitting a snag regarding upgrading my web.config file.

我尝试使用Microsoft.Framework.ConfigurationModel.Xml包读取URL重写配置.配置如下:

I tried using Microsoft.Framework.ConfigurationModel.Xml package to read a URL Rewrite configuration. The config looks like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="MainRule" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" />
            <add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true" />
          </conditions>
          <action type="Rewrite" url="default.html" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

但是,当它尝试将其转换为aspnet5使用的对象时,我当然遇到了重复的关键问题.

but of course I'm getting duplicate key issues when it tries to convert it to the object that aspnet5 uses.

将现有的web.config移植到新的aspnet模型的最佳方法是什么?我意识到这是一个很小的情况,但是在现实世界中,这些配置确实非常复杂.

Whats the best way to port your existing web.config to the new aspnet model? This is a small case I realize but in the real world these configs are really intense.

我创建了一个示例项目,希望与之共享当我弄清其中一些情况时,其他人就会发现.

I've created an example project that I'm hoping to share with others when i get a few of these cases figured out.

推荐答案

您发布的web.config文件仅具有iis的URL重写规则.您是否真的需要从您的应用程序访问那些内容? IIS将直接从web.config中读取这些内容,但是您不需要在应用程序中使用这些内容,因此您根本不需要尝试使用Microsoft.Framework.Configuration中的新类来解析该文件.

the web.config file you posted only has url rewrite rules for iis. Do you really need to access those from your app? IIS will read those directly from the web.config but you shouldn't need that stuff in your app so you don't need to try to parse that file with the new classes in Microsoft.Framework.Configuration at all.

如果您的应用程序需要其他设置,那么您也可以使用json.config文件,如许多示例中所示,用于您自己的应用程序设置.

if your app needs some other settings then you might as well use a json.config file as shown in many examples for your own application settings.

您仍然可以将该web.config文件放入应用程序根目录,并假设您的应用程序托管在IIS中,它仍然应该执行其工作并告诉IIS进行一些URL重写.您不应将其重命名为config.xml,因为IIS不会注意到该文件,除非该文件名为web.config

you can still drop that web.config file into the application root and assuming your app is hosted in IIS it should still do its job and tell IIS to do some url rewriting. you should not rename it to config.xml as it appears you have done, since IIS won't notice the file unless it is named web.config

为什么要从应用程序代码访问所有url重写规则,因为它是IIS而不是进行URL重写的应用程序代码?

why would you need to access those url rewrite rules from application code at all since it is IIS and not application code that does the url rewriting?

我认为新的范例是使用json.config和/或天蓝色的环境变量进行应用程序配置

I think the new paradigm is use json.config and/or environment variables in azure for application configuration

您可能仍会使用web.config文件的唯一是IIS配置,但这与应用程序配置是分开的,这是您将继续使用web.config文件的唯一选择,并且您不需要访问Web完全来自应用程序代码中的.config文件.

The only thing you might still use a web.config file for is IIS configuration but that is separate from application configuration and that is the only thing you would use web.config files for going forward and you should not need to access web.config file from application code at all.

这篇关于将Web.Config移植到ASPNET5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆