[ASP.NET Core开发实战]基础篇06 配置

ASP.NET Core Identity 使用教程 ASP.NET Core Identity 是微软提供的一个用于处理用户身份验证和授权的库。它可以轻松地与 ASP.NET Core 应用程序集成,并支持多种身份验证方式,如密码、社交登录(如 Google、Facebook)、双因素认证等。Identity 默认使用 Entity Framework Core 来处理用户和角色的存储,但也可以自定义存储机制。ASP.NET Core Identity 为开发人员提供了一个灵活而强大的身份验证和授权解决方案。 阅读详情

配置,是应用程序很重要的组成部分,常常用于提供信息,像第三方应用登录钥匙、上传格式与大小限制等等。

ASP.NET Core提供一系列配置提供程序读取配置文件或配置项信息。

ASP.NET Core项目启动时默认加载的配置有:

  • 命令行参数
  • 环境变量
  • appsettings.json、appsettings.Environment.json、appsettings.Production.json等

【示例代码下载】

常用的配置提供程序

ASP.NET Core常用的配置Provider有:

  • CommandLineConfigurationProvider(命令行配置)
  • EnvironmentVariablesConfigurationProvider(环境变量配置)
  • FileConfigurationProvider(文件配置)

命令行配置

命令行配置Provider通过读取应用启动时的命令行参数来设置配置项。

默认情况下,在命令行上设置的配置值会替换通过所有其他配置提供程序设置的配置值。

支持的命令格式

  • 无前缀的key=value模式
  • 双中横线模式--key=value或--key value
  • 正斜杠模式 /key=value或/key value

注:等号分隔符和空格分隔符不能混用

命令替换模式

  • 必须以单划线(-)或双划线(--)开头
  • 映射字典不能包含重复Key

注:使用单划线时,代表需要替换的占位符,必须进行替换,不然会报错。
在这里插入图片描述

配置位置

{
  "profiles": {
    "ConfigurationProviderSample.ConsoleApp": {
      "commandName": "Project",
      "commandLineArgs": "MyKey1=cmd --MyKey3=cmd /MyKey6=cmd --k1=k3",
      "environmentVariables": {
        "MyKey2": "situation"
      }
    }
  }
}

在launchSettings.json文件里的profiles.[项目名].commandLineArgs属性。

代码示例:

class Program
{
    static void Main(string[] args)
    {
        IConfigurationBuilder builder = new ConfigurationBuilder();

        // 加载命令行参数
        builder.AddCommandLine(args);

        //// 替换参数,注意要去命令行参数那里把双划线--k1改成单划线-k1,并且要注释上面一句代码。
        //var mapper = new Dictionary<string, string>() { { "-k1", "MyKey7" } };
        //builder.AddCommandLine(args, mapper);

        var configurationRoot = builder.Build();
        Console.WriteLine($"MyKey1:{configurationRoot["MyKey1"]}");
        Console.ReadKey();
    }
}

输出结果:
在这里插入图片描述
在这里插入图片描述

环境变量配置

环境变量配置,通过读取操作系统的环境变量参数来设置配置项。

适用场景

  • 在Docker中运行
  • 在Kubernetes中运行
  • 需要设置ASP.NET Core的一些内置特殊配置时

特性

  • 对于配置的分层键,支持用双下划线(__)代替冒号(:)。在Linux中是支持冒号(:)
  • 支持根据前缀加载

代码示例:

class Program
{
    static void Main(string[] args)
    {
        IConfigurationBuilder builder = new ConfigurationBuilder();

        // 分层键
        builder.AddEnvironmentVariables();
        var configurationRoot = builder.Build();

        Console.WriteLine($"MyKey2:{configurationRoot["MyKey2"]}");

        var section = configurationRoot.GetSection("SECTION1");
        Console.WriteLine($"MyKey2:{section["MyKey2"]}");

        // 支持多重分层
        var section2 = configurationRoot.GetSection("SECTION1:SECTION2");
        Console.WriteLine($"MyKey2:{section2["MyKey2"]}");
        Console.ReadKey();

        //// 前缀过滤

        //builder.AddEnvironmentVariables("PREFIX_");

        //var configurationRoot = builder.Build();

        //Console.WriteLine($"MyKey2:{configurationRoot["MyKey2"]}");
        //Console.ReadKey();
    }
}

文件配置

常用的文件格式有:ini、json和xml。

特性

  • 指定文件可选、必选。
  • 指定是否监听文件的变更。

示例代码:

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration((hostingContext, config) =>
            {
                // 普通加载文件
                config.AddJsonFile("appsettings.json");

                // 演示指定文件可选
                config.AddJsonFile("appsettings.Development.json", true);

                // 演示指定文件变更
                config.AddJsonFile("appsettings.Production.json", false, true); 
            })
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
}

