请求.IsAuthenticated不能与自定义成员资格提供程序一起工作

本文关键字:程序 一起 工作 不能 IsAuthenticated 自定义 成员 请求 | 更新日期: 2023-09-27 18:17:19

My login is. at controller

 MemberShipProvider objMProvider = new MemberShipProvider();
        var abc =RedirectToAction("Index", "Home");
        if (ModelState.IsValid)
        {
            var checkVal = objMProvider.ValidateUser(m.username, m.password);
            if (checkVal == true)
            {
                Session["User"] = m.username;
                TempData["userName"] = m.username;
                //IdentityHelper.RedirectToReturnUrl("~/User_Dashboard.aspx");
               abc=RedirectToAction("Dashboard","User");
            }
            else if (checkVal == false)
            {
                abc = RedirectToAction("Index", "Home");
                return abc;
            }
        }

my webconfig member setting…

 <system.web>
<membership defaultProvider="MemberShipProvider">
  <providers>
    <clear/>
    <add name="MemberShipProvider" type="FndooMvc.Models.Common.MemberShipProvider"
         connectionStringName="mycon"
         applicationName="/" />
  </providers>
</membership>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />

<system.webServer>
<modules>
  <remove name="FormsAuthentication" />
</modules>

我的自定义会员资格提供程序logincheck代码是public override bool ValidateUser(string username, string password) { return objLogin.IsValid(username,password) == true ? true : false; }我使用扁平登录代码,然后我决定根据需要使用自定义会员。帮助我使用这个自定义成员的身份和原则特性现在我想知道为什么我的请求。IsAuthenicated

请求.IsAuthenticated不能与自定义成员资格提供程序一起工作

看看这个:

ASP。NET身份识别系统是为了取代以前的asp.net身份识别系统而设计的。NET会员和简单会员系统。它包括配置文件支持、OAuth集成、与OWIN一起工作,并且包含在ASP中。. NET模板。

如果你想要一篇关于身份和原则的好文章

我需要这个代码块在全局配置中的认证请求事件。

 HttpCookie authCookie =Context.Request.Cookies[FormsAuthentication.FormsCookieName];
        if (authCookie != null)
        {
            FormsAuthenticationTicket authTicket =
                                        FormsAuthentication.Decrypt(authCookie.Value);
            string[] roles = authTicket.UserData.Split(new Char[] { ',' });
            GenericPrincipal userPrincipal =
                             new GenericPrincipal(new GenericIdentity(authTicket.Name),
                                                  roles);
            Context.User = userPrincipal;
        }

现在请求。isAuthenticated作品。

我将如何改变这个提供商,并使用Hboubati建议的