Dotnetnuke:修改Login控件实现登录后返回登录前页面

一.简介
  Login控件(~/admin/skins/login.ascx):该控件的作用就是在页面上提供一个login或logout的链接,让用户登录或登出网站;
  Account Login模块:处理登录逻辑.

二.Dotnetnuke原Login控件的不足
  1.若使用Dotnetnuke原来的Login控件,当用户点击Login跳转到登录页面后,发现登录页面只包含Account Login模块,不包含其它模块,不美观;
  2.新建的登录页面登录后无法正常返回登录前页面.

三.解决方法
  Account Login模块可处理returnurl传入参数,Account Login处理完登录逻辑后会返回returnurl指定的页面,若returnurl未指定,则跳回默认页面.
  若在跳往登录页面时传入returnurl参数,则可实现登录后返回登录前页面的功能.这里通过修改Login.ascx控件传入returnurl参数.

  修改后Login.ascx.cs代码如下(96-98为修改代码):

  1 None.gif Imports  DotNetNuke.Entities.Host
  2 None.gif
  3 ExpandedBlockStart.gifContractedBlock.gif Namespace DotNetNukeNamespace Namespace DotNetNukeNamespace DotNetNuke.UI.Skins.Controls
  4InBlock.gif    ''' -----------------------------------------------------------------------------
  5InBlock.gif    ''' <summary></summary>
  6InBlock.gif    ''' <remarks></remarks>
  7InBlock.gif    ''' <history>
  8InBlock.gif    '''     [smcculloch]10/15/2004    Fixed Logoff Link for FriendlyUrls
  9InBlock.gif    '''     [cniknet]    10/15/2004    Replaced public members with properties and removed
 10InBlock.gif    '''                             brackets from property names
 11InBlock.gif    ''' </history>
 12InBlock.gif    ''' -----------------------------------------------------------------------------
 13ExpandedSubBlockStart.gifContractedSubBlock.gif    Partial Class LoginClassClass LoginClass Login
 14InBlock.gif
 15InBlock.gif        Inherits UI.Skins.SkinObjectBase
 16InBlock.gif
 17InBlock.gif        ' public attributes
 18InBlock.gif        Private _text As String
 19InBlock.gif        Private _cssClass As String
 20InBlock.gif        Private _logoffText As String
 21InBlock.gif
 22InBlock.gif        Const MyFileName As String = "Login.ascx"
 23InBlock.gif
 24ContractedSubBlock.gifExpandedSubBlockStart.gifPublic MembersPublic Members#Region "Public Members"
 25ExpandedSubBlockStart.gifContractedSubBlock.gif        Public Property Text()Property Text()Property Text()Property Text() As String
 26InBlock.gif            Get
 27InBlock.gif                Return _text
 28InBlock.gif            End Get
 29InBlock.gif            Set(ByVal Value As String)
 30InBlock.gif                _text = Value
 31InBlock.gif            End Set
 32ExpandedSubBlockEnd.gif        End Property

 33InBlock.gif
 34ExpandedSubBlockStart.gifContractedSubBlock.gif        Public Property CssClass()Property CssClass()Property CssClass()Property CssClass() As String
 35InBlock.gif            Get
 36InBlock.gif                Return _cssClass
 37InBlock.gif            End Get
 38InBlock.gif            Set(ByVal Value As String)
 39InBlock.gif                _cssClass = Value
 40InBlock.gif            End Set
 41ExpandedSubBlockEnd.gif        End Property

 42InBlock.gif
 43ExpandedSubBlockStart.gifContractedSubBlock.gif        Public Property LogoffText()Property LogoffText()Property LogoffText()Property LogoffText() As String
 44InBlock.gif            Get
 45InBlock.gif                Return _logoffText
 46InBlock.gif            End Get
 47InBlock.gif            Set(ByVal Value As String)
 48InBlock.gif                _logoffText = Value
 49InBlock.gif            End Set
 50ExpandedSubBlockEnd.gif        End Property

 51InBlock.gif
 52ExpandedSubBlockEnd.gif#End Region

 53InBlock.gif
 54InBlock.gif        '*******************************************************
 55InBlock.gif        '
 56InBlock.gif        ' The Page_Load server event handler on this page is used
 57InBlock.gif        ' to populate the role information for the page
 58InBlock.gif        '
 59InBlock.gif        '*******************************************************
 60ExpandedSubBlockStart.gifContractedSubBlock.gif        Private Sub Page_Load()Sub Page_Load()Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 61InBlock.gif
 62InBlock.gif            ' public attributes
 63InBlock.gif            If CssClass <> "" Then
 64InBlock.gif                hypLogin.CssClass = CssClass
 65InBlock.gif            End If
 66InBlock.gif
 67InBlock.gif            If Request.IsAuthenticated = True Then
 68InBlock.gif                If LogoffText <> "" Then
 69InBlock.gif                    If LogoffText.IndexOf("src="<> -1 Then
 70InBlock.gif                        LogoffText = Replace(LogoffText, "src=""""src=""" & PortalSettings.ActiveTab.SkinPath)
 71InBlock.gif                    End If
 72InBlock.gif                    hypLogin.Text = LogoffText
 73InBlock.gif                Else
 74InBlock.gif                    hypLogin.Text = Services.Localization.Localization.GetString("Logout", Services.Localization.Localization.GetResourceFile(Me, MyFileName))
 75InBlock.gif                End If
 76InBlock.gif
 77InBlock.gif                If HostSettings.GetHostSetting("UseFriendlyUrls"= "Y" Then
 78InBlock.gif                    hypLogin.NavigateUrl = FriendlyUrl(PortalSettings.ActiveTab, ApplicationURL(PortalSettings.ActiveTab.TabID) & "&portalid=" & PortalSettings.PortalId.ToString, "Logoff.aspx")
 79InBlock.gif                Else
 80InBlock.gif                    hypLogin.NavigateUrl = ResolveUrl("~/Admin/Security/Logoff.aspx?tabid=" & PortalSettings.ActiveTab.TabID & "&portalid=" & PortalSettings.PortalId.ToString)
 81InBlock.gif                End If
 82InBlock.gif            Else
 83InBlock.gif                If Text <> "" Then
 84InBlock.gif                    If Text.IndexOf("src="<> -1 Then
 85InBlock.gif                        Text = Replace(Text, "src=""""src=""" & PortalSettings.ActiveTab.SkinPath)
 86InBlock.gif                    End If
 87InBlock.gif                    hypLogin.Text = Text
 88InBlock.gif                Else
 89InBlock.gif                    hypLogin.Text = Services.Localization.Localization.GetString("Login", Services.Localization.Localization.GetResourceFile(Me, MyFileName))
 90InBlock.gif                End If
 91InBlock.gif
 92InBlock.gif                If PortalSettings.LoginTabId <> -1 And Request.QueryString("override"Is Nothing Then
 93InBlock.gif                    ' user defined tab
 94InBlock.gif
 95InBlock.gif                    ' modified by jailu, 2007-04-15
 96InBlock.gif                    Dim strURL As String = Server.UrlEncode(Request.Url.ToString())
 97InBlock.gif                    Dim strTemp As String = NavigateURL(PortalSettings.LoginTabId, """returnurl=" + strURL)
 98InBlock.gif                    hypLogin.NavigateUrl = strTemp
 99InBlock.gif                Else
100InBlock.gif                    ' admin tab
101InBlock.gif                    hypLogin.NavigateUrl = NavigateURL("Login")
102InBlock.gif                End If
103InBlock.gif            End If
104InBlock.gif
105ExpandedSubBlockEnd.gif        End Sub

106InBlock.gif
107ExpandedSubBlockEnd.gif    End Class

108InBlock.gif
109ExpandedBlockEnd.gifEnd Namespace
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值