注:最终配置项的值跟文件加载的顺序有关。

配置优先级

当同时使用命令行配置、环境变量配置、文件配置,并且有相同配置项名字时,如何判断使用哪个配置项。

使用ASP.NET Core项目的默认模板,通过修改文件launchSettings.json的commandLineArgs和environmentVariables

    "ConfigurationProviderSample": {
      "commandName": "Project",
      "commandLineArgs": "MyKey1=cmd --MyKey3=cmd /MyKey6=cmd --k1=k3",
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "MyKey2": "situation",
        "SECTION1__MyKey2": "hello world",
        "SECTION1__SECTION2__MyKey2": "hi world",
        "PREFIX_MyKey2": "hello world"
      }
    }

另外,appsettings.json如下:

{
  "MyKey1": "appsettings.json",
  "MyKey2": "appsettings.json",
  "MyKey3": "appsettings.json",
  "MyKey4": "appsettings.json",
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

结果如下:
在这里插入图片描述

通过上述结果可知,当同时使用命令行配置、环境变量配置、文件配置时,优先级是:命令行 > 环境变量 > 文件。

如何使用配置

上面介绍了如何加载配置,下面介绍如何在ASP.NET Core中使用配置。下面介绍三种常用的方式:

  • 在Razor Pages中使用配置
  • 在MVC视图中使用配置
  • 在Startup中使用配置

在Startup中使用配置

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
        Console.WriteLine($"MyKey : {Configuration["MyKey"]}");
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        Console.WriteLine($"Position:Title : {Configuration["Position:Title"]}");

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapRazorPages();
        });
    }
}

在Razor Pages中使用配置

通过inject语法注入配置对象IConfiguration。

@page
@model Test5Model
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration

Configuration value for 'MyKey': @Configuration["MyKey"]

在Startup.ConfigureServices中配置MyOptions。

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<MyOptions>(Configuration.GetSection("MyOptions"));

    services.AddRazorPages();
}

通过inject注入。

@page
@model SampleApp.Pages.Test3Model
@using Microsoft.Extensions.Options
@inject IOptions<MyOptions> optionsAccessor


<p><b>Option1:</b> @optionsAccessor.Value.Option1</p>
<p><b>Option2:</b> @optionsAccessor.Value.Option2</p>

在MVC视图中使用配置

方式与Razor Pages类似。

@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration

Configuration value for 'MyKey': @Configuration["MyKey"]
public void ConfigureServices(IServiceCollection services)
{
    services.Configure<MyOptions>(myOptions =>
    {
        myOptions.Option1 = "Value configured in delegate";
        myOptions.Option2 = 500;
    });

    services.AddRazorPages();
}

可通过Model类注入配置来初始化。

public class Test2Model : PageModel
{
    private readonly IOptions<MyOptions> _optionsDelegate;

    public Test2Model(IOptions<MyOptions> optionsDelegate )
    {
        _optionsDelegate = optionsDelegate;
    }

    public ContentResult OnGet()
    {
        return Content($"Option1: {_optionsDelegate.Value.Option1} 
" +
                       $"Option2: {_optionsDelegate.Value.Option2}");
    }
}
使用ASP.NET core 6.0的心得 ASP.NET Core 6.0 阅读详情

相关推荐

ASP.NET Core 多环境配置:从萌新到高手的进阶之路

通过这篇深入浅出的ASP.NET Core多环境配置教程,相信你已经掌握了如何在不同环境中优雅地管理配置的方法。无论是使用配置文件还是环境变量,ASP.NET Core都提供了灵活的方式来适应各种场景。🎉希望这篇教程能帮助你在日常开发中更加高效地使用ASP.NET Core。如果你有任何疑问或者想要分享自己的经验,请随时留言交流!😊以上就是我们今天的全部内容啦!是不是感觉ASP.NET Core的多环境配置魅力又增加了不少呢?记得练习哦,熟能生巧嘛!😉。

java专栏 1195

asp.net中commandname应用

http://blog.sina.com.cn/s/blog_6672120701010y7e.html 有时候需要几个按纽调用同一模块,实现相似(而非相同)的功能,需要用到按纽的CommandName行为 实现步骤如下: 1、VS2005新建一个网站项目,拖入两个web控件Button控件,分别设置CommandName为btn1,btn2,btn3,btn4;再分

Lyncai的专栏 4116

迪文串口屏开发环境搭建全流程:从DGUS Tool到串口联调

串口屏作为嵌入式人机交互的核心组件,通过串口通信实现主控MCU与显示终端的指令交互。其工作原理基于变量地址映射,主控读写VP地址即可驱动屏上控件,兼具低功耗与高稳定性。在工业控制、医疗设备及智能家居面板等场景中,串口屏能显著降低开发门槛与硬件成本。迪文屏凭借DGUS Tool上位机与自定义串口协议,成为主流选择。掌握DGUS Tool版本匹配、串口驱动安装及VP地址规划,是快速搭建开发环境的关键。

