.net core 2.0 webb怎么发布

.NET Core 2.0迁移小技巧之web.config 配置文件示例详解_asp.net教程-织梦者
当前位置:&>&&>& > .NET Core 2.0迁移小技巧之web.config 配置文件示例详解
.NET Core 2.0迁移小技巧之web.config 配置文件示例详解
本文将为关注织梦者的朋友提供的是的.NET Core 2.0迁移小技巧之web.config 配置文件示例详解相关教程,具体实例代码请看下文:前言
相信大家应该都知道.NET Core现在不再支持原来的web.config配置文件了,取而代之的是json或xml配置文件。官方推荐的项目配置方式是使用appsettings.json配置文件,这对现有一些重度使用web.cofig配置的项目迁移可能是不可接受的。
但是好消息是,我们是可以直接在.NET Core 2.0项目种利用上现有的web.config的。本文将详细介绍.NET Core 2.0迁移之web.config 配置文件的相关内容,下面话不多说了,来一起看看详细的介绍吧。
1.首先在解决方案中引入System.Configuration.ConfigurationManager,只有引入它才可以让我们已有的读取web.config代码起作用.
2. 导入web.config文件到项目根目录,并将名称修改为app.config. 因为.NET Core的项目本质是控制台应用,所以ConfigurationManager的API会去默认读取app.config配置文件,而不是web.config配置文件。
3.去除config中和需要的配置无关的内容,主要是&system.web& , &system.webServer&和&system.codedom&等典型标签。
&?xml version="1.0" encoding="utf-8"?&
&configuration& &configSections& &!-- For more information on Entity Framework configuration, visit /fwlink/?LinkID=237468 --& &section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c" requirePermission="false" /& &/configSections& &connectionStrings& &add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication24-02.Initial Catalog=aspnet-WebApplication24-02;Integrated Security=True"
providerName="System.Data.SqlClient" /& &/connectionStrings&
&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="MyKey" value="true"/&
&/appSettings&
&system.web&
&compilation debug="true" targetFramework="4.7" /&
&httpRuntime targetFramework="4.7" /&
&httpModules&
&add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /&
&/httpModules&
&/system.web&
&assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&
&dependentAssembly&
&assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /&
&bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /&
&/dependentAssembly&
&dependentAssembly&
&assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf" /&
&bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /&
&/dependentAssembly&
&dependentAssembly&
&assemblyIdentity name="WebGrease" publicKeyToken="31bf" /&
&bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&
&/dependentAssembly&
&dependentAssembly&
&assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf" /&
&bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&
&/dependentAssembly&
&dependentAssembly&
&assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf" /&
&bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&
&/dependentAssembly&
&dependentAssembly&
&assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf" /&
&bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" /&
&/dependentAssembly&
&/assemblyBinding&
&/runtime&
&system.webServer&
&validation validateIntegratedModeConfiguration="false" /&
&remove name="ApplicationInsightsWebTracking" /&
&add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /&
&/modules&
&/system.webServer&
&system.codedom&
&compilers&
&compiler language="c#;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf" warningLevel="4" compilerOptions="/langversion:default /nowarn:01" /&
&compiler language="vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&Web\& /optionInfer+" /&
&/compilers&
&/system.codedom&
&/configuration&
&?xml version="1.0" encoding="utf-8"?&
&configuration&
&configSections&
&!-- For more information on Entity Framework configuration, visit /fwlink/?LinkID=237468 --&
&section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c" requirePermission="false" /&
&/configSections&
&connectionStrings&
&add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication24-02.Initial Catalog=aspnet-WebApplication24-02;Integrated Security=True"
providerName="System.Data.SqlClient" /&
&/connectionStrings&
&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="MyKey" value="true"/&
&/appSettings&
&/configuration&
4.测试原ASP.NET代码,查看读取配置值
using System.C
namespace WebConfigTest.Configuration
public class ConfigurationService
public static bool GetConfigValue(string key)
var result =
var val= ConfigurationManager.AppSettings[key];
if (val != null)
result = bool.Parse(val);
打个断点,看下读取配置值是否正确:
大功告成,读取的配置值完全正确。
大家可以使用这个方法快速迁移现有配置文件和代码过去啦。
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对织梦者的支持。谢谢您的访问.
这些内容可能对你也有帮助
更多可查看asp.net教程列表页。
猜您也会喜欢这些文章登录以解锁更多InfoQ新功能
获取更新并接收通知
给您喜爱的内容点赞
关注您喜爱的编辑与同行
966,690 十月 独立访问用户
语言 & 开发
架构 & 设计
文化 & 方法
您目前处于:
.NET Core 2.0终于发布了
.NET Core 2.0终于发布了
0&他的粉丝
日. 估计阅读时间:
:Facebook、Snapchat、Tumblr等背后的核心技术
Author Contacted
语言 & 开发
87 他的粉丝
架构 & 设计
270 他的粉丝
10 他的粉丝
280 他的粉丝
相关厂商内容
相关赞助商
告诉我们您的想法
允许的HTML标签: a,b,br,blockquote,i,li,pre,u,ul,p
当有人回复此评论时请E-mail通知我
Re: wonderful
允许的HTML标签: a,b,br,blockquote,i,li,pre,u,ul,p
当有人回复此评论时请E-mail通知我
允许的HTML标签: a,b,br,blockquote,i,li,pre,u,ul,p
当有人回复此评论时请E-mail通知我
赞助商链接
架构 & 设计
文化 & 方法
<及所有内容,版权所有 &#169;
C4Media Inc.
服务器由 提供, 我们最信赖的ISP伙伴。
北京创新网媒广告有限公司
京ICP备号-7
找回密码....
InfoQ账号使用的E-mail
关注你最喜爱的话题和作者
快速浏览网站内你所感兴趣话题的精选内容。
内容自由定制
选择想要阅读的主题和喜爱的作者定制自己的新闻源。
设置通知机制以获取内容更新对您而言是否重要
注意:如果要修改您的邮箱,我们将会发送确认邮件到您原来的邮箱。
使用现有的公司名称
修改公司名称为:
公司性质:
使用现有的公司性质
修改公司性质为:
使用现有的公司规模
修改公司规模为:
使用现在的国家
使用现在的省份
Subscribe to our newsletter?
Subscribe to our industry email notices?
我们发现您在使用ad blocker。
我们理解您使用ad blocker的初衷,但为了保证InfoQ能够继续以免费方式为您服务,我们需要您的支持。InfoQ绝不会在未经您许可的情况下将您的数据提供给第三方。我们仅将其用于向读者发送相关广告内容。请您将InfoQ添加至白名单,感谢您的理解与支持。其他回答(2)
System.Web 按照别人的说法 太臃肿了 没有和IIS解耦所以 微软应该推出新的框架代替了
2.0出来了,,也不支持啊
&&&您需要以后才能回答,未注册用户请先。.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验
时间: 10:49:40
&&&& 阅读:659
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&&.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验
.NET Standard 2.0 is final
Broad platform support. .NET Standard 2.0 is&supported on the following platforms:
.NET Framework 4.6.1
.NET Core 2.0
Xamarin.iOS 10.14
Xamarin.Mac 3.8
Xamarin.Android 7.5
UWP is work in progress and will ship later this year.
/dotnet/standard/issues/439&
.NET Core 2.0 正式版Nuget库: https://dotnet.myget.org/gallery/dotnet-2-0-0-rtm
.NET Core 2.0 正式版发布时间将会在.NET Conf 上发布。具体时间为9月18日或19日。
.NET Core 2.0.1 SDK Windows x64下载
https://dotnetcli.blob.core.windows.net/dotnet/Sdk/release/2.0.0/dotnet-sdk-latest-win-x64.exe
更多版本下载:/dotnet/cli/tree/release/2.0.0
下面来正式体验。本文使用sdk 压缩包。
dotnet --info
新建项目 dotnet new console
在项目目录下添加 NuGet.Config 如下:
&?xml version="<span style="color: #.0" encoding="utf-8"?&
&configuration&
&packageSources&
&add key="dotnet-2-0-0-rtm" value="https://dotnet.myget.org/F/dotnet-2-0-0-rtm/api/v3/index.json" /&
&/packageSources&
&/configuration&
添加 System.Data.SqlClient&包,使用dotnet add package 或者编辑csproj。
&Project Sdk="Microsoft.NET.Sdk"&
&PropertyGroup&
&OutputType&Exe&/OutputType&
&TargetFramework&netcoreapp2.<span style="color: #&/TargetFramework&
&/PropertyGroup&
&ItemGroup&
&PackageReference Include="System.Data.SqlClient" Version="<span style="color: #.4.0" /&
&/ItemGroup&
&/Project&
接着还原包
然后使用VS Code 打开文件夹,实现ado.net 获取DataTable。
编写代码如下:
using System.D
using System.Data.SqlC
namespace adonetdemo
class Program
static void Main(string[] args)
Console.WriteLine("Hello World!");
string connectionString = "Data Source=.;database=Nuid=pwd=";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter("select * from Notes",conn);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
DataTable dt = dataset.Tables[<span style="color: #];
foreach (var item in dt.Rows)
DataRow row=item as DataR
System.Console.WriteLine(row["Title"]);
System.Console.WriteLine("本文原创LineZero");
运行显示结果如下:
新建项目 dotnet new mvc
Program.cs 已经精简如下:
public class Program
public static void Main(string[] args)
BuildWebHost(args).Run();
public static IWebHost BuildWebHost(string[] args) =&
WebHost.CreateDefaultBuilder(args)
.UseStartup&Startup&()
使用dotnet run 运行。
新建项目 dotnet new razor
目录下会发现只有Pages 文件夹,然后只有视图页和视图对应的cs文件,代码也可以在视图页上编写。
将Index改成如下:
&h3&@Model.Name&/h3&
Index.cshtml.cs 如下:
public class IndexModel : PageModel
public string N
public void OnGet()
Name="LineZero Blog";
运行程序dotnet run:
开发调试项目
本文使用VS Code ,版本: 1.14.2 C#插件版本:1.12.0
VS Code 首次使用的话需要确保C#插件全部下载完成如下图:
最新版本VS
应该也是支持.NET Core 2.0。
本部分使用adonetdemo 项目做演示。直接调试可以参考之前文章:
使用附加调试进行调试。
选择.NET Core Attach 这里在代码中加入Console.ReadKey();,使程序暂时不退出,然后附加。
点击调试,注意选择第一个,dotnet exec 。
然后按任意键,开始进行调试
可以正常调试,并显示信息。
最后.NET Core 2.0 的正式版微软正式发布还有一段时间,本文不代表最终.NET Core 2.0正式版。
如果你觉得本文对你有帮助,请点击“推荐”,谢谢。&标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&国之画&&&& &&&&chrome插件&&
版权所有 京ICP备号-2
迷上了代码!今天看啥 热点:
.NET Core 2.0迁移小技巧之web.config 配置文件示例详解,coreweb.config前言
相信大家应该都知道.NET Core现在不再支持原来的web.config配置文件了,取而代之的是json或xml配置文件。官方推荐的项目配置方式是使用appsettings.json配置文件,这对现有一些重度使用web.cofig配置的项目迁移可能是不可接受的。
但是好消息是,我们是可以直接在.NET Core 2.0项目种利用上现有的web.config的。本文将详细介绍.NET Core 2.0迁移之web.config 配置文件的相关内容,下面话不多说了,来一起看看详细的介绍吧。
1.首先在解决方案中引入System.Configuration.ConfigurationManager,只有引入它才可以让我们已有的读取web.config代码起作用.
2. 导入web.config文件到项目根目录,并将名称修改为app.config. 因为.NET Core的项目本质是控制台应用,所以ConfigurationManager的API会去默认读取app.config配置文件,而不是web.config配置文件。
3.去除config中和需要的配置无关的内容,主要是&system.web& , &system.webServer&和&system.codedom&等典型asp.net标签。
&&#63;xml version="1.0" encoding="utf-8"&#63;&
&configuration& &configSections& &!-- For more information on Entity Framework configuration, visit /fwlink/&#63;LinkID=237468 --& &section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c" requirePermission="false" /& &/configSections& &connectionStrings& &add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication24-02.Initial Catalog=aspnet-WebApplication24-02;Integrated Security=True"
providerName="System.Data.SqlClient" /& &/connectionStrings&
&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="MyKey" value="true"/&
&/appSettings&
&system.web&
&compilation debug="true" targetFramework="4.7" /&
&httpRuntime targetFramework="4.7" /&
&httpModules&
&add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /&
&/httpModules&
&/system.web&
&assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&
&dependentAssembly&
&assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /&
&bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /&
&/dependentAssembly&
&dependentAssembly&
&assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf" /&
&bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /&
&/dependentAssembly&
&dependentAssembly&
&assemblyIdentity name="WebGrease" publicKeyToken="31bf" /&
&bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&
&/dependentAssembly&
&dependentAssembly&
&assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf" /&
&bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&
&/dependentAssembly&
&dependentAssembly&
&assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf" /&
&bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&
&/dependentAssembly&
&dependentAssembly&
&assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf" /&
&bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" /&
&/dependentAssembly&
&/assemblyBinding&
&/runtime&
&system.webServer&
&validation validateIntegratedModeConfiguration="false" /&
&remove name="ApplicationInsightsWebTracking" /&
&add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /&
&/modules&
&/system.webServer&
&system.codedom&
&compilers&
&compiler language="c#;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf" warningLevel="4" compilerOptions="/langversion:default /nowarn:01" /&
&compiler language="vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&Web\& /optionInfer+" /&
&/compilers&
&/system.codedom&
&/configuration&
&&#63;xml version="1.0" encoding="utf-8"&#63;&
&configuration&
&configSections&
&!-- For more information on Entity Framework configuration, visit /fwlink/&#63;LinkID=237468 --&
&section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c" requirePermission="false" /&
&/configSections&
&connectionStrings&
&add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication24-02.Initial Catalog=aspnet-WebApplication24-02;Integrated Security=True"
providerName="System.Data.SqlClient" /&
&/connectionStrings&
&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="MyKey" value="true"/&
&/appSettings&
&/configuration&
4.测试原ASP.NET代码,查看读取配置值
using System.C
namespace WebConfigTest.Configuration
public class ConfigurationService
public static bool GetConfigValue(string key)
var result =
var val= ConfigurationManager.AppSettings[key];
if (val != null)
result = bool.Parse(val);
打个断点,看下读取配置值是否正确:
大功告成,读取的配置值完全正确。
大家可以使用这个方法快速迁移现有配置文件和代码过去啦。
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对帮客之家的支持。
相关搜索:
相关阅读:
相关频道:
&&&&&&&&&&&&&&&&
Asp.Net教程最近更新

我要回帖

更多关于 .net core 2.0 web 的文章

 

随机推荐