作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 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/
我是一名优秀的程序员,十分优秀!