Skip to content

Commit

Permalink
Try to fix Glimpse#632
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlbyk committed Nov 13, 2013
1 parent 53b0104 commit 30a9f93
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions source/Glimpse.AspNet/AspNetFrameworkProvider.cs
Expand Up @@ -48,11 +48,16 @@ internal HttpContextBase Context
private static HttpContextBase GetOrCaptureLogicalContext()
{
if (HttpContext.Current == null)
return CallContext.LogicalGetData("Glimpse.HttpContext") as HttpContextBase;

var wrapper = new HttpContextWrapper(HttpContext.Current);
CallContext.LogicalSetData("Glimpse.HttpContext", wrapper);
return wrapper;
{
var wrapper = CallContext.LogicalGetData("Glimpse.HttpContext") as SerializableHttpContextWrapper;
return wrapper == null ? null : wrapper.Context;
}
else
{
var wrapper = new SerializableHttpContextWrapper();
CallContext.LogicalSetData("Glimpse.HttpContext", wrapper);
return wrapper.Context;
}
}

private ILogger Logger { get; set; }
Expand Down Expand Up @@ -134,4 +139,24 @@ public void WriteHttpResponse(string content)
}
}
}

[Serializable]
public class SerializableHttpContextWrapper
{
[NonSerialized]
private HttpContextBase current;

public SerializableHttpContextWrapper()
{
if (Context == null)
{
throw new InvalidOperationException("Missing HttpContext");
}
}

public HttpContextBase Context
{
get { return current ?? (current = new HttpContextWrapper(HttpContext.Current)); }
}
}
}

0 comments on commit 30a9f93

Please sign in to comment.