如何在Event Handler中获取HttpContext [英] How to obtain the HttpContext in Event Handler
本文介绍了如何在Event Handler中获取HttpContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在 MOSS 的文档库中的事件处理程序中获取 HTTPContext,但我所拥有的只是 HTTPContext.Current 的空值,我对 List 执行相同的操作并返回 HTTPContext.有没有办法获取文档库中的 HTTPContext 来访问 HTTPContext.Request 方法?
I’m trying to obtain the HTTPContext within an Event Handler in a Document Library in MOSS, but all I have is a null value of the HTTPContext.Current, I do the same thing on a List and the HTTPContext is returned. There is a way to obtain the HTTPContext in Document Libraries to access the HTTPContext.Request method?
感谢您的帮助
代码如下:
public class TestContextListItemEventReceiver : SPItemEventReceiver
{
HttpContext current;
static object obj;
/// <summary>
/// Initializes a new instance of the Microsoft.SharePoint.SPItemEventReceiver class.
/// </summary>
public TestContextListItemEventReceiver()
{
current = HttpContext.Current;
}
public override void ItemAdding(SPItemEventProperties properties)
{
obj = current;
}
}
推荐答案
步骤 1声明:
private HttpContext currentContext;
static HttpContext _stCurrentContext;
第 2 步
currentContext = HttpContext.Current; // in constructor
第三步
public override void ItemAdding(SPItemEventProperties properties)
_stCurrentContext = currentContext;
第四步
public override void ItemAdded(SPItemEventProperties properties)
if (_stCurrentContext.Request.Files[0].ContentLength > 0)
HttpPostedFile uploadfile = _stCurrentContext.Request.Files[0];
这篇关于如何在Event Handler中获取HttpContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文