GVKun编程网logo

asp.net-mvc – Azure托管的ASP.NET MVC网站删除与客户端缓存相关的HTTP标头

16

最近很多小伙伴都在问asp.net-mvc–Azure托管的ASP.NETMVC网站删除与客户端缓存相关的HTTP标头这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展ASP.NET

最近很多小伙伴都在问asp.net-mvc – Azure托管的ASP.NET MVC网站删除与客户端缓存相关的HTTP标头这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 27. CICD Azure DevOps、ASP.NET MVC 3:在发送HTTP标头后,服务器无法追加标头、asp.net – ASP MVC – 默认的HTTP标头有任何常量吗?、asp.net-mvc – 404 Asp.Net中的Http错误处理程序MVC(RC 5)等相关知识,下面开始了哦!

本文目录一览:

asp.net-mvc – Azure托管的ASP.NET MVC网站删除与客户端缓存相关的HTTP标头

asp.net-mvc – Azure托管的ASP.NET MVC网站删除与客户端缓存相关的HTTP标头

我们最近已经开始将我们的一些ASP.NET MVC网站从我们自己的托管环境迁移到Azure.我们看到的一个问题是客户端缓存在传递动态创建的内容时似乎不能正常工作.具体来说,删除代码中添加到HTTP响应的缓存相关头.

例如,在旧环境中返回以下标题,以便向客户建议内容可能被缓存:

Cache-Control:          public,max-age=31533144
Content-disposition:    attachment; filename=picture.png
Content-Length:         64326
Content-Type:           image/png
Date:                   Tue,23 Jul 2013 15:44:57 GMT
Etag:                   "845D3DD630A7AEF5B68EA7A09B670A4D"
Expires:                Fri,23 Aug 2013 14:57:22 GMT
Last-Modified:          Tue,23 Jul 2013 14:57:22 GMT
Server:                 Microsoft-IIS/7.5

但是在Azure中,会返回以下标题:

Content-disposition:    attachment; filename=picture.png
Content-Length:         64326
Content-Type:           image/png
Date:                   Tue,23 Jul 2013 15:44:57 GMT
Server:                 Microsoft-IIS/8.0
X-Powered-By:           ARR/2.5,ASP.NET

如您所见,Cache-Control,Etag,Expires和Last-Modified标题已被删除.

我已经看到关于静态内容的缓存的一些建议,但我不认为这些将有助于这种情况.是否是Azure CDN的结构以这种方式阻止缓存的情况?应该使用Azure blob吗?是否有可能被忽视的基本配置更改?

提前致谢

解决方法

X-Powered-By:           ARR/2.5,ASP.NET

ARR代表应用请求路由.

转到inetmgr UI并单击服务器名称,您将找到选项“应用程序请求路由缓存”.

您会看到“缓存配置”,检查那里的选项.此外,请检查“缓存控制规则”.点击“添加规则…”,然后尝试玩.

ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 27. CICD Azure DevOps

ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 27. CICD Azure DevOps

VSTS做持续集成


后来改名叫做Azure Deveps



https://azure.microsoft.com/zh-cn/services/devops/


这是中文的地址


创建一个项目

名称、描述、私有的项目

然后点击创建。对个人用户完全免费,个人团队不超过5个人都可以使用

相当于项目的首页

源码放在这里

复制git的地址

git init
然后把复制的两句话粘贴进去


这样源码 就上传上来了。

项目工行迁进来 看不出来啥效果。看一个已经存在的项目

找到一个文件之后,就可以看到文件的代码


修改的历史

点击历史可以对当前版本进行比较


开发管理



可以点开查看详情:



自定义查询,例如查询分配给我的工作


今天主要讲整理


可以做构建和发布

cl就是持续集成的意思

支持多种语言平台,除了.net core还支持java等





基本上都是默认的

可以输入关键字搜索模板,点击Apply


模板里面有这些步骤

有任何的代码提交到Mater后,就会开始自动构建




直接默认,然后点击Save即可

Releases










点击Add后就是这个效果


点击闪电的符号






选择订阅

然后再点击授权;








修改下本地的代码

代码提交一下  然后push

代码提交了就进行了一次build




状态变成对号了


在看Release,邮件也收到了。

点进去

点进去


看到失败了









更多的参考语雀:

https://www.yuque.com/yuejiangliu/dotnet/pu6igu


 

ASP.NET MVC 3:在发送HTTP标头后,服务器无法追加标头

ASP.NET MVC 3:在发送HTTP标头后,服务器无法追加标头

我们正忙着使用3.5框架将ASP.NET MVC 2应用程序升级到在4.0框架上运行的ASP.NET MVC 3应用程序.

