How to obtain the HttpContext in Event Handler

后端 未结 8 642
隐瞒了意图╮
隐瞒了意图╮ 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:32

    If you place it in a static variable like that, you also have multiple people using the same context object that will be the context of the user who first ran the event receiver, and concurrent changes could have unexpected results.

    The context is removed by design to encourage people not to use it. You should try to use the properties that are exposed as much as possible to avoid compatibility issues later. You can get the username off the properties.Web.CurrentUser as one example.

    Using static variables in the event receiver is tricky, and you have to remember if you have multiple front ends, the data in the static variable is not available outside the frontend that the instance of the event receiver runs on.

提交回复
热议问题