C# 自定义会员资格提供商赢得';t重定向

C# 自定义会员资格提供商赢得';t重定向,c#,asp.net-mvc,membership-provider,custom-membershipprovider,C#,Asp.net Mvc,Membership Provider,Custom Membershipprovider,我已经设置了一个自定义的成员资格和角色提供程序,但它当前没有正常工作。我怀疑我错过了什么,但通过我所有的研究,我一直无法弄清楚它是什么 出现的问题是,当我输入正确的登录详细信息时,登录页面将重新加载,而不是重定向。我怀疑它正在重定向,但由于某种原因,它不记得授权已被批准,因此它会将用户发送回登录页面。然后,这只是在一个恼人的循环中不断重复 这是我的web.config <connectionStrings> <add name="DefaultConnection" conne

我已经设置了一个自定义的成员资格和角色提供程序,但它当前没有正常工作。我怀疑我错过了什么,但通过我所有的研究,我一直无法弄清楚它是什么

出现的问题是,当我输入正确的登录详细信息时,登录页面将重新加载,而不是重定向。我怀疑它正在重定向,但由于某种原因,它不记得授权已被批准,因此它会将用户发送回登录页面。然后,这只是在一个恼人的循环中不断重复

这是我的web.config

<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-BoomtickVenueEvents-20130313220611;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-BoomtickVenueEvents-20130313220611.mdf" providerName="System.Data.SqlClient" />
<add name="BoomtickVenueEventsDBContext" connectionString="Data Source=EAN-PC;Initial Catalog=BoomtickVenueEventsDB;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
...
<system.web>
<globalization uiCulture="en-AU" culture="en-AU" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<membership defaultProvider="CustomMembershipProvider" userIsOnlineTimeWindow="15">
  <providers>
    <add name="CustomMembershipProvider" type="BoomtickVenueEvents.Providers.VOMembershipProvider" 
         connectionStringName="AuthenticationService"
         enablePasswordRetrieval="false"
         enablePasswordReset="true"
         requiresQuestionAndAnswer="false"
         applicationName="/"
         requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="5"
         minRequiredPasswordLength="7"
         minRequiredNonalphanumericCharacters="0"
         passwordAttemptWindow="10" />
  </providers>
</membership>
<roleManager defaultProvider="CustomRoleProvider" enabled="true" cacheRolesInCookie="false">
  <providers>
    <clear />
    <add name="CustomRoleProvider" type="BoomtickVenueEvents.Providers.VORoleProvider" />
  </providers>
</roleManager>
<pages>
  <namespaces>
    <add namespace="System.Web.Helpers" />
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Optimization" />
    <add namespace="System.Web.Routing" />
    <add namespace="System.Web.WebPages" />
  </namespaces>
</pages>

...

我的自定义成员资格提供程序如下

using EventOracle.Data.Interfaces;
using EventOracle.Domain.Models;
using System;
using System.ServiceModel;
using System.Web.Security;

namespace BoomtickVenueEvents.Providers
{
    public class VOMembershipProvider : MembershipProvider
    {
        private static ISecurityProviderService _voData;

        #region Constructors
        /// <summary>
        /// Constructor that connects to the Database Service and sets a refference point to the service
        /// </summary>
        public VOMembershipProvider()
        {
            ChannelFactory<ISecurityProviderService> VODataFactory;
            NetTcpBinding tcpBinding = new NetTcpBinding();

            // Set the allowable message sizes
            tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue;
            //tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue;

            // Set a string to the URL of the server
            string sURL = "net.tcp://localhost:50001/SecurityProviderService";

            try
            {
                // Instantiate the channel factory using the string pointing to the server location
                VODataFactory = new ChannelFactory<ISecurityProviderService>(tcpBinding, sURL);

                // Start the channel factory
                _voData = VODataFactory.CreateChannel();
            }
            catch (Exception ex)
            {
                // Display the error message to the user
                Console.WriteLine(ex.Message);
            }
        }
        #endregion // Constructors