有一个页面在使用浏览器后退按钮接近时抛出异常.为了支持此页面上的浏览器后退按钮,我们实现了一个系统,该系统在返回页面时会重新请求该页面的结果.我没有明确的迹象表明在哪里寻找问题,因为我总是只找到错误

Server cannot append header after HTTP headers have been sent.

使用堆栈跟踪

at System.Web.HttpResponse.AppendHeader(String name,String value)
at System.Web.HttpResponseWrapper.AppendHeader(String name,String value)
at System.Web.Mvc.MvcHandler.AddVersionHeader(HttpContextBase httpContext)
at System.Web.Mvc.MvcHandler.ProcessRequestinit(HttpContextBase httpContext,IController& controller,IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.<>c__displayClass6.<BeginProcessRequest>b__2()
at System.Web.Mvc.SecurityUtil.<>c__displayClassb`1.<ProcessInApplicationTrust>b__a()
at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust[TResult](Func`1 func)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback callback,Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext,Object state)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context,AsyncCallback cb,Object exTradata)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)

为什么HTTP标头已经发送了?

先感谢您,
IvanL

编辑:
我正在寻找我在寻找此问题时获得的新信息和洞察力. Asynch Controller提到的其中一个答案让我感到疑惑.当我发现我必须为旧的MVC2方法更改以下内容时:

[HttpPost,ValidateInput(false)]
public void SearchResultOverview(SearchResultviewmodel model,string searchUrl)
{
    if (!string.IsNullOrEmpty(searchUrl))
    {
        searchUrl = searchUrl.Replace("SearchPartial","SearchPartialInternal");

        //NOTE MVC 3
        HttpContext.Server.TransferRequest(searchUrl,true);

        //NOTE MVC 2
        //System.Web.HttpContext.Current.RewritePath(searchUrl,false);

        //IHttpHandler httpHandler = new MvcHttpHandler();
        //// Process request
        //httpHandler.ProcessRequest(System.Web.HttpContext.Current);
    }
}

当我查找TransferRequest方法时,我发现它执行指定URL的异步执行并保留查询字符串参数. (http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.transferrequest.aspx)

还有一个Exception在我发布的异常之前被抛出(我只是错过了它,因为我迟到了).这个例外是:

