溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ASP.NET中Membership的作用是什么

發(fā)布時間:2021-07-15 15:15:58 來源:億速云 閱讀:123 作者:Leah 欄目:編程語言

本篇文章為大家展示了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è)下面的代碼的粗體部分布存在地話)

  1. <membership> 

  2. <providers> 

  3. <clear/> 

  4. <add name="AspNetSqlMembershipProvider" 

  5. type="System.Web.Security.SqlMembershipProvider, System.Web, 
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
     

  6. connectionStringName="LocalSqlServer" 

  7. enablePasswordRetrieval="false" 

  8. enablePasswordReset="true" 

  9. requiresQuestionAndAnswer="true" 

  10. requiresUniqueEmail="false" 

  11. passwordFormat="Hashed" 

  12. maxInvalidPasswordAttempts="5" 

  13. minRequiredPasswordLength="7" 

  14. minRequiredNonalphanumericCharacters="1" 

  15. passwordAttemptWindow="10" 

  16. passwordStrengthRegularExpression="" 

  17. applicationName="/" 

  18. /> 

  19. </providers> 

  20. </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:

  1. <membership> 

  2. <providers> 

  3. <clear/> 

  4. <add name="AspNetSqlMembershipProvider" 

  5. type="System.Web.Security.SqlMembershipProvider, System.Web, 
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
     

  6. connectionStringName="LocalSqlServer" 

  7. enablePasswordRetrieval="false" 

  8. enablePasswordReset="true" 

  9. requiresQuestionAndAnswer="true" 

  10. requiresUniqueEmail="false" 

  11. passwordFormat="Hashed" 

  12. maxInvalidPasswordAttempts="5" 

  13. minRequiredPasswordLength="7" 

  14. minRequiredNonalphanumericCharacters="1" 

  15. passwordAttemptWindow="10" 

  16. passwordStrengthRegularExpression="" 

  17. applicationName="/website8" 

  18. /> 

  19. </providers> 

  20. </membership> 

上述內(nèi)容就是ASP.NET中Membership的作用是什么,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(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)容。

AI