zoukankan      html  css  js  c++  java
  • aps.net cored 新概念

    Tag Helpers

    The EnvironmentTagHelper can be used to include different scripts in your views (for example, raw or minified) based on the runtime environment, such as Development, Staring, or Production:

    1 <environment names="Development">
    2     <script src="~/lib/jquery/dist/jquery.js"></script>
    3 </environment>
    4 <environment names="Staging,Production">
    5     <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"
    6             asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
    7             asp-fallback-test="window.jQuery">
    8     </script>
    9 </environment>

    formating

     By default MVC includes a JsonInputFormatter class for handling JSON data, but you can add additional formatters for handling XML and other custom formats.可以添加其它的formatting.例如:

    services.AddMvc()
           .AddXmlSerializerFormatters();或者
    services.AddMvc(options =>
    {
      options.OutputFormatters.Add(new XmlSerializerOutputFormatter());
    });
     

    Action可以返回一个对象,Controller actions can return POCOs (Plain Old CLR Objects), in which case ASP.NET MVC will automatically create an ObjectResult for you that wraps the object. 

    强制格式化返回数据:[Produces] filter

    [Produces("application/json")]
    public class AuthorsController

    在url中定义数据格式:

    1 [FormatFilter]
    2 public class ProductsController
    3 {
    4   [Route("[controller]/[action]/{id}.{format?}")]
    5   public Product GetById(int id)

    Response cache 

       

    The primary HTTP header used for caching is Cache-Control. The HTTP 1.1 specification details many options for this directive. Three common directives are:

    public
    Indicates that the response may be cached.
    private
            此种情况只能保存个人的缓存中,比如浏览器。
    Indicates the response is intended for a single user and must not be cached by a shared cache. The response could still be cached in a private cache (for instance, by the user’s browser).
    no-cache
    Indicates the response must not be used by a cache to satisfy any subsequent request (without successful revalidation with the origin server).
    本人全手工打造的dotnetcore webapi 框架,可实现快速开发。地址:https://github.com/ryansecret/WebApiCore.git。 1 采用DDD模式开发,充血模型 2 添加Dapper扩展,默认实现增删改查基本操作。利用AutoMapper 做实体转换,减少重复劳动。 3 依赖注入融合Autofac,仓储层和应用层自动注入 4 实现JWT验证 5 加入swagger 文档 6 单元测试添加了xunit,MyMvc 可以方便对webapi测试 7 数据库版本控制
  • 相关阅读:
    初学C++到底应该用什么工具比较合适——工具简析
    便携式办公套件LibreOffice Portable 4.0.1
    Hibernate和JPA之间的联系
    央视《家有妙招》整理版,共250招,值得永远收藏
    思科Vs华为:不可避免的对决
    Facebook手机刺激了谁?
    Facebook利用Home平台加速进军移动领域
    英特尔Haswell处理器已出货 预计6月推出
    苹果自建街景地图 或与谷歌针锋相对
    图片链接
  • 原文地址:https://www.cnblogs.com/ryansecreat/p/6000804.html
Copyright © 2011-2022 走看看