您好,登錄后才能下訂單哦!
本篇文章為大家展示了ASP.NET中Membership的作用是什么,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
在本地開發(fā)一個ASP.NET2.0的應(yīng)用程序時使用了Membership、Roles或Profile特性。你創(chuàng)建了ASP.NET一些新用戶,一切都沒有問題。
然后把這個程序copy到遠(yuǎn)程服務(wù)器(remote server)上(或者只是移動到你本地服務(wù)器上的其他目錄)然后運(yùn)行。由于某種原因,雖然我們能夠連接到Membership數(shù)據(jù)庫,但是當(dāng)?shù)顷懙臅r候就會出現(xiàn)錯誤了,它并不拋出連接錯誤(connection error),而是提示你像類似的錯誤:“嘗試登陸失敗,請重試”(Login attempt unsuccessful, please try again)
原因:
這種經(jīng)常出現(xiàn)的錯誤的原因是因為Membership(或者是roles、profile) provider已經(jīng)被加入到了程序的web.config里了。但是applicationName屬性(attribute)并沒有被指定(假設(shè)下面的代碼的粗體部分布存在地話)
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
applicationName="/"
/>
</providers>
</membership>
如果它被copy到其他的地方或服務(wù)器上并且更換了虛擬路徑(比如說“/app1” 或更通常被設(shè)置的“/”)后,當(dāng)Membership APIs被使用時他們就“看”不到數(shù)據(jù)庫里已有的用戶了——因為他們將會使用一個不同的applicationName去數(shù)據(jù)庫里尋找用戶,相應(yīng)地過濾 application_Users表中的用戶。這就是為什么會出現(xiàn)上面錯誤的原因。
如何解決這個問題:
最簡單的辦法是打開ASPNETDB數(shù)據(jù)庫中的aspnet_Users和aspnet_Application表,去“回想”(figure out,因為那時候我們的虛擬目錄叫什么名字我們恐怕已經(jīng)忘了)創(chuàng)建用戶和其他數(shù)據(jù)的時候的程序名稱(去aspnet_Application表中查找)
然后打開你的web.config文件,添加一個applicationName屬性到provider聲明的地方并且給他賦值,例如,下面的代碼我們把它設(shè)置為在aspnet_Application表存在的/website8:
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
applicationName="/website8"
/>
</providers>
</membership>
上述內(nèi)容就是ASP.NET中Membership的作用是什么,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。