Simulating logon in Moss allows you to easily use spsecurity to simulate running.ProgramThe user in the pool.
Simulated logon sets web. currentuser as the user in the running program pool.
During use, I found that:
Conclusion 1:Code
Spsite site = Null ;
Spweb myweb = Null ;
Spsecurity. runwithelevatedprivileges ( Delegate ()
{
Site=Spcontent. Current. Site;
Myweb=Site. openweb ();
} );
That is, using spcontent. Current. site or spcontent. Current. Web to specify the site or web cannot achieve the purpose of simulation.
Discovery 2: You only need to include the obtained web code in spsecurity. runwithelevatedprivileges.
Spsite site = Null ;
Spweb myweb = Null ;
Spsecurity. runwithelevatedprivileges ( Delegate ()
{
Site= NewSpsite (siteurl );
Myweb=Site. openweb ();
//You do not need to put the following operations on the list or other updates.
} );
// Put it here.
// Until the site is released, Web. currentuser will be a simulated user.
Here we need to pursue the principle of simulated login. spsecurity. runwithelevatedprivileges set spweb. currentuser to the account of the running program pool. If it is not a new website object, it is illegal to assign a value to spweb. currentuser.
That's why one cannot, and two can.