προσπαθω να κατανοησω την λειτουργια του Membership και του Profile και θα ηθελα την αποψη σας στον κωδικα που εχω γραψει.
στο αρχειο Web.Config εχω το εξης
<authentication mode="Forms">
<forms name=".ASPXCookie" protection="All" timeout="30" path="/" cookieless="UseCookies" />
</authentication>
<authorization>
<allow users="*" />
</authorization>
<membership defaultProvider="MembershipProvider">
<providers>
<clear/>
<add name="MembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ConnectionString" applicationName="/"
minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" passwordFormat="Clear" enablePasswordRetrieval="true" requiresQuestionAndAnswer="false" />
</providers>
</membership>
<anonymousIdentification enabled="true" />
<profile defaultProvider="OdbcProvider" enabled="true">
<providers>
<clear />
<add name="OdbcProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ConnectionString" applicationName="/" />
</providers>
<properties>
<clear />
<add name="LangID" type="System.Int16" allowAnonymous="true" serializeAs="String" />
<add name="UserID" type="System.Int64" allowAnonymous="false" serializeAs="String" />
<add name="UserLevel" type="System.Int16" allowAnonymous="false" serializeAs="String" />
<add name="Firstname" type="System.String" allowAnonymous="false" serializeAs="String" />
<add name="Lastname" type="System.String" allowAnonymous="false" serializeAs="String" />
</properties>
</profile>
μεσα στην Global.asax το εξης
void Session_Start(object sender, EventArgs e) {
ProfileBase.Create(HttpContext.Current.Request.AnonymousID, false) as ProfileCommon;
//Ειναι σωστο αυτο που δημιουργω μονος μου το Profile για τους Anonymoys users???
}
στην Login.aspx σελιδα εχω τα εξης
if (Membership.ValidateUser(ebUsername.Text, Psw)) {
string userData = ProfileLib.LangID.ToString();
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(ebUsername.Text, cbRemember.Checked);
FormsAuthenticationTicket newTicket, ticket = FormsAuthentication.Decrypt(authCookie.Value);
newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, userData);
authCookie.Value = FormsAuthentication.Encrypt(newTicket);
Response.Cookies.Add(authCookie);
//Migrate Anonymous Profile
ProfileCommon anonProfile = (Profile as ProfileCommon).GetProfile(Request.AnonymousID);
Profile.Initialize(Username, true);
ProfileCommon Prof = Profile as ProfileCommon;
Prof.LangID = anonProfile.LangID;
Prof.UserID = UserID;
Prof.UserLevel = UserLevel;
Prof.Firstname = FirstName;
Prof.Lastname = LastName;
AnonymousIdentificationModule.ClearAnonymousIdentifier(); //εδω μου λεει πως "is not supported when the feature is disabled or the user is anonymous."
Response.Redirect("Default.aspx");
}
και στο Logout εχω τα εξης
FormsAuthentication.SignOut();
ProfileCommon Prof = Profile as ProfileCommon;
Int16 ALangID = Prof.LangID;
ProfileManager.DeleteProfile(Prof.UserName); //δεν μου κανει null το Profile
//δημιουργω νεο Profile για τον Anonymous User. Ειναι σωστο αυτό?
Prof = ProfileBase.Create(Request.AnonymousID, false) as ProfileCommon;
Prof.LangID = ALangID;
με λιγα λογια αυτο που θελω ειναι πως οταν ο χρηστης μπαινει στην σελιδα να μπορω να κραταω στο Profile του την μεταβλητη LangID. Οταν κανει Login να του την μεταφερω στο Authenticate Profile του και οταν κανει Logout να του δημιουργω Anonymoys Profile οπου θα κραταω την τιμη που ειχε η LangID. Ετσι οπως το εχω γραψει, ειναι ο σωστος τροπος??