weixin_33937499的博客 602

ASP.NET控件使用——Button中关于CommandName 和 CommandArgument 的理解?????

(一)CommandName:其实可以设置成一种动作,比如Select,Update,Delete,等操作。。就是说CommandName是确定他到底引发的是哪一事件,如果CommandName的名字 等于datalist 的事件的名字 他就引发事件  CommandArgument:可以设置,如果是Delete的话就可以设置id,就是主键,根据得出的主键值进行删除操作 (二)

francy1025的专栏 1943

手把手教你逆向分析某里系bx-ua参数(以225版本为例)

本文详细解析了某里系应用bx-ua参数的逆向工程实战方法,重点拆解其三层加密体系(二进制加密、字符替换和Base64编码)。通过工具链配置和实战案例,帮助开发者掌握逆向分析技巧,适用于合法合规的安全研究和加密技术评估场景。

weixin_33220360的博客 407

【信创-k8s】银河麒麟V10国防版+鲲鹏/飞腾(arm64架构)在线/离线部署k8s1.30+kubesphere

银河麒麟作为国家核高基专项的重要成果,国防版凭借其卓越的安全性和可靠性,已成为军工领域的首选操作系统。之前我们在适配麒麟V4国防版的过程中已发现诸多安全性要求,而麒麟V10国防版在安全防护等级上又达到了更高的级别。本文将主要演示离线部署,因为军工项目基本不会出现联网场景。即使在线,也可以按离线方式部署,且离线部署由于有私有仓库,不会存在镜像获取不到和丢失情况。

2023年最新地推相关信息 539

golang 命令行 command line (flag,os,arg,args)

golang 命令行 command line (flag,os,arg,args)

云满笔记 1339

python毕设 基于Web的中药材信息查询系统程序+论文

***(程序+源码+数据库+调试部署+开发环境)论文文档1,文末可获取,系统界面在最后面。****

m0_74825541的博客 1257

CommandName属性和CommandArgument属性

在ASP.NET页面中利用CommandName属性和CommandArgument属性:   你也许对LinkButton组件中CommandName属性和CommandArgument属性有点迷惑,他们到底会有什么作用。其实他们有着非常重要的作用。举例如下:   假如在你的一个页面中有100个LinkButton,那么在服务器端要判断到底是哪个LinkButton被按动了。如果没有

ゞ修ζ止符℡_R 1480

华为OD机试 - 末世分配资源包 - 二分查找 + 贪心(Python/JS/C/C++ 新系统 100分)

本专栏收录于《华为OD机试真题(Python/JS/C/C++)》。刷的越多,抽中的概率越大,私信哪吒,备注华为OD,加入华为OD刷题交流群,每一题都有详细的答题思路、详细的代码注释、3个测试用例、为什么这道题采用XX算法、XX算法的适用场景,发现新题目,随时更新。末世时代,政府为各地方配资源,现有资源分配表 nums[n],要求按如下规则分配给 k 个营地:在最优平均分配情况下,得到最大团队所获得的资源数4,3,6,9,7 216最佳划分之一:[4,3,6] -> 13 [9,7] -> 16最大

学Java,找哪吒 223

PCL ——LevenbergMarquardt非线性最小二乘法拟合圆柱(C++详细过程版)

使用C++详细过程版实现的LevenbergMarquardt非线性最小二乘法拟合圆柱

点云侠的博客 606

【Asp.Net】Asp.Net CommandName作用

数据绑定控件的模板中 CommandName 属性以下属性值会触发特定的事件: Cancel(取消) Delete(删除) Select(选择) Edit(编辑) Insert(插入) Update(更新) Sort(排序)...

weixin_33889665的博客 345

(第14天)Veritas NetBackup(NBU) 配合 RMAN 脚本备份 Oracle 数据库

NBU(Veritas Netbackup)是企业中比较常用的备份软件,通常用于备份企业使用中的系统,数据库,文件等等,通常是搭配 Oracle RMAN 来进行备份 Oracle 数据库。

LuciferLiu_DBA 1640

ASP.NET Core Web API发布部署IIS详细教程

安装 .NET Core 托管捆绑包(Hosting Bundle)在将 .NET Core 应用程序部署到 IIS 时是一个必要的步骤。Internet Information Services (IIS) 是一种灵活、安全且可管理的 Web 服务器,用于托管 Web 应用(包括 ASP.NET Core)。在生产环境中展示 Swagger 通常是不推荐的,因为它可能会暴露你的 API 文档,增加安全风险。因为发布后运行的环境属于。

