Login 在Umbraco 7上以编程方式登录成员

Login 在Umbraco 7上以编程方式登录成员,login,umbraco,umbraco7,Login,Umbraco,Umbraco7,我正在与之斗争。在Umbraco 6中,您可以使用以下工具轻松完成此操作: Member.AddMemberToCache( Member.GetMemberFromEmail(email), true, new TimeSpan(0, 30, 0) ); 我不希望在umbraco 7会员服务中找到相同的内容。在umbraco 7中,您可以使用umbraco.Web.Security.MembershipHelper类。 可通过继承自以下内容的视图中的成员属性访问其实例

我正在与之斗争。在Umbraco 6中,您可以使用以下工具轻松完成此操作:

Member.AddMemberToCache(
    Member.GetMemberFromEmail(email),
    true,
    new TimeSpan(0, 30, 0)
);

我不希望在umbraco 7会员服务中找到相同的内容。

在umbraco 7中,您可以使用umbraco.Web.Security.MembershipHelper类。
可通过继承自以下内容的视图中的成员属性访问其实例:

  • Umbraco.Web.Mvc.Umbraco模板页面
  • Umbraco.Web.Mvc.Umbraco查看页面
  • Umbraco.Web.Mvc.Umbraco查看页面
同样在继承自的控制器中:

  • Umbraco.Web.WebApi.UmbracoApiController
  • Umbraco.Web.Mvc.SurfaceController
以编程方式登录成员:
成员。登录(“用户名”、“密码”)
通过电子邮件拉取成员:
成员。GetByEmail(“电子邮件”);//返回IPPublishedContent

Umbraco.Web.Security.MembershipHelper类的完整公共界面:

  /// <summary> A helper class for handling Members </summary>
  public class MembershipHelper
  {
    public MembershipHelper(ApplicationContext applicationContext, HttpContextBase httpContext);
    public MembershipHelper(UmbracoContext umbracoContext);

    /// <summary> Returns true if the current membership provider is the Umbraco built-in one. </summary>
    public bool IsUmbracoMembershipProviderActive();

    /// <summary> Updates the currently logged in members profile </summary>
    /// <returns> The updated MembershipUser object </returns>
    public Attempt<MembershipUser> UpdateMemberProfile(ProfileModel model);

    /// <summary> Registers a new member </summary>
    /// <param name="model"/><param name="status"/>
    /// <param name="logMemberIn">true to log the member in upon successful registration </param>
    public MembershipUser RegisterMember(RegisterModel model, out MembershipCreateStatus status, bool logMemberIn = true);

    /// A helper method to perform the validation and logging in of a member - this is simply wrapping standard membership provider and asp.net forms auth logic.
    public bool Login(string username, string password);

    /// <summary> Logs out the current member </summary>
    public void Logout();

    public IPublishedContent GetByProviderKey(object key);
    public IPublishedContent GetById(int memberId);
    public IPublishedContent GetByUsername(string username);
    public IPublishedContent GetByEmail(string email);

    /// <summary> Returns the currently logged in member as IPublishedContent </summary>
    public IPublishedContent GetCurrentMember();

    /// <summary> Returns the currently logged in member id, -1 if they are not logged in </summary>
    public int GetCurrentMemberId();

    /// Creates a new profile model filled in with the current members details if they are logged in which allows for editing
    ///             profile properties
    public ProfileModel GetCurrentMemberProfileModel();

    /// Creates a model to use for registering new members with custom member properties
    public RegisterModel CreateRegistrationModel(string memberTypeAlias = null);

    /// Returns the login status model of the currently logged in member, if no member is logged in it returns null;
    public LoginStatusModel GetCurrentLoginStatus();

    /// <summary> Check if a member is logged in </summary>
    public bool IsLoggedIn();

    /// Returns true or false if the currently logged in member is authorized based on the parameters provided
    public bool IsMemberAuthorized(bool allowAll = false, IEnumerable<string> allowTypes = null, IEnumerable<string> allowGroups = null, IEnumerable<int> allowMembers = null);

    /// Changes password for a member/user given the membership provider and the password change model
    public Attempt<PasswordChangedModel> ChangePassword(string username, ChangingPasswordModel passwordModel, string membershipProviderName);
    public Attempt<PasswordChangedModel> ChangePassword(string username, ChangingPasswordModel passwordModel, MembershipProvider membershipProvider);
  }
///用于处理成员的帮助器类
公共类成员身份助手
{
公共成员身份助手(ApplicationContext ApplicationContext、HttpContextBase httpContext);
公共成员身份助手(UmbracoContext UmbracoContext);
///如果当前成员资格提供程序是Umbraco内置的,则返回true。
public bool Isumbraco Membership ProviderActive();
///更新当前登录的成员配置文件
///已更新的MembershipUser对象
公共尝试更新成员配置文件(ProfileModel);
///注册新会员
/// 
///如果为true,则在成功注册后登录该成员
public membership用户RegisterMember(RegisterModel,out-MembershipCreateStatus状态,bool-logMemberIn=true);
///执行成员验证和登录的助手方法-这只是包装标准成员资格提供程序和asp.net表单验证逻辑。
公共bool登录(字符串用户名、字符串密码);
///注销当前成员
公开作废注销();
public IPPublishedContent GetByProviderKey(对象密钥);
public-ippublishedcontent-GetById(int-memberId);
public ippublishedcontent GetByUsername(字符串用户名);
public ippublishedcontent GetByEmail(字符串电子邮件);
///将当前登录的成员返回为IPublishedContent
public IPPublishedContent GetCurrentMember();
///返回当前登录的成员id,-1(如果未登录)
public int GetCurrentMemberId();
///如果当前成员已登录,则创建一个新的配置文件模型,该模型将填充当前成员的详细信息,以便进行编辑
///剖面属性
公共配置文件模型GetCurrentMemberProfileModel();
///创建用于注册具有自定义成员属性的新成员的模型
公共注册表模型CreateRegistrationModel(字符串memberTypeAlias=null);
///返回当前登录成员的登录状态模型,如果没有成员登录,则返回null;
public LoginStatusModel GetCurrentLoginStatus();
///检查成员是否已登录
公共bool IsLoggedIn();
///如果当前登录的成员根据提供的参数获得授权,则返回true或false
public bool IsMemberAuthorized(bool allowAll=false,IEnumerable allowTypes=null,IEnumerable allowGroups=null,IEnumerable allowMembers=null);
///根据成员资格提供程序和密码更改模型更改成员/用户的密码
公共尝试更改密码(字符串用户名、更改密码模型passwordModel、字符串成员资格ProviderName);
公共尝试更改密码(字符串用户名、更改密码模型密码模型、成员资格提供程序成员资格提供程序);
}

谢谢,不久前我找到了一个解决方法,但这非常有用,我相信一些人会发现它很有用