簡體   English   中英

異常詳細信息:System.Security.SecurityException:指定的登錄會話不存在。 它可能已經終止了

[英]Exception Details: System.Security.SecurityException: A specified logon session does not exist. It may already have been terminated

我將測試Web應用程序部署到虛擬Windows Server 2008 std。 IIS沒有為此應用程序分配任何證書功能,也沒有為該服務器上部署的任何應用程序分配證書功能,因此我發現的解決方案均與我的問題無關。 同一台服務器上的所有其他應用程序都可以正常工作,這使我得出結論,問題一定出在我用來在global.asax文件中進行身份驗證的代碼上。

我檢查了gpedit.msc和網絡訪問權限:不允許存儲憑據已被禁用。 該帖子最接近我所能找到的問題,但未接受任何解決方案。 我已經檢查了MMC,但是除了空的Console Root節點之外,它什么也沒有,所以就像在這里這里所建議的那樣,沒有什么要刪除和重新安裝的。 我無法通過工作訪問博客網站-有些聽起來很有前途,但我看不懂。 我將完全信任添加到web.config中,這沒有什么區別,並指出IIS中的.NET信任級別已設置為完全(內部)。

完整的錯誤消息是:

System.Security.SecurityException: A specified logon session does not exist. It may already have been terminated.

   at System.Security.Principal.WindowsIdentity.KerbS4ULogon(String upn)
   at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName, String type)
   at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName)
   at EPRSystem.Global.IsInADGroup(String user, String group)
   at EPRSystem.Global.Application_AuthenticateRequest(Object sender, EventArgs e)
The Zone of the assembly that failed was:
MyComputer

對我有什么想法嗎?

這是我的全局代碼:

    public Boolean IsAdmin;
    public Boolean IsManager;
    public Boolean IsDeveloper;

    string UserName;

   public String GetUserName()
   {
        WindowsIdentity wiCurrentUser;
        wiCurrentUser = WindowsIdentity.GetCurrent();

        String strUserName = wiCurrentUser.Name;

        String[] strParts = strUserName.Split('\\');
        strUserName = strParts[1];  

        return strUserName; 
   }

   public Boolean IsInADGroup(string user, string group)
   {
       using (var identity = new WindowsIdentity(user))
       {
           var principal = new WindowsPrincipal(identity);

           return principal.IsInRole(group);
       }
   }   


    protected void Session_Start(object sender, EventArgs e)
    {
        //Write method: Get current user's username

        UserName = HttpContext.Current.User.Identity.Name; //get AD name of user

        HttpContext.Current.Session["UserName"] = GetUserName();

        HttpContext.Current.Session["IsAdmin"] = IsInADGroup(HttpContext.Current.Session["UserName"].ToString(), "group1");

        HttpContext.Current.Session["IsManager"] = IsInADGroup(HttpContext.Current.Session["UserName"].ToString(), "group2");

        HttpContext.Current.Session["IsDeveloper"] = IsInADGroup(HttpContext.Current.Session["UserName"].ToString(), "group3");  
    }


    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        //Write method: Identity/Authenticate current user

        DAL.ErrorLog oErrorLog = new DAL.ErrorLog();
        try
        {
            String strUser = GetUserName();

            IsAdmin = IsInADGroup(strUser, "group1");

            IsManager = IsInADGroup(strUser, "group2");

            IsDeveloper = IsInADGroup(strUser, "group3");
        }
        catch (System.Security.SecurityException ex)
        {
            oErrorLog.WriteErrorLog(ex.ToString());
        }

    }  

我閱讀了Shawn Farkas的這篇文章,重點關注他的評論“ 1. 確定要求什么權限導致您的應用程序拋出,並嘗試修改您的應用程序以不再需要這些權限。應該拋出的SecurityException告訴您哪個需求失敗。

我從Global.asax中完全刪除了授權代碼,將其移至Default.aspx.cs。 我取代IsInADGroup(x,y)的方法,其是其中產生錯誤,與所建議的代碼的混合物marc_s在稱為的新方法CheckGroupMembership(). 我實例化了一個全局數組變量groupName[]其中包含我要檢查其成員資格的三個AD組,最終將這些值IsMember[]傳遞給Session變量,以便可以在另一頁上使用它們。 解決方案的核心是這種方法:需要名稱空間System.DirectoryServices.AccountManagement

public void CheckGroupMembership()
    {
        // set up domain context
        PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "XXX");

        // find a user
        UserPrincipal user = UserPrincipal.FindByIdentity(ctx, GetUserName());

        for (int i = 0; i < 3; i++)
        {
            // find the group in question
            GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, groupName[i]);

            if (user != null)
            {
                // check if user is member of that group
                if (user.IsMemberOf(group))
                { 
                    IsMember[i] = true;  
                }
                else
                {
                    IsMember[i] = false;
                }
            }
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM