Sunday, 2 July 2017

How to pass HttpContext.Current to function?

ou can either pass the context into the function or use HttpContext.Current to retrieve the current context.

Pass it in

public static List<SellsLive> SearchFunc(SellsLiveSearch Per, HttpContext context)
{
    context.Response.SetCookie(cookie);
}
And call it like this:
SearchFunc(Per, this.HttpContext);

Get Current context

public static List<SellsLive> SearchFunc(SellsLiveSearch Per)
{
    HttpContext context = HttpContext.Current;
    context.Response.SetCookie(cookie);
    //etc
}
Of course, this way will only work if the function is running on the correct thread.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.