我希望做出能在后台查看所有登陆用户信息的功能。在global.asax有这样一段:
void Application_Start(object sender, EventArgs e) 
{
   Application["hashTable"] = new Hashtable();
}
用户登陆过程中我有这样一段代码:string sessionId = this.Session.SessionID;
try
{
Application.Lock();
Hashtable sessionTable = Application["hashTable"] as Hashtable;
if (null == sessionTable)
{
   Application["hashTable"] = new Hashtable();
}
if (!sessionTable.Contains(sessionId))
{                       
   sessionTable.Add(sessionId, info);                       
}
Application.UnLock();
}
catch (Exception ex)
{
   throw new Exception("You have already login.");
}
我发现Application似乎不太稳定,我的Application并没有time out,但有时候Application中保存的Hashtable 会丢失一些用户信息,不知道这是怎么回事?  谢谢!

解决方案 »

  1.   

    应用被IIS回收了!所以会丢数据!
      

  2.   


    var FONT_NAME = Array(
        Array('Arial', 'Arial'),
        Array('Arial Black', 'Arial Black'),
        Array('Times New Roman', 'Times New Roman'),
        Array('Courier New', 'Courier New'),
        Array('Tahoma', 'Tahoma'),
        Array('Verdana', 'Verdana'),
        Array('GulimChe', 'GulimChe'),
        Array('MS Gothic', 'MS Gothic')
    );
    //event handler
    function execCmd()
    {
     var cmd=window.event.srcElement.id;
     switch(cmd)
     {
       case "bold":
       var selectDocument=document.frames("Editor").document;
       selectDocument.execCommand("Bold",false,null);
       break;
       case "italic":
       var selectDocument=document.frames("Editor").document;
       selectDocument.execCommand("Italic",false,null);
       break;
       case "underLine":
       var selectDocument=document.frames("Editor").document;
       selectDocument.execCommand("Underline",false,null);
       break;
       case "fontName":
       DisplayFontNameMenu();
       break;
       case "Arial":
       document.frames("Editor").document.focus();
       var selectDocument=document.frames("Editor").document;
       selectDocument.execCommand("FontName",true,"Arial");
       break;
       case "Arial Black":
       var selectDocument=document.frames("Editor").document;
       selectDocument.execCommand("FontName",false,"Arial Black");
       break;
       case "Times New Roman":
       break;
       case "Courier New":
       break;
       case "Tahoma":
       var selectDocument=document.frames("Editor").document;
       selectDocument.execCommand("FontName",false,"Tahoma");
       break;
       case "Verdana":
       break;
       case "GulimChe":
       break;
       case "MS Gothic":
       break;
       default:
       break;
     }}
    function DisplayFontNameMenu()
    {
      var menu=document.getElementById("menu");
      if(menu.innerHTML!="")
      {
          menu.innerHTML="";
      }
      else
      {
         var htmlContent = "";
         for (var i = 0; i < FONT_NAME.length; i++)
         {
            htmlContent += "<div id='"
                           +FONT_NAME[i][0]
                           +"'style='font-family:" + FONT_NAME[i][0]
                           +";padding:2px;width:160px;cursor:pointer;' " 
                           +"onclick='execCmd();'"
                           +">"
                           +FONT_NAME[i][1]
                           + "</div>";
         }
         menu.innerHTML=htmlContent;
      }
    }
    function mouseover(el) {
    el.className = "issueDetailToolbarButtonRaised";
    }function mouseout(el) {
    el.className = "issueDetailToolbarButton";
    }function mousedown(el) {
    el.className = "issueDetailToolbarButtonPressed";
    }function mouseup(el) {
    el.className = "issueDetailToolbarButtonRaised";
    }//Creates a tool bar button for html editor
    function createToolBarButton(icon, alt, cmd)
    {
        var htmlContent="<img id='"
                   +cmd
                   +"'class='issueDetailToolbarButton'onmouseover='mouseover(this);'onmouseout='mouseout(this);'onmousedown='mousedown(this);'onmouseup='mouseup(this);'"
                   + "onclick='execCmd();'"
                   + "src='"+icon+"'"
                   +"align='middle'"
                   +"alt='"+alt+"'"
                   +"/>"    return htmlContent;
    }
    //constructor
    function htmlEditor(objName)
    { this.init=function()
     {
         var toolBar=document.getElementById("toolBar");
         var htmlContent=createToolBarButton("bold.gif", "click to make your selection bold", "bold");
         htmlContent+=createToolBarButton("italic.gif", "click to make your selection italic", "italic");
         htmlContent+=createToolBarButton("underLine.gif", "click to make your selection underLine", "underLine");
         htmlContent+=createToolBarButton("fontColor.gif", "click to make your selection color", "fontColor");
         htmlContent+=createToolBarButton("size.gif", "click to make your selection font size", "fontSize");
         htmlContent+=createToolBarButton("font.gif", "click to make your selection font name", "fontName");
         toolBar.innerHTML=htmlContent;
     }
    }
      

  3.   

    <html>
    <head>
    <link href="view.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="htmlEditor.js"></script>
    </head>
    <body><form name="my_form">
    <div style="width: 600px; height: 280px">
    <div id="toolBar" style="background-color:#d0d0d0; width: 100%;height:8%;"></div>
    <div id="menu"></div><IFRAME id="Editor" style="width:100%;height:92%"></IFRAME>
    </div>
    <SCRIPT language=javascript>
    function initEdit(Editor)
    {
       Editor.document.designMode="On";
    }
    initEdit(Editor);
    var editorInit=new htmlEditor("aa");
    editorInit.init();
    </SCRIPT>
    </form>
    </body>
    </html>
      

  4.   


     /*------------------issue detail page-------------------*/
    .issueDetailToolbarButton
    {
      border-top: 1px solid #d0d0d0;
      border-left: 1px solid #d0d0d0;
      border-bottom: 1px solid #d0d0d0;
      border-right: 1px solid #d0d0d0;
    }.issueDetailToolbarButtonRaised
    {
    border-top: 1px solid #0080FF;
    border-left: 1px solid #0080FF;
    border-bottom: 1px solid #0080FF;
    border-right: 1px solid #0080FF;
    background-color: #D2E9FF;
    }.issueDetailToolbarButtonPressed
    {
    border-top: 1px solid #0080FF;
    border-left: 1px solid #0080FF;
    border-bottom: 1px solid #0080FF;
    border-right: 1px solid #0080FF;
    background-color: #D2E9FF;
    }