so after further reading their is no direct way to request the client browser to regenerate a new session id, even if I used Session.Clear(), Session.RemoveAll() or Session.Abandon() it will not serve my needs (you can read about the difference in this artical Link it was a good read), so at the end of the day I was using the sessionid as a generaic string to identify database records for update statement at the end of page request so I created a function that generate a random 20 character string by each call and assign the value to a global var, this var can be used in my insert/update requests, the method I created to generate a random string is as follows :-
public static string GenerateSessionID()
{
char[] characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".ToCharArray();
Random r = new Random();
System.Threading.Thread.Sleep(10);
string randomstring = "";
for (int i = 0; i < 20; i++)
{
randomstring += characters[r.Next(0, 60)].ToString();
}
return randomstring;
}
to help understand the code
char[] characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".ToCharArray();
this line of code will create an array of char including all numbers letters in lower and upper case, you can put any kind of characters you would like
Random r = new Random();
here you create an object "r" of the random class
string randomstring = "";
just creating a string to hold the value of generated key
for (int i = 0; i < 20; i++)
you can define the length of the random key by increasing or decreasing the max value of "i"
r.Next(0, 60)
the method r.Next(0,60) return a random number between 0, 60 ; r.Next(min, max); you can call r.Next() it will get any random number
I defined the min and max value because I will use the number generated as an index to the characters array
randomstring += characters[r.Next(0, 60)].ToString();
I guess now it is self explained that everytime you loop, the char in the character array with index random will be concatenated to the randomstring
System.Threading.Thread.Sleep(10);
now the reason I used thread.sleep for 10 mili-sesond is, when u keep calling the random .next() function without any break it will return the same value, I briefly read about it, I kept decresing the value of the mili-second until I reached 2 and it was a hit and miss sometimes it generate a new value sometimes not so just to be on the safe side I put the value as 10
now I call the function when I need it and place the value in a string and use it