        public override string ApplicationName
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
                throw new System.NotImplementedException();
            }
        }

        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            throw new System.NotImplementedException();
        }

        public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
        {
            throw new System.NotImplementedException();
        }

        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            throw new System.NotImplementedException();
        }

        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            throw new System.NotImplementedException();
        }

        public override bool EnablePasswordReset
        {
            get { throw new System.NotImplementedException(); }
        }

        public override bool EnablePasswordRetrieval
        {
            get { throw new System.NotImplementedException(); }
        }

        public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new System.NotImplementedException();
        }

        public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new System.NotImplementedException();
        }

        public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            throw new System.NotImplementedException();
        }

        public override int GetNumberOfUsersOnline()
        {
            throw new System.NotImplementedException();
        }

        public override string GetPassword(string username, string answer)
        {
            throw new System.NotImplementedException();
        }

        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            User user = _voData.GetUser(username);
            if (user != null)
            {
                MembershipUser memUser = new MembershipUser("CustomMembershipProvider", 
                                                                username, user.UserId, user.Email,
                                                                string.Empty, string.Empty, true,
                                                                false, DateTime.MinValue, DateTime.MinValue,
                                                                DateTime.MinValue, DateTime.Now, DateTime.Now);
                return memUser;
            }
            return null;
        }

        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            throw new System.NotImplementedException();
        }

        public override string GetUserNameByEmail(string email)
        {
            throw new System.NotImplementedException();
        }

        public override int MaxInvalidPasswordAttempts
        {
            get { throw new System.NotImplementedException(); }
        }

        public override int MinRequiredNonAlphanumericCharacters
        {
            get { throw new System.NotImplementedException(); }
        }

        public override int MinRequiredPasswordLength
        {
            get { throw new System.NotImplementedException(); }
        }

        public override int PasswordAttemptWindow
        {
            get { throw new System.NotImplementedException(); }
        }

        public override MembershipPasswordFormat PasswordFormat
        {
            get { throw new System.NotImplementedException(); }
        }

        public override string PasswordStrengthRegularExpression
        {
            get { throw new System.NotImplementedException(); }
        }

        public override bool RequiresQuestionAndAnswer
        {
            get { throw new System.NotImplementedException(); }
        }

        public override bool RequiresUniqueEmail
        {
            get { throw new System.NotImplementedException(); }
        }

        public override string ResetPassword(string username, string answer)
        {
            throw new System.NotImplementedException();
        }

        public override bool UnlockUser(string userName)
        {
            throw new System.NotImplementedException();
        }

        public override void UpdateUser(MembershipUser user)
        {
            throw new System.NotImplementedException();
        }

        public override bool ValidateUser(string username, string password)
        {
            return _voData.ValidateUser(username, password);
        }
    }
}
namespace BoomtickVenueEvents.Controllers
{
    [Authorize]
    [InitializeSimpleMembership]
    public class AccountController : Controller
    {

        private static ISecurityProviderService _voData;

        #region Constructors
        /// <summary>
        /// Constructor that connects to the Database Service and sets a refference point to the service
        /// </summary>
        public AccountController()
        {
            ChannelFactory<ISecurityProviderService> VODataFactory;
            NetTcpBinding tcpBinding = new NetTcpBinding();

            // Set the allowable message sizes
            tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue;
            //tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue;

            // Set a string to the URL of the server
            string sURL = "net.tcp://localhost:50001/AuthoriseService";

            try
            {
                // Instantiate the channel factory using the string pointing to the server location
                VODataFactory = new ChannelFactory<ISecurityProviderService>(tcpBinding, sURL);

                // Start the channel factory
                _voData = VODataFactory.CreateChannel();
            }
            catch (Exception ex)
            {
                // Display the error message to the user
                Console.WriteLine(ex.Message);
            }
        }
        #endregion // Constructors

        //
        // GET: /Account/Login

        [AllowAnonymous]
        public ActionResult Login(string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            return View();
        }

        //
        // POST: /Account/Login

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && Membership.ValidateUser(model.UserName, model.Password))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }

        //
        // POST: /Account/LogOff

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult LogOff()
        {
            WebSecurity.Logout();

            return RedirectToAction("Index", "Home");
        }
