Chaging the SessionId
<p>I have a problem that i have to change the existing Session id generated by asp.net.I need to assign my own session id. </p>

<p>I tried with just overriding the methods of session id manager(<code>createsession</code> and <code>validate</code>).but still existing session id is retaining in the session. After that i have seen some code which deals with some internal fields using reflection.But still same result old sessionid is there?</p>

<p>i have taken the following code</p>

<pre><code>    HttpSessionState ss = HttpContext.Current.Session;
    HttpContext.Current.Session["test"] = "test";
    HttpContext.Current.Response.Write(ss.SessionID);     
    SessionIDManager manager = new SessionIDManager();
    manager.RemoveSessionID(System.Web.HttpContext.Current);
    ss.Clear();
    Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
    MysessionId myId = new MysessionId();
    bool redirected = false;
    bool IsAdded = false;
    string newid = myId.CreateSessionID(System.Web.HttpContext.Current); 
    myId.SaveSessionID(System.Web.HttpContext.Current, newid, out redirected, out IsAdded);
    HttpApplication ctx = (HttpApplication)HttpContext.Current.ApplicationInstance;
    HttpModuleCollection mods = ctx.Modules;
    System.Web.SessionState.SessionStateModule ssm = (SessionStateModule)mods.Get("Session");
    System.Reflection.FieldInfo[] fields = ssm.GetType().GetFields( BindingFlags.NonPublic|BindingFlags.Instance);
    SessionStateStoreProviderBase store = null; 
    System.Reflection.FieldInfo rqIdField = null, rqLockIdField = null, rqStateNotFoundField = null; 
    foreach (System.Reflection.FieldInfo field in fields)
    { 
        if (field.Name.Equals("_store")) store = (SessionStateStoreProviderBase)field.GetValue(ssm); 
        if (field.Name.Equals("_rqId")) rqIdField = field;
        if (field.Name.Equals("_rqLockId")) rqLockIdField = field; 
        if (field.Name.Equals("_rqSessionStateNotFound")) rqStateNotFoundField = field; 
    }
    object lockId = rqLockIdField.GetValue(ssm);
    if ((lockId != null) &amp;&amp; (ss.SessionID != null)) store.ReleaseItemExclusive(Context, ss.SessionID, lockId);
    rqStateNotFoundField.SetValue(ssm, true); rqIdField.SetValue(ssm, newid); 
    HttpSessionState s2 = HttpContext.Current.Session;
    lblMessage.Text = "changed session id is     :" + s2.SessionID;
</code></pre>

<p>here MysessionId is the class in which i have overriden create and validate{return true} methods</p>
