junwei's profileRichard's footprint on ....PhotosBlogListsMore Tools Help

Blog


    September 21

    FormsAuthentication

    This morning, when I debug my web app, I found a strange phenomenon. My web app used forms authentication, but after login from login page, There will be two identical authentication cookies issued along with server response. The partial authentication section is as following in web.config:
    <authentication mode="forms">
    <forms loginUrl="login.aspx" path="/" ...>
    </forms>
    </authentication>
     
    <authorization>
    <deny user="?"/>
    </authorization>
     
    Originally I wrote the following codes:
     
    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket            (1,userName,DateTime.Now,DateTime.Now.AddMinutes,false,"");
     
    string encryptedToken = FormsAuthentication.Encrypt(ticket);
     
    Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsAuthName, encryptedToken));
     
    FormsAuthentication.RedirectFromLoginPage(userName,false);
     
    I started a tcp monitor and found that two Set-Cookie http header sent to client along with the response, after reading MS RedirectFromLoginPage API doc which states that this method will auto call SetAuthCookie method to issue an authentication cookie and append it to response cookie collection! That's why there are two Set-Cookie header exists.
    So in this case, I have to code like this:
     
    Response.Redirect(FormsAuthentication.GetDefaultUrl(userName,false)); // right way
     
    instead of the codes the bold red line shows. And in the subsequent request, this authentication cookie will attach to each request to indicate that one user has been authenticated within a session. If you use tcp monitor, you will see that each subsequent request uses a Cookie http header to pertain this value.
     
    And another tip: this kind of cookie is session cookies, it was stored in memory and when session expired or  when browser window is closed, it will be removed from browser. 
    September 06

    Auto generating Visio diagram

     I knew a bit VSTO, but I have never explorered it further. Because of a VBA project, I began to utilitize this tech. It's required that visio diagrams must be generated autmatically against data stored as plain text, or in database, or other forms. Originally I got no clue about that. What I was confused is how such text data was converted to a diagram. After searching, I got some tutorial material on this, especially materials from MSDN. There is a standlone visio SDK downloadable freely. It is a good place to start. VBA usage in visio is also talked about.