How to get the current portal login URL in DotNetNuke?

In the context of the DNN module, what is the general common way to find out which URL is for the login function?

+3
source share
4 answers

Here is a utility that gets the login url:

FROM#

        /// <summary>
        /// Gets the login URL for the given portal from the current <paramref name="request"/>.
        /// </summary>
        /// <param name="portalSettings">The portal settings.</param>
        /// <param name="request">The request.</param>
        /// <returns>The URL for the login page</returns>
        /// <exception cref="ArgumentNullException">if <paramref name="portalSettings"/> or <paramref name="request"/> is null.</exception>
        public static string GetLoginUrl(PortalSettings portalSettings, HttpRequest request)
        {
            if (portalSettings != null && request != null)
            {
                int tabId = portalSettings.ActiveTab.TabID;
                string controlKey = "Login";
                string returnUrl = request.RawUrl;
                if (returnUrl.IndexOf("?returnurl=", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    returnUrl = returnUrl.Substring(0, returnUrl.IndexOf("?returnurl=", StringComparison.OrdinalIgnoreCase));
                }

                returnUrl = HttpUtility.UrlEncode(returnUrl);

                if (!Null.IsNull(portalSettings.LoginTabId) && string.IsNullOrEmpty(request.QueryString["override"]))
                {
                    // user defined tab
                    controlKey = string.Empty;
                    tabId = portalSettings.LoginTabId;
                }
                else if (!Null.IsNull(portalSettings.HomeTabId))
                {
                    // portal tab
                    tabId = portalSettings.HomeTabId;
                }

                // else current tab
                return Globals.NavigateURL(tabId, controlKey, new string[] { "returnUrl=" + returnUrl });
            }

            throw new ArgumentNullException(portalSettings == null ? "portalSettings" : "request");
        }

Vb.net

''' <summary>
''' Gets the login URL for the given portal from the current <paramref name="request"/>.
''' </summary>
''' <param name="portalSettings">The portal settings.</param>
''' <param name="request">The request.</param>
''' <returns>The URL for the login page</returns>
''' <exception cref="ArgumentNullException">if <paramref name="portalSettings"/> or <paramref name="request"/> is null.</exception>
Public Shared Function GetLoginUrl(portalSettings As PortalSettings, request As HttpRequest) As String
    If portalSettings <> Nothing AndAlso request <> Nothing Then
        Dim tabId As Integer = portalSettings.ActiveTab.TabID
        Dim controlKey As String = "Login"
        Dim returnUrl As String = request.RawUrl
        If returnUrl.IndexOf("?returnurl=", StringComparison.OrdinalIgnoreCase) > -1 Then
            returnUrl = returnUrl.Substring(0, returnUrl.IndexOf("?returnurl=", StringComparison.OrdinalIgnoreCase))
        End If

        returnUrl = HttpUtility.UrlEncode(returnUrl)

        If Not Null.IsNull(portalSettings.LoginTabId) AndAlso String.IsNullOrEmpty(request.QueryString("override")) Then
            ' user defined tab
            controlKey = String.Empty
            tabId = portalSettings.LoginTabId
        ElseIf Not Null.IsNull(portalSettings.HomeTabId) Then
            ' portal tab
            tabId = portalSettings.HomeTabId
        End If

        ' else current tab
        Return Globals.NavigateURL(tabId, controlKey, New String() {"returnUrl=" + returnUrl})
    End If

    Throw New ArgumentNullException(If(portalSettings = Nothing, "portalSettings", "request"))
End Function
+3
source

Globals.LoginURL

public static string LoginURL(
    string returnURL,
    bool override
)
+3
source

ctl = login, DNN , URL- .

string loginURL = string.Format("{0}://{1}/Default.aspx?ctl=login", 
    Request.Url.Scheme, Request.Url.Host);
Response.Redirect(loginURL);
0

Source: https://habr.com/ru/post/1714641/


All Articles