2015-04-22 25 views
0

我已經開發出一種web portal,問題是沒有允許在同一時間多次登錄在ASP網站

它不允許在同一時間許多連接。當新用戶登錄時,以前的會話會自動銷燬。

我已經部署了該項目,但它是沒有用的,因爲它只允許一個用戶登錄。

這裏是我使用該connectionstring

<connectionstrings> 
    <add name="ABCConnectionString" connectionString="Data Source=435.632.653.322\SQLEXPRESS;Initial Catalog=ABC;User ID=sa;Password=abcabc" providerName="System.Data.SqlClient" /> 
    </connectionstrings> 

如果登錄成功的話,填充類:

Login_Info.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

/// <summary> 
/// Summary description for Login_Info 
/// </summary> 
public class Login_Info : System.Web.UI.Page 
{ 
    public Login_Info() 
    { 
     // 
     // TODO: Add constructor logic here 
     // 
    } 

    private string name; 

    public string Name 
    { 
     get { return HttpContext.Current.Application["name"] as string; } 
     set { HttpContext.Current.Application["name"] = value; } 
    } 

    private string empID; 

    public string EmpID 
    { 
     get { return HttpContext.Current.Application["empID"] as string; } 
     set { HttpContext.Current.Application["empID"] = value; } 
    } 

    private string role; 

    public string Role 
    { 
     get { return HttpContext.Current.Application["role"] as string; } 
     set { HttpContext.Current.Application["role"] = value; } 
    } 

    private string email; 

    public string Email 
    { 
     get { return HttpContext.Current.Application["email"] as string; } 
     set { HttpContext.Current.Application["Email"] = value; } 
    } 
} 

類填充是這樣的:

var login="from a in......."; 

    Session["portal"] = login.Email; 
         Role = login.role.ToString(); 
         Name = login.Name; 
         EmpID = login.ID.ToString(); 
         Email = login.Email; 
+1

您是否收到錯誤訊息?使用什麼登錄方法? – cederlof

+0

這裏有多種因素,您使用的是哪種身份驗證,是否有任何異常被拋出?你如何處理會議?這對我來說就像有一個靜態類,每當用戶登錄時都會被設置。 –

+0

@cederlof ...不,不會引發任何消息。 –

回答

1

您不應該爲此使用HttpContext.Current.Application,因爲它不是會話特定的,但可供每個客戶端使用。

根據MSDN

的應用程序的當前狀態,包括一個鍵/值字典,你可以用它來存儲兩個.NET框架 對象和標量值是應用程序範圍內的對象 的與來自多個客戶端的多個Web 請求相關。

如果您想以此方式進行身份驗證,請考慮使用HttpContext.Current.Session代替。

或者,看看一些適當的認證機制,如ASP.NET Identity

+0

它工作非常感謝... –

相關問題