使用EventOracle.Data.Interfaces;
使用EventOracle.Domain.Models;
使用制度;
使用System.ServiceModel;
使用System.Web.Security;
命名空间:VenueEvents.Providers
{
公共类VOMembershipProvider:MembershipProvider
{
私有静态ISecurityProviderService_voData;
#区域构造函数
/// 
///连接到数据库服务并设置服务引用点的构造函数
/// 
公共成员资格提供程序()
{
渠道工厂-沃达工厂;
NetTcpBinding=新的NetTcpBinding();
//设置允许的消息大小
tcpBinding.MaxReceivedMessageSize=System.Int32.MaxValue;
//tcpBinding.ReaderQuotas.MaxArrayLength=System.Int32.MaxValue;
//将字符串设置为服务器的URL
string sURL=“net。tcp://localhost:50001/SecurityProviderService";
尝试
{
//使用指向服务器位置的字符串实例化通道工厂
Vodata工厂=新渠道工厂(tcpBinding,sURL);
//启动渠道工厂
_voData=VODataFactory.CreateChannel();
}
捕获(例外情况除外)
{
//向用户显示错误消息
控制台写入线(例如消息);
}
}
#endregion//构造函数
公共重写字符串ApplicationName
{
得到
{
抛出新系统。NotImplementedException();
}
设置
{
抛出新系统。NotImplementedException();
}
}
public override bool ChangePassword(字符串username、字符串oldPassword、字符串newPassword)
{
抛出新系统。NotImplementedException();
}
公共覆盖bool ChangePasswordQuestionAndAnswer(字符串用户名、字符串密码、字符串newPasswordQuestion、字符串newPasswordAnswer)
{
抛出新系统。NotImplementedException();
}
public override MembershipUser CreateUser(字符串用户名、字符串密码、字符串电子邮件、字符串密码问题、字符串密码答案、bool已批准、对象提供程序UserKey、out MembershipCreateStatus状态)
{
抛出新系统。NotImplementedException();
}
公共覆盖bool DeleteUser(字符串用户名,bool deleteAllRelatedData)
{
抛出新系统。NotImplementedException();
}
公共覆盖布尔启用密码重置
{
获取{抛出新系统。NotImplementedException();}
}
公共覆盖布尔启用密码检索
{
获取{抛出新系统。NotImplementedException();}
}
public override MembershipUserCollection FindUserByEmail(字符串emailToMatch、int pageIndex、int pageSize、out int totalRecords)
{
抛出新系统。NotImplementedException();
}
public override MembershipUserCollection FindUserByName(字符串UserName匹配、int pageIndex、int pageSize、out int totalRecords)
{
抛出新系统。NotImplementedException();
}
公共覆盖MembershipUserCollection GetAllUsers(int-pageIndex、int-pageSize、out-int-totalRecords)
{
抛出新系统。NotImplementedException();
}
公共覆盖int GetNumberOfUsersOnline()
{
抛出新系统。NotImplementedException();
}
公共重写字符串GetPassword(字符串用户名、字符串答案)
{
抛出新系统。NotImplementedException();
}
公共覆盖成员身份用户GetUser(字符串用户名,bool userIsOnline)
{
User User=\u voData.GetUser(用户名);
如果(用户!=null)
{
MembershipUser memUser=新成员身份用户(“CustomMembershipProvider”,
用户名,user.UserId,user.Email,
string.Empty,string.Empty,true,
false、DateTime.MinValue、DateTime.MinValue、,
DateTime.MinValue,DateTime.Now,DateTime.Now);
返回memUser;
}
返回null;
}
公共覆盖成员身份用户GetUser(对象提供程序UserKey,bool userIsOnline)
{
抛出新系统。NotImplementedException();
}
公共重写字符串GetUserNameByEmail(字符串电子邮件)
{
抛出新系统。NotImplementedException();
}
公共覆盖int MaxInvalidPasswordAttempts
{
获取{抛出新系统。NotImplementedException();}
}
public override int minrequired非字母数字字符
{
获取{抛出新系统。NotImplementedException();}
}
公共覆盖int MinRequiredPasswordLength
if (ModelState.IsValid && Membership.ValidateUser(model.UserName, model.Password))
{
    FormsAuthentication.SetAuthCookie( model.UserName, false );
    return RedirectToLocal(returnUrl);
}