ETag的语法?

时间:2011-07-16 18:02:37

标签: http http-headers etag

Redbot报告我的网页标题无效:

  

ETag标头的语法无效。

我的标题设置为:

ETag: 4ae413bd

为什么无效?

ETag的语法是什么?

5 个答案:

答案 0 :(得分:29)

试试ETag: "4ae413bd"。 ETag的值必须遵循ABNF形式:

  entity-tag = [ weak ] opaque-tag
  weak       = "W/"
  opaque-tag = quoted-string

  quoted-string  = ( <"> *(qdtext | quoted-pair ) <"> )
  qdtext         = <any TEXT except <">>
  quoted-pair    = "\" CHAR
  CHAR           = <any US-ASCII character (octets 0 - 127)>
  TEXT           = <any OCTET except CTLs, but including LWS>
  OCTET          = <any 8-bit sequence of data>
  LWS            = [CRLF] 1*( SP | HT )
  CTL            = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
  CRLF           = CR LF
  CR             = <US-ASCII CR, carriage return (13)>
  LF             = <US-ASCII LF, linefeed (10)>
  SP             = <US-ASCII SP, space (32)>
  HT             = <US-ASCII HT, horizontal-tab (9)>

,在常规正则表达式中基本为([wW]/)?"([^"]|\\")*"

请注意,"\""/"都是etags的有效值。

参考文献:section-14.19section-3.11section-2.2

答案 1 :(得分:11)

正如Arnaud所说,请确保您已引用该值。

替换

new EntityTagHeaderValue("0");

new EntityTagHeaderValue("\"0\"");

答案 2 :(得分:6)

“ETag是由Web服务器分配给在URL处找到的资源的特定版本的不透明标识符”。这意味着它几乎可以是任何东西。

问题可能是语法,使用:

ETag: "4ae413bd"

答案 3 :(得分:0)

如果您是由于我下面写的那种堆栈跟踪而到达这里的,请确保您取消选中Visual Studio中抛出此错误的选项:uncheck this

Conversion> [13:31:10 ERR] Connection id "0HLJ153E20LDJ", Request id "0HLJ153E20LDJ:00000003": An unhandled exception was thrown by the application.
Conversion> System.ObjectDisposedException: The response has been aborted due to an unhandled application exception. ---> System.FormatException: Invalid ETag name
Conversion>    at Microsoft.Net.Http.Headers.EntityTagHeaderValue..ctor(StringSegment tag, Boolean isWeak)
Conversion>    at Microsoft.Net.Http.Headers.EntityTagHeaderValue..ctor(StringSegment tag)
Conversion>    at Microsoft.VisualStudio.Web.BrowserLink.BrowserLinkMiddleWareUtil.AddToETag(ResponseHeaders responseHeader, Int32 port)
Conversion>    at Microsoft.VisualStudio.Web.BrowserLink.BrowserLinkMiddleware.<>c__DisplayClass7_0.<ExecuteWithFilter>b__0()
Conversion>    at Microsoft.AspNetCore.Http.HttpResponse.<>c.<.cctor>b__30_0(Object callback)
Conversion>    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.FireOnStartingMayAwait(Stack`1 onStarting)
Conversion>    --- End of inner exception stack trace ---
Conversion>    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ThrowResponseAbortedException()
Conversion>    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.InitializeResponseAsync(Int32 firstWriteByteCount)
Conversion>    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.WriteAsync(ReadOnlyMemory`1 data, CancellationToken cancellationToken)
Conversion>    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
Conversion>    at System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count)
Conversion>    at Microsoft.VisualStudio.Web.BrowserLink.ScriptInjectionFilterStream.<>c__DisplayClass37_0.<<CreateResponseHandler>b__0>d.MoveNext()
Conversion> --- End of stack trace from previous location where exception was thrown ---
Conversion>    at Microsoft.VisualStudio.Web.BrowserLink.SocketReader.ReadBytesIntoResponseHandler(Int64 totalBytesToRead, ResponseHandler handler, CancellationToken cancellationToken)
Conversion>    at Microsoft.VisualStudio.Web.BrowserLink.HttpSocketAdapter.ResponseReader.ReadBytesIntoResponse(Int64 bytesToRead)
Conversion>    at Microsoft.VisualStudio.Web.BrowserLink.HttpSocketAdapter.ResponseReader.ReadChunkedContent()
Conversion>    at Microsoft.VisualStudio.Web.BrowserLink.HttpSocketAdapter.ResponseReader.ReadResponse()
Conversion>    at Microsoft.VisualStudio.Web.BrowserLink.DelayConnectingHttpSocketAdapter.Microsoft.VisualStudio.Web.BrowserLink.IHttpSocketAdapter.WaitForResponseComplete()
Conversion>    at Microsoft.VisualStudio.Web.BrowserLink.ScriptInjectionFilterStream.WaitForFilterComplete()
Conversion>    at Microsoft.VisualStudio.Web.BrowserLink.BrowserLinkMiddleware.ExecuteWithFilter(IHttpSocketAdapter injectScriptSocket, String requestId, HttpContext httpContext)
Conversion>    at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Conversion>    at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Conversion>    at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext)
Conversion>    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

答案 4 :(得分:0)

答案:“启用浏览器链接” 是有关错误的问题的答案:

  

Microsoft.AspNetCore.Server.Kestrel:错误:连接ID为“”,请求   id“”:应用程序引发了未处理的异常。

我要感谢DevNull,因为它解决了我的问题“红est错误500”