Discussion:
ServerContext.GetContext(SPSite) does not return the context
(too old to reply)
MJ
2007-11-06 22:44:01 UTC
Permalink
I am running the following code on a virtual machine (Windows 2003 Server in
DC role). The second line spits out the correct ID. For some reason though
GetContext cannot create the context from site and is null. Code is running
under windows authentication and I have verified the account.

SPSite site = new SPSite("http://localhost");
Response.Write(site.ID);
ServerContext context = ServerContext.GetContext(site);
Gary A. Bushey
2007-11-07 11:46:51 UTC
Permalink
You can try using

SPContext.GetContext(SPWeb)
--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
Post by MJ
I am running the following code on a virtual machine (Windows 2003 Server in
DC role). The second line spits out the correct ID. For some reason though
GetContext cannot create the context from site and is null. Code is running
under windows authentication and I have verified the account.
SPSite site = new SPSite("http://localhost");
Response.Write(site.ID);
ServerContext context = ServerContext.GetContext(site);
MJ
2007-11-07 16:05:01 UTC
Permalink
No. It deosn't work.
Post by Gary A. Bushey
You can try using
SPContext.GetContext(SPWeb)
--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
Post by MJ
I am running the following code on a virtual machine (Windows 2003 Server in
DC role). The second line spits out the correct ID. For some reason though
GetContext cannot create the context from site and is null. Code is running
under windows authentication and I have verified the account.
SPSite site = new SPSite("http://localhost");
Response.Write(site.ID);
ServerContext context = ServerContext.GetContext(site);
Gary A. Bushey
2007-11-07 21:42:47 UTC
Permalink
Strange. I have used this in many different pieces of code. Can you
provide more details as to what you are trying to do?
--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
Post by MJ
No. It deosn't work.
Post by Gary A. Bushey
You can try using
SPContext.GetContext(SPWeb)
--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
Post by MJ
I am running the following code on a virtual machine (Windows 2003
Server
in
DC role). The second line spits out the correct ID. For some reason though
GetContext cannot create the context from site and is null. Code is running
under windows authentication and I have verified the account.
SPSite site = new SPSite("http://localhost");
Response.Write(site.ID);
ServerContext context = ServerContext.GetContext(site);
MJ
2007-11-08 04:03:00 UTC
Permalink
Yes It used to work for me too. I put the code I have posted in a aspx page
with nothing else and still context is null. The only thing I can think of is
that maybe some security thing is blocking access but it is not throwing, it
only returns null.

I try to test it on a different machine and see what is going on. Maybe it
is because the server is a DC.
Post by Gary A. Bushey
Strange. I have used this in many different pieces of code. Can you
provide more details as to what you are trying to do?
--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
Post by MJ
No. It deosn't work.
Post by Gary A. Bushey
You can try using
SPContext.GetContext(SPWeb)
--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
Post by MJ
I am running the following code on a virtual machine (Windows 2003
Server
in
DC role). The second line spits out the correct ID. For some reason though
GetContext cannot create the context from site and is null. Code is running
under windows authentication and I have verified the account.
SPSite site = new SPSite("http://localhost");
Response.Write(site.ID);
ServerContext context = ServerContext.GetContext(site);
Aparna
2007-12-19 22:54:00 UTC
Permalink
Hi

I am facing the exact same issue.

But the code works fine on a console application.

Please help... i am a new bie to .net & sharepoint....

the code:

