找回密码
 立即注册
首页 业界区 业界 【Azure Services Platform Step by Step-第14篇】使用A ...

【Azure Services Platform Step by Step-第14篇】使用Azure

摹熹 2025-5-30 01:17:48
ASP.NET Application Providers相信大家都已经非常熟悉,它为我们开发ASP.NET应用程序提供了方便。
比如在Visual Studio控件工具箱中的Login部分,就是基于Membership provider、Session provider和Profile provider,大大地简化了我们在开发过程中处理与用户相关的功能。
1.png
 
(更多Provider的信息请查看http://msdn.microsoft.com/en-us/library/aa479030.aspx)

ASP.NET Provider架构示意图
2.png

 
ASP.NET Provider的类结构图
3.png
 
Azure Provider是什么
Azure上的应用程序也是ASP.NET 应用程序,所以它也支持ASP.NET 的Provider模型。不同的是,我们平时用的Provider是基于关系数据库的(如SQL Server),而“云端”上Provider自然也需要使用“云端”的数据解决方案——Windows Azure Storage。
云平台是基于分布式计算的。这就意味着,你的同一个应用程序可能会分布在不同的机器上。所以包括Session在内的各种用户数据不能放在host主机上,必须通过Windows Azure Storage来统一管理。
4.png

 
微软认为:基于Windows Azure Storage的provider 比传统SQL provider具有以下优势:
  在保持与SQL provider完全相同的使用方法(不用做任何代码修改)的基础上,
       
  • 并行处理更强悍。   
  • 分页查询更方便。   
  • 计算能力更牛X。   
  • 运行更稳定。
 
Azure Provider的原理
在Windows Azure SDK(March 2009 CTP)中,微软已经提供了可直接使用的Azure版ASP.NET Provider。包括membership, role,  profile,  session state 4种providers。
 
 
打开Azure版ASP.NET Provider项目,非常一目了然。以下的4个文件与4种provider一一对应。
5.png

拿TableStorageMembershipProvider来说,它其实是继承了MembershipProvider类(参照上文的provider类结构图),override了MembershipProvider类里与数据操作相关的方法,将它们换成使用Windows Azure Table Storage版本的。
  1. public class TableStorageMembershipProvider : MembershipProvider
复制代码
 
配置使用Azure  Provider
刚才说了,从传统的SQL Provder转换到使用Azure Provider,不用做任何代码上的改动,只需要更改配置文件就可以了。
下面是MemshipProvider的配置示例。(其他Provider也类似,请参考附件中的代码)
6.gif

7.gif

8.gif
     
9.gif

10.gif
       
11.gif

12.gif
       
13.gif

14.gif
type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageMembershipProvider"
15.gif

16.gif
            description="Membership provider using table storage"
17.gif

18.gif
            applicationName="roviderTest"
19.gif

20.gif
            tableServiceBaseUri=”your table service endpoint”
21.gif

22.gif
            allowInsecureRemoteEndpoints=”false”
23.gif

24.gif
            accountName="youraccountname"
25.gif

26.gif
sharedKey="yoursharedkey"
27.gif

28.gif
            membershipTableName="Membership"
29.gif

30.gif
            enablePasswordRetrieval="false"
31.gif

32.gif
            enablePasswordReset="true"
33.gif

34.gif
            requiresQuestionAndAnswer="false"
35.gif

36.gif
            minRequiredPasswordLength="1"
37.gif

38.gif
            minRequiredNonalphanumericCharacters="0"
39.gif

40.gif
            requiresUniqueEmail="true"
41.gif

42.gif
            passwordFormat="Hashed"
43.gif

44.gif
         />
45.gif

46.gif
      
47.gif

48.gif
    
49.gif
 
代码下载:
使用Azure Provider的示例代码:AspProvidersDemo.rar
Azure Provider源代码:AspProviders.rar
StorageClient:StorageClient.rar
______________________分割线____________________________________________________
 
 
Azure Provider的数据层面:

            Provider
            
            Storage
            
            Membership
            
            Table storage
            
            Profile 
            
            Table storage for storing management data
            Blob storage for storing the actual profile data
            
            Session state
            
            Table storage for storing management data
            Blob storage for storing the actual session state
            
            Role provider
            
            Table storage
            

Membership Table

            Column
            
            Type
            
            Comment
            
            Partition key
            
            String
            
            Concatenation of application name and user name
            
            Row key
            
            String
            
            Unused, empty string
            
            User name
            
            String
            
             
            
            User id
            
            Guid
            
             
            
            Password
            
            String
            
            Max 128 characters because of encode limitations
            
            Password format
            
            String
            
            .NET regular expression
            
            Password salt
            
            String
            
             
            
            Email
            
            String
            
             
            
            Password question
            
            String
            
             
            
            Password answer
            
            String
            
             
            
            IsApproved
            
            Bool
            
             
            
            IsAnonymous
            
            Bool
            
             
            
            IsLockedOut
            
            Bool
            
             
            
            CreateDate
            
            DateTime
            
            In UTC
            
            LastLoginDate
            
            DateTime
            
            In UTC
            
            LastPasswordChangeDate
            
            DateTime
            
            In UTC
            
            LastLockoutDate
            
            DateTime
            
            In UTC
            
            LastActivityDate
            
            DateTime
            
            In UTC
            
            FailedPasswordAttemptCount
            
            Int
            
             
            
            FailedPasswordAttemptWindowStart
            
            DateTime
            
            In UTC
            
            FailedPasswordAnswerAttemptCount
            
            Int
            
             
            
            FailedPasswordAnswerAttemptWindowStart
            
            DateTime
            
            In UTC
            
            Comment
            
            String
            
             
            
            ProfileLastUpdated
            
            DateTime
            
            In UTC
            
            ProfileBlobName
            
            String
            
            Blob where profile data is stored
            
            ProfileIsCreatedByProfileProvider
            
            Bool
            
             
            
            ProfileSize
            
            Int
            
            Size of profile data; saved to save roundtrips
            
 
Role Table

            Column
            
            Type
            
            Comment
            
            Partition key
            
            String
            
            Concatenation of application name and user name
            
            Row key
            
            String
            
            Role name
            
            Application name
            
            String
            
             
            
            User name
            
            String
            
             
            
            Role name
            
            String
            
             
            
 
Session State Table

            Column
            
            Type
            
            Comment
            
            Partition key
            
            String
            
            Application name + Session id
            
            Row key
            
            String
            
            Not used, empty string
            
            Id
            
            String
            
             
            
            Application name
            
            String
            
             
            
            Blob name
            
            String
            
            References session blob
            
            Timeout
            
            DateTime
            
             
            
            Expires
            
            DateTime
            
            In Utc
            
            Created
            
            DateTime
            
            In Utc
            
            Lock date
            
            DateTime
            
            In Utc
            
            Locked
            
            Bool
            
             
            
            Lock
            
            Int
            
             
            
            Initialized
            
            bool
            
             
            
 

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册