From: Satish Kumar on
Create SPUserToken and use like below:

string url = SPContext.Current.Site.Url;
SPUserToken token=site.RootWeb.GetToken...
SPSite site = new SPSite(url,token);

Hope this will solve ur problem :)



Jirka wrote:

SecurityException
30-Jan-09

Hi all

my dev machine: virtual Windows Server 2008 x64, WSS 3.0 SP1 x64,
VisualStudio 2008, VSeWSS 1.3 (CTP)

I'm trying to get my webpart to WSS, deploying is correct, webpart is in
website galery list, but if I want to import to any site, it doesn't work.
I debug this situation and got:

this.ExportMode = WebPartExportMode.All;

string url = SPContext.Current.Site.Url; // this line works
correct (got the right url)
SPSite site = new SPSite(url); // this line thows
exception

the complete exception

System.Security.SecurityException was unhandled by user code
Message="Request failed."
Source="Microsoft.SharePoint"
StackTrace:
at Microsoft.SharePoint.Administration.SPPersistedObject.ToString()
at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri,
Boolean contextSite, SPUserToken userToken)
at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
at klienti.klienti_sql..ctor()
at T_90428866_5b97_4ebf_a295_118a24ff54b2.CreateInstance()
at System.Web.HttpRuntime.FastCreatePublicInstance(Type type)
at
System.Web.UI.WebControls.WebParts.WebPartManager.ImportWebPart(XmlReader
reader, String& errorMessage)
InnerException:

the similar exception is thown by the try to connect to MSSQL ....

I have no idea how this situation resolve ... I tryied to run WSS under
domain administrator, connecting to SQL as domain administrator, add user
account in Central Administration > Application Management > Policy for Web
Application but with no effect :( ...

Regards

JH

Previous Posts In This Thread:

On Friday, January 30, 2009 10:17 AM
Jirka wrote:

SecurityException
Hi all

my dev machine: virtual Windows Server 2008 x64, WSS 3.0 SP1 x64,
VisualStudio 2008, VSeWSS 1.3 (CTP)

I'm trying to get my webpart to WSS, deploying is correct, webpart is in
website galery list, but if I want to import to any site, it doesn't work.
I debug this situation and got:

this.ExportMode = WebPartExportMode.All;

string url = SPContext.Current.Site.Url; // this line works
correct (got the right url)
SPSite site = new SPSite(url); // this line thows
exception

the complete exception

System.Security.SecurityException was unhandled by user code
Message="Request failed."
Source="Microsoft.SharePoint"
StackTrace:
at Microsoft.SharePoint.Administration.SPPersistedObject.ToString()
at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri,
Boolean contextSite, SPUserToken userToken)
at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
at klienti.klienti_sql..ctor()
at T_90428866_5b97_4ebf_a295_118a24ff54b2.CreateInstance()
at System.Web.HttpRuntime.FastCreatePublicInstance(Type type)
at
System.Web.UI.WebControls.WebParts.WebPartManager.ImportWebPart(XmlReader
reader, String& errorMessage)
InnerException:

the similar exception is thown by the try to connect to MSSQL ....

I have no idea how this situation resolve ... I tryied to run WSS under
domain administrator, connecting to SQL as domain administrator, add user
account in Central Administration > Application Management > Policy for Web
Application but with no effect :( ...

Regards

JH

EggHeadCafe - Software Developer Portal of Choice
Call a .NET Webservice using XMLHTTP, XMLDOM, XPATH and VBScript
http://www.eggheadcafe.com/tutorials/aspnet/a78b7a2d-2156-43f1-980b-67fa6d6dfa46/call-a-net-webservice-us.aspx