找不到formIdentity的Object

时间:2015-11-07 22:36:57

标签: c# asp.net entity-framework

我正在尝试根据我在login.aspx中创建的故障单设置验证请求但由于某种原因我收到错误代码如下

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        // Create an Identity object
        FormsIdentity identity = (FormsIdentity)Context.User.Identity;
        // When the ticket was created, the UserData property was assigned a
        // pipe delimited string of role names.
        string[] roles = identity.Ticket.UserData.Split(new char[] { ',' });
        String userData = identity.Ticket.UserData;
        // This principal will flow throughout the request.
        GenericPrincipal principal = new GenericPrincipal(identity, roles);
        // Attach the new principal object to the current HttpContext

    }

enter image description here

1 个答案:

答案 0 :(得分:0)

您必须从Application_AuthenticateRequest()转到管道中的下一个功能:

Application_AuthorizeRequest(object sender, EventArgs e)

在此阶段,应该完成Windows身份验证,因为Application_AuthenticateRequest()它仍然是null。有关管道订单的基本信息可以找到here和漂亮的可视化图表here

如果您使用IIS 7和asp.net 4.0运行,那么您应该调用所有登录请求:

Application_PostAuthenticateRequest() (object sender, EventArgs e)

,如example