MOSS 2007 -- 无效 URL 异常 SPSite.OpenWeb(...)
这似乎有点微不足道,但我一直无法弄清楚。 我正在打开一个 SPSite,然后尝试在该 SPSite 下打开一个 SPWeb。 这在具有相同网站集/网站层次结构的 VPC 上运行良好,但在生产中,当我尝试 SPSite.OpenWeb(webUrl); 时,我收到一个异常,告诉我 URL 无效。 我已经验证 URL 是正确的。
代码:
try
{
SPSite scheduleSiteCol = new SPSite(branchScheduleURL);
lblError.Text += Environment.NewLine + "Site Collection URL: " + scheduleSiteCol.Url;
SPWeb scheduleWeb = scheduleSiteCol.OpenWeb(branchScheduleURL.Replace(scheduleSiteCol.Url, "")); //<--- Throws error on this line
SPList scheduleList = scheduleWeb.GetList(branchScheduleURL + "/lists/" + SPContext.Current.List.Title);
return scheduleList.GetItemById(int.Parse(testID));
}
catch (System.Exception ex)
{
lblError.Text += Environment.NewLine + ex.ToString();
return null;
}
注:
branchScheduleURL 实际上是包含 Web URL 的整个 URL。
输出+异常:
网站集 URL:https://ourSite.com/mocc
System.ArgumentException:无效 URL:/internal/scheduletool。 在 Microsoft.SharePoint.SPSite.OpenWeb(字符串 strUrl,布尔 requireExactUrl) 在 Microsoft.SharePoint.SPSite.OpenWeb(字符串 strUrl) 在 MOCCBranchScheduleListWeb.MOCCBranchScheduleListV3.GetConflictListItem(字符串branchScheduleURL,字符串 testID)System.NullReferenceException:对象引用未设置为对象的实例。 在 MOCCBranchScheduleListWeb.MOCCBranchScheduleListV3.CheckForConflicts(String[] cfcFlags1, DateTime startTime, DateTime endTime, String[] cfcFlags2)
注意:
https://ourSite.com/mocc/internal/scheduletool 是我尝试打开的 SPWeb。
我错过了一些明显的东西吗? 任何帮助将不胜感激。
谢谢。
This may seem a bit trivial, but I have not been able to figure it out. I am opening up a SPSite and then trying to open up a SPWeb under that SPSite. This is working fine on the VPC, which has the same Site Collection/Site hierarchy, but on production, I get an exception telling me that the URL is invalid when I try the SPSite.OpenWeb(webUrl);. I have verified that the URL’s are correct.
The Code:
try
{
SPSite scheduleSiteCol = new SPSite(branchScheduleURL);
lblError.Text += Environment.NewLine + "Site Collection URL: " + scheduleSiteCol.Url;
SPWeb scheduleWeb = scheduleSiteCol.OpenWeb(branchScheduleURL.Replace(scheduleSiteCol.Url, "")); //<--- Throws error on this line
SPList scheduleList = scheduleWeb.GetList(branchScheduleURL + "/lists/" + SPContext.Current.List.Title);
return scheduleList.GetItemById(int.Parse(testID));
}
catch (System.Exception ex)
{
lblError.Text += Environment.NewLine + ex.ToString();
return null;
}
Note:
branchScheduleURL is actually the whole URL that includes the URL of the Web as well.
The output + exception:
Site Collection URL: https://ourSite.com/mocc
System.ArgumentException: Invalid URL: /internal/scheduletool. at Microsoft.SharePoint.SPSite.OpenWeb(String strUrl, Boolean requireExactUrl) at Microsoft.SharePoint.SPSite.OpenWeb(String strUrl) at MOCCBranchScheduleListWeb.MOCCBranchScheduleListV3.GetConflictListItem(String branchScheduleURL, String testID)System.NullReferenceException: Object reference not set to an instance of an object. at MOCCBranchScheduleListWeb.MOCCBranchScheduleListV3.CheckForConflicts(String[] cfcFlags1, DateTime startTime, DateTime endTime, String[] cfcFlags2)
Note:
https://ourSite.com/mocc/internal/scheduletool is the SPWeb I am trying to open.
Am I missing something obvious? Any help would be greatly appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看此页面底部的示例表。
尝试不要将任何参数发送到 OpenWeb() 方法(第二行)。
Looks at the examples table at the bottom of this page.
Try not sending any parameters into the OpenWeb() method (2nd row).
首先尝试获取“Internal”的 SPWeb 对象。 然后获取该对象的 SubWeb SPWebCollection。 由此,尝试使用 GetSubwebsForCurrentUser() 方法获取“ScheduleTool”的 SPWeb 对象。
Try getting the SPWeb object for "Internal" first. then get the SubWeb SPWebCollection for that and object. From that, try to get the SPWeb object for "ScheduleTool" using the GetSubwebsForCurrentUser() Method.
它表示您的网站集 URL 是 /mocc,因此您的 SPWeb 下面将类似于 /mocc/internal/scheduletool。 因此,请执行类似
string webServerRelativeUrl = site.ServerRelativeUrl + "/internal/scheduletool"
It says your Site Collection URL is /mocc, thus your SPWeb underneath would be something like /mocc/internal/scheduletool. So do something like
string webServerRelativeUrl = site.ServerRelativeUrl + "/internal/scheduletool"