当前位置: 首页 > news >正文

单页站好做seo吗网络营销就业方向和前景

单页站好做seo吗,网络营销就业方向和前景,2021最火的新媒体营销案例,网站建设的seo策略基于 Controller 的 Web API ASP.NET Wep API 的请求架构 客户端发送Http请求,Contoller响应请求,并从数据库读取数据,序列化数据,然后通过 Http Response返回序列化的数据。 ControllerBase 类 Web API 的所有controllers 一般…

基于 Controller 的 Web API

ASP.NET Wep API 的请求架构

在这里插入图片描述
客户端发送Http请求,Contoller响应请求,并从数据库读取数据,序列化数据,然后通过 Http Response返回序列化的数据。

ControllerBase 类

Web API 的所有controllers 一般继承于 ControllerBase 类,而不是Controller 类。
因为 Controller 类也继承自ControllerBase 类,但是支持views,而API一般不需要这个功能。

ControllerBase 提供了很多处理Http Request 和 Response方法,比如返回201结果的CreatedAtAction(表示成功创建资源):

[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public ActionResult<Pet> Create(Pet pet)
{pet.Id = _petsInMemoryStore.Any() ? _petsInMemoryStore.Max(p => p.Id) + 1 : 1;_petsInMemoryStore.Add(pet);return CreatedAtAction(nameof(GetById), new { id = pet.Id }, pet);
}

其他一些主要方法:

  • Ok(),返回空的 http code 200
  • File(),返回文件和 http code 200,或者返回部分文件和 http code 206,或者不支持的Range和http code 416
  • PhysicalFile(),返回文件和 http code 200,或者返回部分文件和 http code 206,或者不支持的Range和http code 416
  • CreatedAtAction(),返回 http code 201
  • AcceptedAtAction(),返回 http code 202
  • NoContent(),返回 http code 204
  • Content(),返回具体结果,plain-text 格式
  • RedirectToActionPermanent(),返回 http code 301
  • RedirectToPagePermanent(),返回 http code 301
  • RedirectToPage(),返回 http code 302
  • RedirectToRoute(),返回 http code 302
  • RedirectToAction(),返回 http code 302
  • RedirectToActionPreserveMethod(),返回 http code 307
  • RedirectToPagePreserveMethod(),返回 http code 307
  • RedirectToActionPermanentPreserveMethod(),返回 http code 308
  • RedirectToPagePermanentPreserveMethod(),返回 http code 308
  • BadRequest(),返回 http code 400
  • Problem(),返回 http code 400
  • ValidationProblem(),返回 http code 400
  • Unauthorized(),返回 http code 401
  • Challenge(),返回 http code 401 或 403
  • Forbid() ,返回 http code 403
  • NotFound(),返回 http code 404
  • Conflict() ,返回 http code 409
  • UnprocessableEntity(),返回 http code 422
  • SignIn()
  • SignOut()
  • StatusCode(Int32)

重要的属性

  • ControllerContext
  • HttpContext,获取当前action的HttpContext
  • Url,IUrlHelper对象
  • Request,获取当前action的HttpRequest
  • Response,获取当前action的HttpResponse
  • RouteData,获取当前action的RouteData
  • User,获取当前action关联的User的ClaimsPrincipal

重要的Attributes

标识 Action的功能,包括:

  • [ApiController],表示这个Action为HTTP API responses服务。包括:
    • 必须要指定 [Route(“[controller]”)]
    • 自动验证model
    • 自动bind,包括[FromBody]等
    • 推断 multipart/form-data 的类型
  • [Area],指定Route
  • [Bind],
  • Route,指定Route
  • [Consumes],指定action 接收的数据类型,比如 [Consumes(“application/xml”)], [Consumes(“application/json”)],[Consumes(“application/x-www-form-urlencoded”)]
  • [Produces],指定action 返回的数据类型
  • [HttpGet],
  • [HttpDelete],
  • [HttpPost],
  • [HttpPut],
  • [HttpPatch],
  • [HttpOptions],
  • [HttpHead],
  • [NonAction],表示不是Action方法
  • [NonController],表示不是NonController方法
  • [FromBody],标识参数或属性可以绑定Body,比如:
    • public IActionResult Action3([FromBody] Product product, [FromBody] Order order)
  • [FromHeader],
  • [FromForm],

格式化Action 的返回结果

Action 不一定要返回某个特定类型,ASP.NET Core 支持任何对象类型。
Actions 可以忽略 HttpRequest的Header的Accept,返回自己想要的类型。
如果返回结果类型不是IActionResult,那么会被序列化。

ControllerBase.Ok 默认返回Json类型。
Http Reponse 的 content-type: application/json; charset=utf-8.

[HttpGet]
public IActionResult Get()=> Ok(todoItemStore.GetList());

而下面这个,Content-Type是text/plain。

[HttpGet("Version")]
public ContentResult GetVersion()=> Content("v1.0.0");

协商结果类型

当HttpRequest 指定了Header的Accept,而 Action返回的类型是JSON时,会发生结果协商
ASP.NET Core 默认支持的结果类型:

  • application/json
  • text/json
  • text/plain
  1. 当Header的Accept中指定了一个类型是Action支持的类型时,则返回这个类型。
  2. 如果Action不支持指定的类型,且设置了MvcOptions.ReturnHttpNotAcceptable为true,则返回406。
  3. 用Action中第一个formatter 返回结果。
  4. 当Header的Accept中没有指定类型时,用Action中第一个formatter 返回结果。
  5. 当Header的Accept中包含"/"时,会被忽略,由Action决定。
  6. 当请求来自于浏览器时,Accept 会被忽略,由Action决定,默认返回JSON。
  7. 当请求来自于浏览器时,Accept 会被忽略,如果Host设置了RespectBrowserAcceptHeader为true,则使用浏览器的header。

如果 Action返回的结果是复杂类型时,.NET 会创建一个 ObjectResult,封装结果,然后序列化成协商的结果类型。比如:

[HttpGet("{id:long}")]
public TodoItem? GetById(long id)=> _todoItemStore.GetById(id);

设置成XML结果类型

var builder = WebApplication.CreateBuilder(args);builder.Services.AddControllers().AddXmlSerializerFormatters();

设置成使用json.net的结果类型

默认的JSON格式是基于System.Text.Json的。

var builder = WebApplication.CreateBuilder(args);builder.Services.AddControllers().AddNewtonsoftJson();
http://www.mmbaike.com/news/96726.html

相关文章:

  • 百度推广会帮你做网站不网络排名优化软件
  • wordpress 默认头像 本地山东服务好的seo
  • 连接器零售在什么网站做太原seo网站管理
  • 红酒网站制作廊坊网站推广公司
  • 素材图片高清武汉seo优化服务
  • 辽宁金帝建设集团网站seo是什么意思的缩写
  • 登封建设局网站建一个app平台的费用多少
  • wordpress云落主题河北百度竞价优化
  • 网站建设的开发方式中国seo关键词优化工具
  • 网站建设与管理答案军事新闻头条最新消息
  • 盐城网站优化工作室友情链接代码美化
  • python做网站性能兰州疫情最新情况
  • 外贸英文网站建设如何做好线上营销
  • 做网站用什么后缀格式做好seo排名是什么
  • 万网博通迈步者seo
  • 分类目录网站大全做seo怎样在浏览器上找网站
  • 兰考县红庙关东村做网站的郑州优化公司有哪些
  • 做期货看什么网站的资讯少儿编程培训机构排名前十
  • 泉州手机端建站模板凡科建站多少钱
  • 做网站的登陆功能珠海企业网站建设
  • 做静态网站步骤seo是如何优化
  • 如何做网站seo网络营销与策划
  • 自己做购物网站需要什么广告网站留电话
  • 网站建设公司怎么做业务南宁seo计费管理
  • 做网站需要做什么搜索引擎营销优化的方法
  • 网站备案注销 万网搜索引擎排名
  • 中山网站优化最有效的免费推广方法
  • 产品销售网站模块如何设计国际新闻头条今日国际大事
  • uehtml 网站源码外贸平台有哪些
  • 湛江模板建站哪家好中国免费网站服务器主机域名