SharePoint:SPContext.Current 在 SharePoint Foundation 2010 中返回 null [英] SharePoint: SPContext.Current returns null for in SharePoint foundation 2010

查看:37
本文介绍了SharePoint:SPContext.Current 在 SharePoint Foundation 2010 中返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码从共享点访问网络应用程序.

I am using the below code to access the web-application from sharepoint.

SPWebApplication webApplication = SPContext.Current.Site.WebApplication;

它在 sharepoint server 2010(MOSS2010) 上运行良好.但是当我使用 SharePoint Foundation 2010(WSS4.0) SPContext.Current 时,总是返回 null.谁能告诉我这可能是什么原因?我该如何解决这个问题?

it works fine with the sharepoint server 2010(MOSS2010). But when I work with SharePoint foundation 2010(WSS4.0) SPContext.Current always returns null. Can anyone tell me what could be the reason for this? and how can i resolve this issue?

谢谢和问候,莎米拉

推荐答案

我发现 SPContext 为 null 的常见原因之一是 AAM 配置不正确.sharepoint 了解为您的站点配置了哪些 URL 非常重要,因为如果您的 URL 未注册,它无法判断 URL 是否在 SPContext 内,因此创建它.

One of the common reasons I've seen where SPContext is found to be null is when you have an incorrectly configured AAM. Its really important that sharepoint understands what URLs are configured for your site because if your URL is not registered it cant tell if the URL is inside the SPContext hence create it.

我见过的最常见的变化是修改IIS 站点.这是一个巨大的禁忌,请永远不要这样做(使用AAM 代替).如果你继续修改这些你新的添加的标题只会部分起作用.SharePoint 内部有很多组件直接依赖于 URL 和特别是在内部查找此 URL.你发现了什么(对于开发人员)是对 SPContext.Current 的引用(核心部分SharePoint 优点)将不起作用.这对随机造成严重破坏SharePoint 页面、Web 部件和自定义功能.

The most common change Ive seen is modifying the host headers of the IIS site. This is an enormous no-no, please don't ever do this (use AAM's instead). If you do go ahead and modify these any of your newly added headers will only be partly functional. Inside of SharePoint there is a lot of components which rely directly on the URL and in particular on looking this URL up internally. What you find (for the developers) is that references to SPContext.Current (a core piece of SharePoint goodness) will not work. This causes havoc on random SharePoint pages, web parts and custom features.

如果您想知道如何设置 AAM(并找出它们为何如此重要),请查看此处,请查看我关于该主题的博客文章http://blog.staticvoid.co.nz/2011/05/sharepoint-alternate-access-mappings.html

Take a look here if you want to know how to setup AAMs (and find out why they are so important) take a look at my blog post on the subject http://blog.staticvoid.co.nz/2011/05/sharepoint-alternate-access-mappings.html

这篇关于SharePoint:SPContext.Current 在 SharePoint Foundation 2010 中返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