如何在事件处理程序中获取HttpContext

编程入门 行业动态 更新时间:2024-10-26 22:22:04
本文介绍了如何在事件处理程序中获取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 constructor

Step3

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

本文发布于:2023-11-16 09:43:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603147.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事件   程序   如何在   HttpContext

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!