using (SPSite site = new SPSite("http://servername"))
{
site.AllowUnsafeUpdates = true;
site.CatchAccessDeniedException = false;
ServerContext context = ServerContext.GetContext(site);

UserProfileManager profileManager = new
UserProfileManager(context);
if (profileManager != null)
{

foreach (UserProfile p in profileManager)
{
TextBox1.Text += p.ID;
TextBox1.Text += "\n";
}
}

--------------

getting error at the foreach loop:

Please Help

Thanks in advance

Aparna

Value cannot be null. Parameter name: serverContext
Post by MJ
Yes It used to work for me too. I put the code I have posted in a aspx page
with nothing else and still context is null. The only thing I can think of is
that maybe some security thing is blocking access but it is not throwing, it
only returns null.
I try to test it on a different machine and see what is going on. Maybe it
is because the server is a DC.
Post by Gary A. Bushey
Strange. I have used this in many different pieces of code. Can you
provide more details as to what you are trying to do?
--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
Post by MJ
No. It deosn't work.
Post by Gary A. Bushey
You can try using
SPContext.GetContext(SPWeb)
--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
Post by MJ
I am running the following code on a virtual machine (Windows 2003
Server
in
DC role). The second line spits out the correct ID. For some reason though
GetContext cannot create the context from site and is null. Code is running
under windows authentication and I have verified the account.
SPSite site = new SPSite("http://localhost");
Response.Write(site.ID);
ServerContext context = ServerContext.GetContext(site);
ysm79
2008-01-22 21:48:10 UTC
Permalink
Post by Aparna
Hi
I am facing the exact same issue.
But the code  works fine on a console application.
Please help... i am a new bie to .net & sharepoint....
using (SPSite site = new SPSite("http://servername"))
        {
            site.AllowUnsafeUpdates = true;
            site.CatchAccessDeniedException = false;
            ServerContextcontext= ServerContext.GetContext(site);
             UserProfileManagerprofileManager = newUserProfileManager(context);
              if (profileManager != null)
                {
                    foreach (UserProfile p in profileManager)
                    {
                        TextBox1.Text += p.ID;
                        TextBox1.Text += "\n";
                    }
                }
--------------
Please Help
Thanks in advance
Aparna
Value cannot be null. Parameter name: serverContext
Post by MJ
Yes It used to work for me too. I put the code I have posted in a aspx page
with nothing else and stillcontextis null. The only thing I can think of is
that maybe some security thing is blocking access but it is not throwing, it
only returns null.
I try to test it on a different machine and see what is going on. Maybe it
is because the server is a DC.
Strange.  I have used this in many different pieces of code.  Can you
provide more details as to what you are trying to do?
--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
Post by MJ
No. It deosn't work.
Post by Gary A. Bushey
You can try using
SPContext.GetContext(SPWeb)
--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
Post by MJ
I am running the following code on a virtual machine (Windows 2003
Server
in
DC role). The second line spits out the correct ID. For some reason
though
GetContext cannot create thecontextfrom site and is null. Code is
running
under windows authentication and I have verified the account.
 SPSite site = new SPSite("http://localhost");
 Response.Write(site.ID);
 ServerContextcontext= ServerContext.GetContext(site);- Hide quoted text -
- Show quoted text -
Hi, did you get this issue figured out eventrually, I have same issue.
Thanks for sharing.
j***@yahoo.fr
2008-01-30 10:22:35 UTC
Permalink
Here are some helps (I hope) :
- do not use delegation before getting the context
- in a webpart, if you want the SPWeb, use
SPControl.GetContextWeb(Context)
unknown
2010-04-20 16:14:16 UTC
Permalink
I have same issue when trying to enumarte the user profile. When I create userprofilemanager object, it is created smoothly but when tried to enumarate with foreach loop it is giving me error "Value cannot be null.Parameter name: serverContext". I check with my access rights and permission in SSP.

It is strange to me when I created new windows application and paste this code it is working fine, It is also working fine in console appliaction but again I tried in Web application project it is giving me same error.
Any help really appreciated.

using (SPSite site = new SPSite(strSiteURL))
{
ServerContext siteContext = ServerContext.GetContext(site);
UserProfileManager pm = new UserProfileManager(siteContext);

foreach (UserProfile userProfile in pm)
{}
}



Aparn wrote:

HiI am facing the exact same issue.
19-Dec-07

Hi

I am facing the exact same issue.

But the code works fine on a console application.

Please help... i am a new bie to .net & sharepoint....

the code:

using (SPSite site = new SPSite("http://servername"))
{
site.AllowUnsafeUpdates = true;
site.CatchAccessDeniedException = false;
ServerContext context = ServerContext.GetContext(site);

UserProfileManager profileManager = new
UserProfileManager(context);
if (profileManager != null)
{

foreach (UserProfile p in profileManager)
{
TextBox1.Text += p.ID;
TextBox1.Text += "\n";
}
}

--------------

getting error at the foreach loop:

Please Help

Thanks in advance

Aparna

Value cannot be null. Parameter name: serverContext


"MJ" wrote:

Previous Posts In This Thread:

On Tuesday, November 06, 2007 5:44 PM
M wrote:

ServerContext.GetContext(SPSite) does not return the context
I am running the following code on a virtual machine (Windows 2003 Server in
DC role). The second line spits out the correct ID. For some reason though
GetContext cannot create the context from site and is null. Code is running
under windows authentication and I have verified the account.

SPSite site = new SPSite("http://localhost");
Response.Write(site.ID);
ServerContext context = ServerContext.GetContext(site);

On Wednesday, November 07, 2007 6:46 AM
Gary A. Bushey wrote:

You can try usingSPContext.GetContext(SPWeb)-- Gary A.
You can try using

SPContext.GetContext(SPWeb)

--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
***@mindspring.com

On Wednesday, November 07, 2007 11:05 AM
M wrote:

Re: ServerContext.GetContext(SPSite) does not return the context
No. It deosn't work.

"Gary A. Bushey" wrote:

On Wednesday, November 07, 2007 4:42 PM
Gary A. Bushey wrote:

Strange. I have used this in many different pieces of code.
Strange. I have used this in many different pieces of code. Can you
provide more details as to what you are trying to do?
--
Gary A. Bushey
Microsoft Office SharePoint Server MVP
***@mindspring.com


"MJ" <***@discussions.microsoft.com> wrote in message news:CC6D401C-E6D4-443D-86DF-***@microsoft.com...

On Wednesday, November 07, 2007 11:03 PM
M wrote:

Yes It used to work for me too.
Yes It used to work for me too. I put the code I have posted in a aspx page
with nothing else and still context is null. The only thing I can think of is
that maybe some security thing is blocking access but it is not throwing, it
only returns null.

I try to test it on a different machine and see what is going on. Maybe it
is because the server is a DC.

"Gary A. Bushey" wrote:

On Wednesday, December 19, 2007 5:54 PM
Aparn wrote:

HiI am facing the exact same issue.
Hi

I am facing the exact same issue.

But the code works fine on a console application.

Please help... i am a new bie to .net & sharepoint....

the code:

using (SPSite site = new SPSite("http://servername"))
{
site.AllowUnsafeUpdates = true;
site.CatchAccessDeniedException = false;
ServerContext context = ServerContext.GetContext(site);

UserProfileManager profileManager = new
UserProfileManager(context);
if (profileManager != null)
{

foreach (UserProfile p in profileManager)
{
TextBox1.Text += p.ID;
TextBox1.Text += "\n";
}
}

--------------

getting error at the foreach loop:

Please Help

Thanks in advance

Aparna

Value cannot be null. Parameter name: serverContext


"MJ" wrote:

On Monday, February 04, 2008 10:09 PM
ysm79 wrote:

Re: ServerContext.GetContext(SPSite) does not return the context
wrote:
ite);
fileManager(context);
anager)
age
is
, it
it
you

on

quoted text -

Hi, did you get this issue figured out eventrually, I have same issue.
Thanks for sharing.

On Monday, February 04, 2008 10:09 PM
jerome_vuiber wrote:

Re: ServerContext.GetContext(SPSite) does not return the context
Here are some helps (I hope) :
- do not use delegation before getting the context
- in a webpart, if you want the SPWeb, use
SPControl.GetContextWeb(Context)


Submitted via EggHeadCafe - Software Developer Portal of Choice
C# And The Little Iterator That Could
http://www.eggheadcafe.com/tutorials/aspnet/f0cfca12-7398-4b84-a232-0ae26adaa533/c-and-the-little-iterato.aspx
Loading...