dotnetnuke|dnn 内网实现自动登录

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

 

你可能感兴趣的:(String,dotnetnuke)