The SessionStateTempDataProvider class requires session state to be enabled.
   at System.Web.Mvc.SessionStateTempDataProvider.SaveTempData(ControllerContext controllerContext,IDictionary`2 values)
   at System.Web.Mvc.TempDataDictionary.Save(ControllerContext controllerContext,ITempDataProvider tempDataProvider)
   at System.Web.Mvc.Controller.PossiblySaveTempData()
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__displayClass6.<>c__displayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__displayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__displayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.<>c__displayClasse.<EndProcessRequest>b__d()
   at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)

那我该怎么做呢?

解决方法

如果在页面上关闭了缓冲,则会发生这种情况.缓冲意味着asp.net在发送响应之前等待整个请求完成.这意味着可以随时更改标题.当缓冲关闭时,输出将在生成时发送到客户端.因此,您无法随意更改标头,因为它们已经发送过.

从您的堆栈跟踪,它似乎是一个异步控制器&我想知道这是否与它有关.我只是猜测你发布了什么.

更新

更正,异步提及实际上是框架代码&与您的代码无关.但是从上面的代码中,SearchResultOverview是否在控制器上执行了操作?如果是这样,那么使用你用来转移执行的方法是我认为你的问题的原因.

它导致2个mvchandlers执行&他们互相干扰.路由是重定向请求的更好方法.

asp.net – ASP MVC – 默认的HTTP标头有任何常量吗?

asp.net – ASP MVC – 默认的HTTP标头有任何常量吗?

基本上,同样的问题我要求默认的内容类型,但这次为标题:有微软创建了一个类的标准HTTP头名称的常量,或者我必须自己写?

谢谢卢克

解决方法

请求标题
/// <summary>
/// Contains the standard set of headers applicable to an HTTP request.
/// </summary>
public static class HttpRequestHeaders
{
    ///<summary>Content-Types that are acceptable</summary>
    public const string Accept = "Accept";
    ///<summary>Character sets that are acceptable</summary>
    public const string AcceptCharset = "Accept-Charset";
    ///<summary>Acceptable encodings. SeeHTTP compression.</summary>
    public const string AcceptEncoding = "Accept-Encoding";
    ///<summary>Acceptable languages for response</summary>
    public const string AcceptLanguage = "Accept-Language";
    ///<summary>Acceptable version in time</summary>
    public const string AcceptDatetime = "Accept-Datetime";
    ///<summary>Authentication credentials for HTTP authentication</summary>
    public const string Authorization = "Authorization";
    ///<summary>Used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain</summary>
    public const string CacheControl = "Cache-Control";
    ///<summary>What type of connection the user-agent would prefer</summary>
    public const string Connection = "Connection";
    ///<summary>an HTTP cookie prevIoUsly sent by the server withSet-Cookie(below)</summary>
    public const string Cookie = "Cookie";
    ///<summary>The length of the request body inoctets(8-bit bytes)</summary>
    public const string ContentLength = "Content-Length";
    ///<summary>ABase64-encoded binaryMD5sum of the content of the request body</summary>
    public const string ContentMD5 = "Content-MD5";
    ///<summary>TheMIME typeof the body of the request (used with POST and PUT requests)</summary>
    public const string ContentType = "Content-Type";
    ///<summary>The date and time that the message was sent</summary>
    public const string Date = "Date";
    ///<summary>Indicates that particular server behaviors are required by the client</summary>
    public const string Expect = "Expect";
    ///<summary>The email address of the user making the request</summary>
    public const string From = "From";
    ///<summary>The domain name of the server (forvirtual hosting),mandatory since HTTP/1.1. Although domain name are specified as case-insensitive[5][6],it is not specified whether the contents of the Host field should be interpreted in a case-insensitive manner[7]and in practice some implementations of virtual hosting interpret the contents of the Host field in a case-sensitive manner.[citation needed]</summary>
    public const string Host = "Host";
    ///<summary>Only perform the action if the client supplied entity matches the same entity on the server. This is mainly for methods like PUT to only update a resource if it has not been modified since the user last updated it.</summary>
    public const string IfMatch = "If-Match";
    ///<summary>Allows a304 Not Modifiedto be returned if content is unchanged</summary>
    public const string IfModifiedSince = "If-Modified-Since";
    ///<summary>Allows a304 Not Modifiedto be returned if content is unchanged,seeHTTP ETag</summary>
    public const string IfNoneMatch = "if-none-match";
    ///<summary>If the entity is unchanged,send me the part(s) that I am missing; otherwise,send me the entire new entity</summary>
    public const string IfRange = "If-Range";
    ///<summary>Only send the response if the entity has not been modified since a specific time.</summary>
    public const string IfUnmodifiedSince = "If-Unmodified-Since";
    ///<summary>Limit the number of times the message can be forwarded through proxies or gateways.</summary>
    public const string MaxForwards = "Max-Forwards";
    ///<summary>Implementation-specific headers that may have varIoUs effects anywhere along the request-response chain.</summary>
    public const string Pragma = "Pragma";
    ///<summary>Authorization credentials for connecting to a proxy.</summary>
    public const string ProxyAuthorization = "Proxy-Authorization";
    ///<summary>Request only part of an entity. Bytes are numbered from 0.</summary>
    public const string Range = "Range";
    ///<summary>This is the address of the prevIoUs web page from which a link to the currently requested page was followed. (The word “referrer” is misspelled in the RFC as well as in most implementations.)</summary>
    public const string Referersic = "Referer[sic]";
    ///<summary>The transfer encodings the user agent is willing to accept: the same values as for the response header transfer-encoding can be used,plus the trailers value (related to the chunked transfer method) to notify the server it expects to receive additional headers (the trailers) after the last,zero-sized,chunk.</summary>
    public const string TE = "TE";
    ///<summary>Ask the server to upgrade to another protocol.</summary>
    public const string Upgrade = "Upgrade";
    ///<summary>Theuser agent stringof the user agent</summary>
    public const string UserAgent = "User-Agent";
    ///<summary>Informs the server of proxies through which the request was sent.</summary>
    public const string Via = "Via";
    ///<summary>A general warning about possible problems with the entity body.</summary>
    public const string Warning = "Warning";

}

回应标题

/// <summary>
/// Contains the standard set of headers applicable to an HTTP response.
/// </summary>
public static class HttpResponseHeaders
{
    ///<summary>What partial content range types this server supports</summary>
    public const string AcceptRanges = "Accept-Ranges";
    ///<summary>The age the object has been in aproxy cachein seconds</summary>
    public const string Age = "Age";
    ///<summary>Valid actions for a specified resource. To be used for a405 Method not allowed</summary>
    public const string Allow = "Allow";
    ///<summary>Tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds</summary>
    public const string CacheControl = "Cache-Control";
    ///<summary>Options that are desired for the connection[17]</summary>
    public const string Connection = "Connection";
    ///<summary>The type of encoding used on the data. SeeHTTP compression.</summary>
    public const string ContentEncoding = "content-encoding";
    ///<summary>The language the content is in</summary>
    public const string ContentLanguage = "Content-Language";
    ///<summary>The length of the response body inoctets(8-bit bytes)</summary>
    public const string ContentLength = "Content-Length";
    ///<summary>An alternate location for the returned data</summary>
    public const string ContentLocation = "Content-Location";
    ///<summary>ABase64-encoded binaryMD5sum of the content of the response</summary>
    public const string ContentMD5 = "Content-MD5";
    ///<summary>An opportunity to raise a File Download dialogue Box for a kNown MIME type with binary format or suggest a filename for dynamic content. Quotes are necessary with special characters.</summary>
    public const string Contentdisposition = "Content-disposition";
    ///<summary>Where in a full body message this partial message belongs</summary>
    public const string ContentRange = "Content-Range";
    ///<summary>TheMIME typeof this content</summary>
    public const string ContentType = "Content-Type";
    ///<summary>The date and time that the message was sent</summary>
    public const string Date = "Date";
    ///<summary>An identifier for a specific version of a resource,often amessage digest</summary>
    public const string ETag = "ETag";
    ///<summary>Gives the date/time after which the response is considered stale</summary>
    public const string Expires = "Expires";
    ///<summary>The last modified date for the requested object,inRFC 2822format</summary>
    public const string LastModified = "Last-Modified";
    ///<summary>Used to express a typed relationship with another resource,where the relation type is defined byRFC 5988</summary>
    public const string Link = "Link";
    ///<summary>Used in redirection,or when a new resource has been created.</summary>
    public const string Location = "Location";
    ///<summary>This header is supposed to setP3Ppolicy,in the form ofP3P:CP=your_compact_policy. However,P3P did not take off,[22]most browsers have never fully implemented it,a lot of websites set this header with fake policy text,that was enough to fool browsers the existence of P3P policy and grant permissions forthird party cookies.</summary>
    public const string P3P = "P3P";
    ///<summary>Implementation-specific headers that may have varIoUs effects anywhere along the request-response chain.</summary>
    public const string Pragma = "Pragma";
    ///<summary>Request authentication to access the proxy.</summary>
    public const string ProxyAuthenticate = "Proxy-Authenticate";
    ///<summary>Used in redirection,or when a new resource has been created. This refresh redirects after 5 seconds. This is a proprietary,non-standard header extension introduced by netscape and supported by most web browsers.</summary>
    public const string Refresh = "Refresh";
    ///<summary>If an entity is temporarily unavailable,this instructs the client to try again after a specified period of time (seconds).</summary>
    public const string RetryAfter = "Retry-After";
    ///<summary>A name for the server</summary>
    public const string Server = "Server";
    ///<summary>anHTTP cookie</summary>
    public const string SetCookie = "Set-Cookie";
    ///<summary>A HSTS Policy informing the HTTP client how long to cache the HTTPS only policy and whether this applies to subdomains.</summary>
    public const string StrictTransportSecurity = "Strict-Transport-Security";
    ///<summary>The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded withchunked transfer-coding.</summary>
    public const string Trailer = "Trailer";
    ///<summary>The form of encoding used to safely transfer the entity to the user.Currently defined methodsare:chunked,compress,deflate,gzip,identity.</summary>
    public const string TransferEncoding = "transfer-encoding";
    ///<summary>Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server.</summary>
    public const string vary = "vary";
    ///<summary>Informs the client of proxies through which the response was sent.</summary>
    public const string Via = "Via";
    ///<summary>A general warning about possible problems with the entity body.</summary>
    public const string Warning = "Warning";
    ///<summary>Indicates the authentication scheme that should be used to access the requested entity.</summary>
    public const string WWWAuthenticate = "WWW-Authenticate";

}

asp.net-mvc – 404 Asp.Net中的Http错误处理程序MVC(RC 5)

asp.net-mvc – 404 Asp.Net中的Http错误处理程序MVC(RC 5)

如果没有框架抛出异常500错误代码,我如何处理404错误?

解决方法

http://jason.whitehorn.ws/2008/06/17/Friendly-404-Errors-In-ASPNET-MVC.aspx给出以下说明:

添加通配符路由规则作为最终规则:

routes.MapRoute("Error","{*url}",new { controller = "Error",action = "Http404" });

任何与其他规则不匹配的请求都会路由到错误控制器的Http404操作,您还需要配置它:

public ActionResult Http404(string url) {
    Response.StatusCode = 404;
    ViewData["url"] = url;
    return View();
}

我们今天的关于asp.net-mvc – Azure托管的ASP.NET MVC网站删除与客户端缓存相关的HTTP标头的分享已经告一段落,感谢您的关注,如果您想了解更多关于ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 27. CICD Azure DevOps、ASP.NET MVC 3:在发送HTTP标头后,服务器无法追加标头、asp.net – ASP MVC – 默认的HTTP标头有任何常量吗?、asp.net-mvc – 404 Asp.Net中的Http错误处理程序MVC(RC 5)的相关信息,请在本站查询。

本文标签: