1, UseCodeWhen Moss SSP is called to obtain USERPROFILE, the code can only run under the moss site or winform. Otherwise, an error occurs. How can this problem be solved?
The Code is as follows:
SpsiteSite =New Spsite("Http: // ssjin073: 9031");
//Obtain the context
Servercontext context = servercontext. getcontext (SITE );//. Getcontext (sspname );
// This. Context. items ["Microsoft. Office. servercontext"] = context;
Userprofilemanager_ Profilemanager;
_ Profilemanager =NewUserprofilemanager (context );
USERPROFILEU = _ profilemanager. getuserprofile ("Saictest" "zjy");
Response. Write (U. personalurl );
This code can only be run on the page of the moss site. If it is run on a common site or directly in the small IIS of Vs, the following error will be reported::
Error
The value cannot be blank.
Parameter Name: Servercontext
Description:Execute currentWebAn unprocessed exception occurred during the request. Check the stack trace information for details about the error and the source of the error in the code.
Exception details: System.Argumentnullexception:The value cannot be blank.
Parameter Name: Servercontext
Source Error:
Line46:USERPROFILEU = _ profilemanager. getuserprofile ("Saictest" "zjy");
Line47:
Line48:Response. Write (U. personalurl );
This error is caused by a moss bug. The internal code of sitecontext will call servercontext in the current context. If servercontext is not called, an error will occur.
We can solve this problem by manually adding context objects:
SpsiteSite =New Spsite("Http: // ssjin073: 9031");
//Obtain the context
Servercontext context = servercontext. getcontext (SITE );//. Getcontext (sspname );
//Here we willServercontextPut Context
This. Context. items ["Microsoft. Office. servercontext"] = Context;
Userprofilemanager_ Profilemanager;
_ Profilemanager =NewUserprofilemanager (context );
USERPROFILEU = _ profilemanager. getuserprofile ("Saictest" "zjy");
Response. Write (U. personalurl );
The above code can be run on any site!
Note:
1)Site ApplicationProgramThe account of the pool must have sufficient permissions or directly use the application pool of the moss site.
2)You need to add the following configuration under Web. config of the site:
<Identity impersonate = "true"/>
2After the permission is elevated, similar errors may occur during listitem operations, which can be solved in the same way:
Protected VoidPage_load (ObjectSender,EventargsE)
{
Spsecurity. Runwithelevatedprivileges (Delegate()
{
Updateitem ();
}
);
}
VoidUpdateitem ()
{
SpsiteSite =New Spsite("Http: // ssjin073: 9032");
SpwebWeb = site. rootweb;
//Force set context object
Httpcontext. Current. items ["Httphandlerspweb"] = Web;
Web. allowunsafeupdates =True;
SplistList = web. Lists ["Mainlist"];
SplistitemItem = List. items [0];
Item ["Title"] =Datetime. Now. tostring ();
Item. Update ();
Web. Dispose ();
Site. Dispose ();
}
ArticleSource: http://www.cnblogs.com/jianyi0115/archive/2008/04/11/1148827.html