0

我正在尝试通过事件接收器访问不同的网站集。事件接收器做我想要的,但它在同一个网站集中做。我有以下代码

 using (SPSite destsite = new SPSite("http://man:8787/ONE/"))
  {
    string currentURL = destsite.Url.ToString()  

   } 

我总是得到 currentURL = http://man:8787

我从来没有得到 currentURL = http://man:8787/ONE

我在http://man:8787/ONE有一个工作网站集

2013 年有什么变化吗?我做错了什么吗?

4

1 回答 1

0

根据您的描述,我们可以假设一两件事:

http://man:8787是一个 SiteCollection - 调用它SPSite

SPSite("http://man:8787/ONE/")如果来自always 的当前 url是该站点集合http://man:8787http://man:8787/ONE/的一个网站,因此您应该使用SPWeb.

如果您希望该网站位于该特定位置,请使用以下代码:

using (SPSite site = new SPSite("http://man:8787/ONE/"))
{
    using (SPWeb web = site.OpenWeb())
    { 
       //magic happens here
    }
}

编辑:SharePoint.SE 上有一个很棒的答案,它消除了围绕 SPSite、SPWeb 等的一些困惑: https ://sharepoint.stackexchange.com/questions/23241/getting-my-head-round-spsite-vs -spweb-vs-其他任何东西

于 2015-03-19T20:28:25.857 回答