• <legend id='SeGJB'><style id='SeGJB'><dir id='SeGJB'><q id='SeGJB'></q></dir></style></legend>
      <i id='SeGJB'><tr id='SeGJB'><dt id='SeGJB'><q id='SeGJB'><span id='SeGJB'><b id='SeGJB'><form id='SeGJB'><ins id='SeGJB'></ins><ul id='SeGJB'></ul><sub id='SeGJB'></sub></form><legend id='SeGJB'></legend><bdo id='SeGJB'><pre id='SeGJB'><center id='SeGJB'></center></pre></bdo></b><th id='SeGJB'></th></span></q></dt></tr></i><div id='SeGJB'><tfoot id='SeGJB'></tfoot><dl id='SeGJB'><fieldset id='SeGJB'></fieldset></dl></div>
        <bdo id='SeGJB'></bdo><ul id='SeGJB'></ul>

      <tfoot id='SeGJB'></tfoot>

        <small id='SeGJB'></small><noframes id='SeGJB'>

      1. ASP.NET 5 中所有类型的 http 标头都去了哪里?

        Where all types for http headers gone in ASP.NET 5?(ASP.NET 5 中所有类型的 http 标头都去了哪里?)

        <small id='gJdqC'></small><noframes id='gJdqC'>

            <i id='gJdqC'><tr id='gJdqC'><dt id='gJdqC'><q id='gJdqC'><span id='gJdqC'><b id='gJdqC'><form id='gJdqC'><ins id='gJdqC'></ins><ul id='gJdqC'></ul><sub id='gJdqC'></sub></form><legend id='gJdqC'></legend><bdo id='gJdqC'><pre id='gJdqC'><center id='gJdqC'></center></pre></bdo></b><th id='gJdqC'></th></span></q></dt></tr></i><div id='gJdqC'><tfoot id='gJdqC'></tfoot><dl id='gJdqC'><fieldset id='gJdqC'></fieldset></dl></div>
            <tfoot id='gJdqC'></tfoot>

            <legend id='gJdqC'><style id='gJdqC'><dir id='gJdqC'><q id='gJdqC'></q></dir></style></legend>
                <bdo id='gJdqC'></bdo><ul id='gJdqC'></ul>
                  <tbody id='gJdqC'></tbody>

                • 本文介绍了ASP.NET 5 中所有类型的 http 标头都去了哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  以前,在 WebApi(在 .NET 4.x 上)中,我们可以通过类型化接口处理请求和响应的标头(请参阅 HttpRequestMessage.Headers/HttpResponseMessage.Headers).现在,在 ASP.NET 5 中,我们有 HttpRequestHttpResponse 以及类型为 IHeaderDictionary 的 Headers 属性.但它只是一个无类型的字典.

                  Previously, in WebApi (on .NET 4.x) we could work with headers of both the request and the response via typed interfaces (see HttpRequestMessage.Headers/HttpResponseMessage.Headers). Now, in ASP.NET 5 we have HttpRequest and HttpResponse with Headers property of type IHeaderDictionary. But it's just an untyped Dictionary.

                  下面我举了一个例子,类型化访问可以返回一个微调的 http-response.需要创建一个 HttpResponseMessage 并填充其 Headers 集合(顺便说一句).

                  Below I put an example with typed accessing could return a fine-tuned http-response. It's needed to create a HttpResponseMessage and fill its Headers collection (which was typed btw).

                  HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
                  response.Content = new StringContent(manifestContent);
                  response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/cache-manifest");
                  response.Headers.CacheControl = new CacheControlHeaderValue {NoCache = true, Public = true};
                  response.Headers.ETag = new EntityTagHeaderValue(""" + etag + """);
                  

                  推荐答案

                  如果为Microsoft.AspNetCore.Http添加using语句,HttpRequest 和 HttpResponseGetTypedHeaders,这应该会为您提供所需的类型安全性.

                  If you add the using statement for Microsoft.AspNetCore.Http, there are extension methods on the HttpRequest and HttpResponse to GetTypedHeaders, which should give you the type safety that you want.

                  在示例中,我还添加了 Microsoft.Net.Http.Headers 的 using 语句,只是为了清理它.

                  In the example, I also added the using statement for Microsoft.Net.Http.Headers, just to clean it up.

                  var headers = Response.GetTypedHeaders();
                  headers.ContentType = new MediaTypeHeaderValue("text/cache-manifest");
                  headers.CacheControl = new CacheControlHeaderValue { NoCache = true, Public = true };
                  headers.ETag = new EntityTagHeaderValue(""" + etag + """);
                  

                  来源:aspnet/HttpAbstractions onGithub

                  这篇关于ASP.NET 5 中所有类型的 http 标头都去了哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
                      <legend id='IejQp'><style id='IejQp'><dir id='IejQp'><q id='IejQp'></q></dir></style></legend>
                    • <small id='IejQp'></small><noframes id='IejQp'>

                      <tfoot id='IejQp'></tfoot>

                        <i id='IejQp'><tr id='IejQp'><dt id='IejQp'><q id='IejQp'><span id='IejQp'><b id='IejQp'><form id='IejQp'><ins id='IejQp'></ins><ul id='IejQp'></ul><sub id='IejQp'></sub></form><legend id='IejQp'></legend><bdo id='IejQp'><pre id='IejQp'><center id='IejQp'></center></pre></bdo></b><th id='IejQp'></th></span></q></dt></tr></i><div id='IejQp'><tfoot id='IejQp'></tfoot><dl id='IejQp'><fieldset id='IejQp'></fieldset></dl></div>
                          <bdo id='IejQp'></bdo><ul id='IejQp'></ul>
                              <tbody id='IejQp'></tbody>