dotnetnuke|dnn 内网实现自动登录

2015/08/27 13:23
阅读数 148

Imports DotNetNuke.Services.Authentication          
 Imports DotNetNuke.Services.Authentication          
            If Request.Cookies("NotFirstTime") Is Nothing Then
                Dim objUser As UserInfo
                objUser = New UserInfo
                If UserController.GetCurrentUserInfo.Username = "" Then
                    '判断是否是内部IP
                    Dim IPAdd As String
                    IPAdd = HttpContext.Current.Request.UserHostAddress
                    Dim myIP(4) As String
                    myIP = IPAdd.Split(".")
                    Dim x(4) As Int32
                    x(0) = Convert.ToInt32(myIP(0))
                    x(1) = Convert.ToInt32(myIP(1))
                    x(2) = Convert.ToInt32(myIP(2))
                    x(3) = Convert.ToInt32(myIP(3))
                    Dim IsInSchool As Boolean
                    IsInSchool = False
                    If x(0) = 10 Then
                        IsInSchool = True
                    End If
                    If x(0) = 172 Then
                        If x(1) >= 16 And x(1) < 31 Then
                            IsInSchool = True
                        End If
                    End If
                    If x(0) = 192 Then
                        If x(1) = 168 Then
                            IsInSchool = True
                        End If
                    End If
                    If x(0) = 127 Then
                        IsInSchool = True
                    End If

                        If IsInSchool = True Then
                        AuthenticationController.SetAuthenticationType(ViewState("AuthenticationType"))
                        objUser.Username = "InnerUser"
                        UserController.UserLogin(Me.PortalSettings.PortalId, objUser, PortalSettings.PortalName,

AuthenticationLoginBase.GetIPAddress(), 1)
                        UserController.UpdateUser(Me.PortalSettings.PortalId, objUser)
                        Response.Redirect(Request.Url.ToString())
                    End If
                End If

                Dim newCookie As HttpCookie
                newCookie = New HttpCookie(1)
                newCookie.Name = "NotFirstTime"
                newCookie.Value = "MoreThanOneTimesLoading"
                newCookie.Expires = System.DateTime.Now.AddSeconds(30)
                Response.Cookies.Add(newCookie)
            End If

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部