Вопрос

We are working on a asp.net site with .net framework 4.0. and we tried to incorporate output cache for it.
But unfortunately it is not worked. Later we found removing Microsoft security update KB2656351 will solve the problem.
I want to know whethere is there any other way to do this without removing the update.

Это было полезно?

Решение

This issue is there only when you install the above mention update and there is a cookies on the response. No matter if cookies contains in request. Found a workaround to fix this problem. I have created a custom HTTPModule and copy all available cookies from the response(including newly added cookies) to the Context.Items. then clear all the cookies available in the response.

In the next step, read the object stored in the Context.items and add back to the response. So when output cache provider is trying to cache the page there is no cookies in the response. so it works as usual. and then adding the cookies back.

    public void Init(HttpApplication context)
    {
        context.PostReleaseRequestState += new EventHandler(OnPostReleaseRequestState);
        context.PostUpdateRequestCache += new EventHandler(OnPostUpdateRequestCache);
    }

    public void OnPostReleaseRequestState(Object source, EventArgs e)
    {
        HttpApplication application = (HttpApplication)source;
        HttpContext context = application.Context;
        HttpCookieCollection cookieCollection = new HttpCookieCollection();
        foreach (string item in context.Response.Cookies)
        {
            HttpCookie tempCookie = context.Response.Cookies[item];

            HttpCookie cookie = new HttpCookie(tempCookie.Name) { Value = tempCookie.Value, Expires = tempCookie.Expires, Domain = tempCookie.Domain, Path = tempCookie.Path };
            cookieCollection.Add(cookie);
        }
        context.Items["cookieCollection"] = cookieCollection;
        context.Response.Cookies.Clear();
    }

    public void OnPostUpdateRequestCache(Object source, EventArgs e)
    {
        HttpApplication application = (HttpApplication)source;
        HttpContext context = application.Context;
        HttpCookieCollection cookieCollection = (HttpCookieCollection)context.Items["cookieCollection"];
        if (cookieCollection != null)
        {
            foreach (string item in cookieCollection)
            {
                context.Response.Cookies.Add(cookieCollection[item]);
            }
        }
    }

Другие советы

There was some problem reported here for this update, and repairing .net Framework 4 worked. It might be because of the corruption of .net Framework or the order in which framework and IIS is installed, which de-registers ASP.Net, so we need to register ASP.Net specifically, which sometimes causes these issue.

I would suggest to repair .Net framework, and the registering ASP.Net separately to see if that works.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top