SharePoint2003>Areas menu refresh on runtime user Roles chnage


Hi All

Good Morning


I am using our custom area menu in my project.

I am changing the role(site group) of current user runtime according to which
the dynamic menu, I have created,displays the Areas according to the role
type assigned
to current user.

To change the role of current user runtime I use /_vti_bin/UserGroup.asmx
sharepoint webservice
by impersonating the adminstrator.

To impersonate I use this function:

//start coding
protected static WindowsIdentity CreateIdentity(string User, string Domain,
string Password)
{
// The Windows NT user token.
IntPtr tokenHandle = new IntPtr(0);

const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_NETWORK = 3;

tokenHandle = IntPtr.Zero;

// Call LogonUser to obtain a handle to an access token.
bool returnValue = LogonUser(User, Domain, Password,
LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
if (false == returnValue)
{
int ret = Marshal.GetLastWin32Error();
throw new Exception("LogonUser failed with error code: " + ret);
}

System.Diagnostics.Debug.WriteLine("Created user token: " + tokenHandle);

//The WindowsIdentity class makes a new copy of the token.
//It also handles calling CloseHandle for the copy.
WindowsIdentity id = new WindowsIdentity(tokenHandle);
CloseHandle(tokenHandle);
return id;
}

[DllImport("advapi32.dll", SetLastError=true)]
private static extern bool LogonUser(String lpszUsername, String
lpszDomain, String lpszPassword,
int dwLogonType, int dwLogonProvider, ref IntPtr phToken);


[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
private extern static bool CloseHandle(IntPtr handle);

//And I call it this way:::::

WindowsImpersonationContext wic = CreateIdentity("sharepointadmin",
"Domain", "password").Impersonate();
SPSite spsite = SPControl.GetContextSite(context);
SPWeb site = spsite.RootWeb;
site.AllowUnsafeUpdates = true;
SPRole currentRole = site.Roles["CurrentRole"];
SPUser userAdd = currentRole.Users[@"cts\147458"];
UserGroup usergroup = new UserGroup();
usergroup.Credentials =CredentialCache.DefaultCredentials;
SPRole newEmulateRole = site.Roles["role To which i am shifting current
user"];
usergroup.AddUserToRole("role To which i am shifting current
user",userAdd.Name,userAdd.LoginName,userAdd.Email,userAdd.Notes);
usergroup.RemoveUserFromRole("CurrentRole",userAdd.LoginName);
usergroup.Dispose();
wic.Undo();

//end coding


<h><b>Now I come to the problem::</b></h>

I change the roletype and I redirect to the destination page..But the menu
displayed contains the pages ,
<b>both for previous role and new role!!!!</b>and even refresh don't help
me now.

one thing I will like to mention:
If In some other window, if I hit any page in "portal/_layouts/..." e.g.
"/_layouts/1033/error.aspx"

and now come back to main working window, our main discussion point,
<b>and now if I refresh it,
it works fine!!!!!!</b>
It shows menu iems only for changed role type...


Could anyone give me atleast some idea why its happenning so that I may
debug my problem

<b>one thing more I need to mention, this problem occurs in only clients'
network, in our development server
the same code works properly in every way!!!</b>
<b>
Regards
Hemant Kumar
hemantup@gmail.com
+91-9823070763
India-Pune
</b>