Some problems encountered when using MemberShip, Profile

1.       Problems encountered when using Profile.GetProfile(string username) <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I want to edit the Profile of any MemberShip User in a page . At this time, I use page.Profile.GetProfile (username), because the users who can log in to this page are all users with permissions, so everything works fine when running , In order to optimize the code, I want to move the code that operates the Profile to the class defined by myself in the background. At this time, there is no instance of the page class, so I want to use HttpContext.Current.Profile instead of Page.Profile At this time, the problem occurs , There is no GetProfile(string username) method in HttpContext.Current.Profile . Take a closer look at the original two Profiles from different classes. Page.Profile is an instance of ProfileComm , and HttpContext.Current.Profile is Profilebase . Instance, finally found to get GetProfile The method is this:

ProfileCommon pc = (ProfileCommon)ProfileBase.Create(username, true);

The username here must be a user who has passed the authentication membership . At this time, you can use pc.GetProfile("otherusername") to edit the profiles of other users .

2.       Problems encountered with MembershipUser.ChangePassword

I have customized a control for adding, modifying, and deleting Membership users. To use the function of changing passwords, MembershipUser has a ChangePassword method, but it requires two parameters, oldpassword and newpassword, because I need a password change and do not need to provide it The function of the old password, so we must first find out the old password of the user. Fortunately, we found that there is a GetPassword method under MembershipUser . Immediately call the pop-up exception, read the description of the exception and continue to find the problem, and found that the problem lies in the Membership Provider . on the configuration parameters,

 

    <membershipdefaultProvider="herSqlMembershipProvider">

      <providers>

        <addname="herSqlMembershipProvider"type="System.Web.Security.SqlMembershipProvider"requiresQuestionAndAnswer="false" connectionStringName="her"requiresUniqueEmail="false"passwordFormat="Clear"minRequiredPasswordLength="3"enablePasswordRetrieval="true"

             minRequiredNonalphanumericCharacters="0"passwordAttemptWindow="10"passwordStrengthRegularExpression=""applicationName="/ " />

      </providers>

</membership>

 

GetPassword mainly involves three properties : passwordFormat, requiresQuestionAndAnswer, enablePasswordRetrieval, first you need to set enablePasswordRetrieval to true, you can recycle the password, and then passwordFormat can set three values: Clear, Encrypted, and Hashed, if it is set to Hashed , then the password It is irreversible, and the password cannot be obtained, but both Clear and Encrypted are possible. Clear is stored in plain text, while Encrypted is encrypted storage. If it is set to encrypted storage, you need to set some keys or something, otherwise CreateUser will make an error. , and finally the attribute requiresQuestionAndAnswer , which is a mechanism to indicate whether a password question and answer is required to retrieve the password. If this is set to true, then when you use GetPassword , you need to pass in the answer to the user's question, otherwise An exception will also be generated.

3.       An exception occurs when setting the Profile property during anonymous access

This is also required to configure the properties in the configuration file:

    <anonymousIdentificationenabled="true" />

    <profiledefaultProvider="herSqlProfile">

      <providers>

        <addname="herSqlProfile"type="System.Web.Profile.SqlProfileProvider"connectionStringName="her" />

      </providers>

      <properties>

        <addname="MyTheme"type="String"allowAnonymous="true"/>

      </properties>

</profile>

The first is anonymousIdentification to set enbaled to true, and then the attribute allowAnonymous="true" in the profile

Reprinted in: https://www.cnblogs.com/dotLive/archive/2007/03/15/676112.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324110795&siteId=291194637