专注于C#/.NET/.NET Core学习、工作、面试干货和实战教程分享。这里聚焦了大量的C#/.NET/.NET Core优质文章、开源项目、实用工具和学习、工作、面试心得。 4881

[网络安全提高篇] 一二九.Powershell恶意代码检测 (5)混淆和反混淆 [上]

前文介绍了如何利用MS Defender实现恶意样本家族批量标注。这篇文章将继续讲解Powershell恶意代码检测,主要包括PowerShell混淆与反混淆内容,首先结合Invoke-Obfuscation工具详细介绍PowerShell代码混淆方法,再结合PowerDecode工具阐述解混淆方法。该研究将为后续的恶意软件家族分类或溯源提供帮助。未完待续,基础性文章,希望您喜欢,且看且珍惜。

杨秀璋的专栏 1533

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

ASP.NET Core - 选项系统之选项配置

预定义的数据注解毕竟有限,在某些验证逻辑比较复杂的情况下,数据注解可能并不能完全满足我们的需求,我们可以通过 OptionsBuilder 类中的 Validate 方法传入一个委托来实现自己的验证逻辑。// 标题中不能包含特殊字符 if(options . Title . Contains("eval")) {// 验证失败 return false;} // 验证通过 return true;});

weixin_37648525的博客 1305

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

ASP.NET Core分布式项目实战

ASP.NET Core开发者成长路线图 老张视频教程:https://www.bilibili.com/video/av58096866/ asp.net core 官方文档 https://docs.microsoft.com/zh-cn/aspnet/core/getting-started/?view=aspnetcore-2.2&tabs=windows 杨旭B站教程:...

weixin_30532987的博客 1064

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

使用 ASP.NET Core 创建 RESTful API

我们需要定义 Product 模型来表示 API 中使用的产品对象。在 Models 文件夹下添加一个新的类 Product.cs。// 定义产品模型类,用于表示API中传输的产品数据set;} // 产品的唯一标识符set;} // 产品名称set;} // 产品价格。

hy_4377的博客 1524

.NET 7 与 ASP.NET Core 核心组件解析

ASP.NET Core 是一个高性能、跨平台的 Web 框架,用于构建现代化的 Web 应用和 API。它在 .NET 7 平台上得到了进一步的增强,继续提供无与伦比的灵活性和性能。ASP.NET Core 通过统一的编程模型,支持 Web 应用、API、微服务、实时应用等多种开发需求。

hy_4377的博客 1437

《ASP.NET Core编程自学与面试指南》最佳学习路线图(2020最新版)

ASP.NET Core跨平台。

西安极客联盟 1543

Linux中以单容器部署Nginx+ASP.NET Core

强烈推荐在生产环境中使用反向代理服务器转发请求到Kestrel Http服务器,本文将会实践将Nginx --->ASP.NET Core 部署架构容器化的过程。

这是一个web全栈开发的博客,取其精华去其糟粕,争取让大家一看就懂,一学就会,一用就成~ 1756

Asp.Net Core 第06局:中间件

总目录 前言 本文介绍Asp.Net Core 中间件。 环境 1.Visual Studio 2017 2.Asp.Net Core 2.2 开局 第一手:中间件概述 1.中间件:添加到应用管道用于处理处理请求和响应的组件。每个组件: - 可以选择是否将请求传递到管道中的下一个组件; - 可以在调用管道中的下...

weixin_30511107的博客 143

ASP.NET Core基础补充06

ASP.NET Core (wwwroot) 什么是ASP.NET Core中的wwwroot文件夹? 默认情况下,ASP.NET Core应用程序中的wwwroot文件夹被视为webroot文件夹,并且该文件夹或目录应位于根项目文件夹中。 在ASP.NET Core应用程序中,静态文件可以存储在webroot文件夹下的任何文件夹中,并且可以使用指向该根目录的相对路径进行访问。 添加wwwroot(webroot)文件夹 当使用Web和MVC模板创建ASP.NET Core Web应用程序时,默认情况下,该

Echo_Wish 664

.NET Core 环境配置与工具安装

NET Core 是一个开源、跨平台的开发框架,由微软主导开发。它允许开发人员构建高性能、可扩展的应用程序,支持 Windows、macOS 和 Linux 等多种操作系统。随着微服务架构和云原生应用的普及,.NET Core 已成为许多开发者的首选。通过上述步骤,您已经成功配置了 .NET Core 开发环境,并安装了所需的开发工具。无论您是在 Windows、macOS 还是 Linux 上开发,.NET Core 都能够为您提供一个强大而灵活的平台。

hy_4377的博客 3994
上一篇: .NetCore JWT token过期时间设置
下一篇: .NET Core开发实战(第9课:命令行配置提供程序)--学习笔记
.NET跨平台
博客等级 码龄15年 6066粉丝 738原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值