zoukankan      html  css  js  c++  java
  • MOSS2007 之SPContext

     MOSS2007的开发中SPContext是个佷重要对象。
     今天来和大家分享一下本人对SPContext的理解啊。

    见名知义:SPContext是一个当前的MOSS上下文对象。

    通过它我们可以访问到所有上下文信息如:

          当前站点

    SPSite oSite = SPContext.Current.Site;

          当前网站

    SPWeb oWeb = SPContext.Current.Web;

          当前应用程序

    SPWebApplication oWebApplicationCur = SPContext.Current.Site.WebApplication;

           当前列表

    SPList oListCur = SPContext.Current.List;
    SPList oListCur = SPContext.Current.List;
    SPWeb oWeb = SPContext.Current.Web;
    SPSite oSite = SPContext.Current.Site;
    SPWebApplication oWebApplicationCur = SPContext.Current.Site.WebApplication;

    其实得到这这些你可能觉得没什么用的,不要搞错了。

    这些可大有用去啊。

    如:获取但前用户

    using(SPWeb oWeb = SPContext.Current.Site.OpenWeb(guidWebsite))
    {
        SPUser oUser = SPContext.Current.Web.CurrentUser;
    }

            获取当前用户的群组

    using(SPWeb oWeb = SPContext.Current.Site.OpenWeb(guidWebsite))
    {
        SPUser oUser = SPContext.Current.Web.CurrentUser;
        SPGroupCollection spgroups=oUser.Groups;
    }

    这样我就就可以针对当前用户和他所在的群组做文章了,哈哈。

    另外注意:

           由SPContext获得的oWeb、oSite、SPWebApplication是不可以Dispose的。

            否则系统容易挂!

  • 相关阅读:
    <style>的scope属性
    scrollIntoView的使用
    需要学习的内容列表
    react生命周期
    JS对象-不可扩展对象、密封对象、冻结对象
    神策埋点
    Django初识
    MySQL的sql_mode模式说明及设置
    MySQL的逻辑查询语句的执行顺序
    MySQL行(记录)的详细操作
  • 原文地址:https://www.cnblogs.com/masahiro/p/10129187.html
Copyright © 2011-2022 走看看