gpt4 book ai didi

c# - 如何在 DotNetNuke 中获取门户的当前登录 URL?

转载 作者:行者123 更新时间:2023-11-30 14:43:57 24 4
gpt4 key购买 nike

在 DNN 模块的上下文中,找出登录功能的 URL 的通用方法是什么?

最佳答案

这是一个获取登录 URL 的实用方法:

C#

        /// <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

关于c# - 如何在 DotNetNuke 中获取门户的当前登录 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1246570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com