Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 异常详细信息:System.Security.SecurityException:指定的登录会话不存在。它可能已经被终止了_C#_Asp.net_Iis_Securityexception - Fatal编程技术网

C# 异常详细信息:System.Security.SecurityException:指定的登录会话不存在。它可能已经被终止了

C# 异常详细信息:System.Security.SecurityException:指定的登录会话不存在。它可能已经被终止了,c#,asp.net,iis,securityexception,C#,Asp.net,Iis,Securityexception,我已将测试web应用部署到虚拟Windows server 2008 std。IIS没有为此应用或此服务器上部署的任何应用分配证书功能,因此我发现的任何解决方案都与我的问题无关。同一服务器上的所有其他应用都工作正常,这让我得出结论,问题一定是我在global.asax文件中用于身份验证的代码 我已检查gpedit.msc和网络访问:不允许存储凭据已被禁用。是最接近我的问题,我已经能够找到,但没有解决方案被接受。我已经检查了MMC,但是里面除了一个空的控制台根节点之外没有任何东西,所以没有任何东西

我已将测试web应用部署到虚拟Windows server 2008 std。IIS没有为此应用或此服务器上部署的任何应用分配证书功能,因此我发现的任何解决方案都与我的问题无关。同一服务器上的所有其他应用都工作正常,这让我得出结论,问题一定是我在global.asax文件中用于身份验证的代码

我已检查gpedit.msc和网络访问:不允许存储凭据已被禁用。是最接近我的问题,我已经能够找到,但没有解决方案被接受。我已经检查了MMC,但是里面除了一个空的控制台根节点之外没有任何东西,所以没有任何东西可以删除和重新安装,正如一些人建议和建议的那样。我不能从工作中访问博客网站,有些听起来很有希望,但我看不懂。我将完全信任添加到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());
        }

    }  
我阅读了这篇文章,重点是他的评论“1.确定请求哪些权限导致应用程序抛出,并尝试修改应用程序,使其不再需要这些权限。正在抛出的SecurityException应该告诉您哪个请求 失败了

我从Global.asax中完全删除了授权代码,将其移动到Default.aspx.cs。我用名为
CheckGroupMembership()的新方法中建议的混合代码替换了引发错误的
IsInADGroup(x,y)
方法。
我实例化了一个全局数组变量
groupName[]
包含我想要检查成员资格的三个广告组,最终这些值
IsMember[]
被传递到会话变量,以便可以在另一个页面上使用。解决方案的核心是此方法:需要命名空间
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;
                }
            }
        }
    }
public void CheckGroupMembership()
{
//设置域上下文
PrincipalContext ctx=新PrincipalContext(ContextType.Domain,“XXX”);
//查找用户
UserPrincipal user=UserPrincipal.FindByIdentity(ctx,GetUserName());
对于(int i=0;i<3;i++)
{
//找到有问题的组
GroupPrincipal group=GroupPrincipal.FindByIdentity(ctx,groupName[i]);
如果(用户!=null)
{
//检查用户是否是该组的成员
if(用户IsMemberOf(组))
{ 
IsMember[i]=真;
}
其他的
{
IsMember[i]=假;
}
}
}
}