Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...How to redirect to login page when LoginTablId is not set (-1)?How to redirect to login page when LoginTablId is not set (-1)?
Previous
 
Next
New Post
8/3/2009 3:28 PM
 

I am creating a module and, in certain circumstances, want to force anonymous users to authenticate before being allowed to continue. I have found that if an admin has specified a login page, the following will work:

Dim  RedirectURL as string = NavigateURL(PortalSettings.LoginTabId, "", "returnurl=" & HttpUtility.UrlEncode _(HttpContext.Current.Request.RawUrl))

Response.Redirect(RedirectURL, True)

However, in a default installation, no login page is defined and LoginTabId returns -1, causing the redirect to go into an infinite loop. In this situation, is there any way to get a user to login and then return to the original URL? It seems that I cannot assume a login page has been defined, right?

Or am I missing something? I am pretty new to DNN.

Thanks, Roger
 

 
New Post
8/7/2009 3:35 PM
 

Hey Roger,

Here is a utility method that gets the current portal's login URL.

Public Shared Function GetLoginUrl(ByVal portalSettings As PortalSettings, ByVal request As HttpRequest) As String

    If ((portalSettings Is Nothing) OrElse (request Is Nothing)) Then

        Throw New ArgumentNullException(IIf((portalSettings Is Nothing), "portalSettings", "request"))

    End If

    Dim tabID As Integer = portalSettings.ActiveTab.TabID

    Dim controlKey As String = "Login"

    Dim rawUrl As String = request.RawUrl

    If (rawUrl.IndexOf("?returnurl=", StringComparison.OrdinalIgnoreCase) > -1) Then

        rawUrl = rawUrl.Substring(0, rawUrl.IndexOf("?returnurl=", StringComparison.OrdinalIgnoreCase))

    End If

    rawUrl = HttpUtility.UrlEncode(rawUrl)

    If (Not Null.IsNull(portalSettings.LoginTabId) AndAlso String.IsNullOrEmpty(request.QueryString.Item("override"))) Then

        controlKey = String.Empty

        tabID = portalSettings.LoginTabId

    ElseIf Not Null.IsNull(portalSettings.HomeTabId) Then

        tabID = portalSettings.HomeTabId

    End If

    Return Globals.NavigateURL(tabID, controlKey, New String() { ("returnUrl=" & rawUrl) })

End Function

http://stackoverflow.com/questions/1246570/how-do-i-get-the-portals-current-login-url-in-dotnetnuke

Hope that helps,

Ian


Software Engineer
Co-Founder, dnnGallery
Stack Overflow: Ian Robinson
Twitter: @irobinson
Linked In: Ian Robinson
 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...How to redirect to login page when LoginTablId is not set (-1)?How to redirect to login page when LoginTablId is not set (-1)?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out