DotNetNuke与MemberShip的结合(五年版)第三步修改HttpModule.DNNMembership

DotNetNuke与MemberShip的结合(五年版)

第一步:实装基于现有membership的DNN
http://www.cnblogs.com/shiningrise/archive/2007/08/13/854297.html

第二步:修改Provider.Membership.AspNetProvider登录方法, 添加membership用户到DNN数据库 (指原本没有的用户)

http://www.cnblogs.com/shiningrise/archive/2007/08/22/864685.html

第三步:修改HttpModule.DNNMembership,让非从DNN登录的用户转到DNN系统时, 添加membership用户到DNN数据库 (指原本没有的用户)

 

下面来写一下第三步.

拷贝 HttpModule.DNNMembership成新的DNNMembership为HttpModule.DNNMembershipFiveYears

新建一个方法

Private Function CreateDNNUser(ByRef user As UserInfo) As UserCreateStatus

 

Dim objSecurity As New PortalSecurity

Dim userName As String = objSecurity.InputFilter(user.Username, PortalSecurity.FilterFlag.NoScripting Or PortalSecurity.FilterFlag.NoAngleBrackets Or PortalSecurity.FilterFlag.NoMarkup)

Dim email As String = objSecurity.InputFilter(user.Email, PortalSecurity.FilterFlag.NoScripting Or PortalSecurity.FilterFlag.NoAngleBrackets Or PortalSecurity.FilterFlag.NoMarkup)

Dim lastName As String = objSecurity.InputFilter(user.LastName, PortalSecurity.FilterFlag.NoScripting Or PortalSecurity.FilterFlag.NoAngleBrackets Or PortalSecurity.FilterFlag.NoMarkup)

Dim firstName As String = objSecurity.InputFilter(user.FirstName, PortalSecurity.FilterFlag.NoScripting Or PortalSecurity.FilterFlag.NoAngleBrackets Or PortalSecurity.FilterFlag.NoMarkup)

Dim createStatus As UserCreateStatus = UserCreateStatus.Success

Dim displayName As String = objSecurity.InputFilter(user.DisplayName, PortalSecurity.FilterFlag.NoScripting Or PortalSecurity.FilterFlag.NoAngleBrackets Or PortalSecurity.FilterFlag.NoMarkup)

Dim updatePassword As Boolean = user.Membership.UpdatePassword

Dim isApproved As Boolean = user.Membership.Approved

 

Try

'下面这句有点东西在里面,大家自己看去

Dim dataProvider As DotNetNuke.Security.Membership.Data.DataProvider = DotNetNuke.Security.Membership.Data.DataProvider.Instance()

user.UserID = CType(dataProvider.AddUser(user.PortalID, userName, firstName, lastName, user.AffiliateID, user.IsSuperUser, email, displayName, updatePassword, isApproved), Integer)

Catch ex As Exception

'Clear User (duplicate User information)

user = Nothing

createStatus = UserCreateStatus.ProviderError

End Try

 

Return createStatus

 

End Function

修改Public Sub OnAuthenticateRequest(ByVal s As Object, ByVal e As EventArgs)方法

If Request.IsAuthenticated = True And Not _portalSettings Is Nothing Then

Dim arrPortalRoles() As String

Dim objRoleController As New RoleController

 

Dim objUser As UserInfo = UserController.GetCachedUser(_portalSettings.PortalId, Context.User.Identity.Name)

/******下面是新添加的******************************************/

Dim user As UserInfo = Nothing

user = objUser

If (user Is Nothing) Then

Dim username As String = Context.User.Identity.Name

user = New UserInfo

user.PortalID = _portalSettings.PortalId

user.Username = username

user.Email = username + "@163.com"

user.FirstName = username

user.LastName = username

user.DisplayName = username

 

Me.CreateDNNUser(user)

objUser = UserController.GetCachedUser(_portalSettings.PortalId, Context.User.Identity.Name)

End If

/************************************************/

修改web.config

        <!--<add name="DNNMembership" type="DotNetNuke.HttpModules.DNNMembershipModule, DotNetNuke.HttpModules.DNNMembership" /> -->

        <add name="DNNMembershipFiveYears" type="DotNetNuke.HttpModules.DNNMembershipModuleFiveYears, DotNetNuke.HttpModules.DNNMembershipFiveYears" />

DNN4.5.5

点击下载源码 

 

posted @ 2007-08-22 18:23  shiningrise  阅读(2237)  评论(3编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css