本文介绍了如何在事件处理程序中获取HttpContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在MOSS的文档库中的事件处理程序中获取HTTPContext,但是我所拥有的只是HTTPContext的空值.当前,我在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 constructorStep3
public override void ItemAdding(SPItemEventProperties properties) _stCurrentContext = currentContext;第4步
public override void ItemAdded(SPItemEventProperties properties) if (_stCurrentContext.Request.Files[0].ContentLength > 0) HttpPostedFile uploadfile = _stCurrentContext.Request.Files[0];更多推荐
如何在事件处理程序中获取HttpContext
发布评论