Tim's Blog

好好学习,天天向上

导航

我在“代码访问安全”遇到的问题,并得到了解决!

    应客户需求,写了个可以在List中分类查找的webpart(关于这个webpart的具体需求请参阅我的博客中WSS3.0的搜索功能一文)。在编写代码的时候用到了Microsoft.sharepoint.webcontrols下的ListViewByQuery类,用visual studio 2005自动部署(我安装了微软提供的webpart for visual studio的扩展插件)webpart在本地调试的时候什么问题都没,但是把webpart部署到目标服务器上的时候却出现了问题。显示webpart不能被输出。于是我看了下日志,找到了提示的错误!

An SPRequest object was not disposed before the end of this thread.  To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it.  Due to flags specified at object creation, this will not be freed until processed by garbage collection.  Allocation Id: {717A4E83-47C3-4C25-A582-2D32B5AA90E2}  To determine where this object was allocated, create a registry key at HKEY_LOCAL_MACHINE"SOFTWARE"Microsoft"Shared Tools"Web Server Extensions"HeapSettings.  Then create a new DWORD named SPRequestStackTrace with the value 1 under this key.

Error importing WebPart. Assembly  ListSearch, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, TypeName. ListSearch.ListSearch

我想来想去,问题应该出在这个类不允许被访问的问题上。于是我修改了sharepoint站点的信任级别。
打开SPS虚拟站点的根目录下的web.config文件,找到下面这行:
<trust level="WSS_Minimal" originUrl="" />
将其修改为:
<trust level="WSS_Medium" originUrl="" />

如果不像修改web.config文件,把webpart部署到GAC中也可以解决(visual studio自动部署的时候就是部署到GAC)

问题终于得到了解决,webpart正常输出。

posted on 2007-09-21 14:27  Tim_li  阅读(517)  评论(0编辑  收藏  举报