How to obtain the HttpContext in Event Handler

后端 未结 8 536
隐瞒了意图╮
隐瞒了意图╮ 2021-01-22 20:20

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 L

相关标签:
8条回答
  • 2021-01-22 20:46

    An item event receiver run asynchronously; you will not have access to the HTTP request that initiated the event.

    0 讨论(0)
  • 2021-01-22 20:48

    Step 1 Declare:

        private HttpContext currentContext;
        static HttpContext _stCurrentContext;
    

    Step 2

    currentContext = HttpContext.Current;      // in constructor
    

    Step3

    public override void ItemAdding(SPItemEventProperties properties)
                     _stCurrentContext = currentContext;
    

    Step 4

     public override void ItemAdded(SPItemEventProperties properties)
     if (_stCurrentContext.Request.Files[0].ContentLength > 0)
     HttpPostedFile uploadfile = _stCurrentContext.Request.Files[0];
    
    0 讨论(0)
提交回复
热议问题