日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

使用MemberShip,Profile时碰上的一些问题

發(fā)布時(shí)間:2025/3/19 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用MemberShip,Profile时碰上的一些问题 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.????? 使用Profile.GetProfile(string username)時(shí)碰上的問(wèn)題<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

我想在一個(gè)頁(yè)面里編輯任意一個(gè)MemberShipUserProfile,這時(shí)我使用了頁(yè)面.Profile.GetProfile(username),由于能登陸到這個(gè)頁(yè)面的用戶都是具有權(quán)限的用戶,所以運(yùn)行的時(shí)候一切正常,為了優(yōu)化代碼,我要把操作Profile的代碼移動(dòng)到后臺(tái)自己定義的類里,這時(shí)候已經(jīng)不存在頁(yè)面類的實(shí)例,所以我要使用HttpContext.Current.Profile來(lái)代替Page.Profile 這時(shí)候問(wèn)題出現(xiàn)了,HttpContext.Current.Profile里不存在GetProfile(string username)這個(gè)方法,仔細(xì)看一下 原來(lái)這兩個(gè)Profile是來(lái)之不同的類,Page.ProfileProfileComm的實(shí)例,而HttpContext.Current.ProfileProfilebase的實(shí)例,最后找到得到GetProfile的方法是這樣的:

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

而這里的username,一定是要一個(gè)通過(guò)認(rèn)證的membershipuser,這時(shí)候在使用pc.GetProfile(“otherusername”) 就可以對(duì)其他用戶的Profile進(jìn)行編輯了。

2.????? 使用MembershipUser.ChangePassword碰上的問(wèn)題

我自定義了一個(gè)添加,修改,刪除Membership用戶的控件,要使用到修改密碼的功能,MembershipUser里有一個(gè)ChangePassword的方法,不過(guò)需要兩個(gè)參數(shù),oldpasswordnewpassword,由于我需要一個(gè)修改密碼而不用提供舊密碼的功能,所以就要先把用戶的老密碼給找出來(lái),幸運(yùn)的發(fā)現(xiàn)在MembershipUser下有一個(gè)GetPassword的方法,立即調(diào)用彈出異常,看了異常的說(shuō)明繼續(xù)找問(wèn)題,發(fā)現(xiàn)問(wèn)題出在 Membership Provider的配置參數(shù)上,

?

??? <membership defaultProvider="herSqlMembershipProvider">

????? <providers>

??????? <add name="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主要涉及到三個(gè)屬性: passwordFormat, requiresQuestionAndAnswer, enablePasswordRetrieval,首先需要把enablePasswordRetrieval設(shè)置為true,可以回收密碼,然后是passwordFormat可以設(shè)置三個(gè)值:Clear, Encrypted, and Hashed,如果設(shè)置成了Hashed,那密碼是不可逆的,也不能得到密碼,而ClearEncrypted都是可以的,Clear是明文保存,而Encrypted是加密保存,如果設(shè)置成了加密保存,還需要設(shè)置一些密鑰什么的,不然CreateUser時(shí)會(huì)出錯(cuò),最后是屬性requiresQuestionAndAnswer,它是表示是否需要有密碼問(wèn)題和答案來(lái)重新取回密碼的機(jī)制,如果這個(gè)設(shè)置為true,那么你在使用GetPassword時(shí),需要把這個(gè)用戶的問(wèn)題的答案一起傳進(jìn)去,不然也會(huì)產(chǎn)生異常。

3.????? 匿名訪問(wèn)時(shí)設(shè)置Profile屬性出現(xiàn)異常

這也是需要配置文件里的屬性進(jìn)行配置:

??? <anonymousIdentification enabled="true" />

??? <profile defaultProvider="herSqlProfile">

????? <providers>

??????? <add name="herSqlProfile" type="System.Web.Profile.SqlProfileProvider" connectionStringName="her" />

????? </providers>

????? <properties>

??????? <add name="MyTheme" type="String" allowAnonymous="true"/>

????? </properties>

</profile>

首先是anonymousIdentification enbaled設(shè)置為true,然后再profile里的屬性allowAnonymous="true"

轉(zhuǎn)載于:https://www.cnblogs.com/dotLive/archive/2007/03/15/676112.html

與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的使用MemberShip,Profile时碰上的一些问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。