dnn 模块 小代码集
1.获取模块的服务器端路径<%=TemplateSourceDirectory%>
2. 在模块中获取用户的ID
UserInfo user = UserController.GetCachedUser(PortalController.GetCurrentPortalSettings().PortalId, Context.User.Identity.Name);
3.需要登录才能访问的页面的处理。
前台ASPX:
<asp:Label runat="server" Visible="false" ID="tipLogin">该项服务需要登陆才能使用,请</asp:Label>
<asp:HyperLink runat="server" Visible="false" ID="hlLogin">登陆</asp:HyperLink>
后台C#:
if (!Request.IsAuthenticated)
{
string returnUrl = HttpContext.Current.Request.RawUrl;
if (returnUrl.IndexOf("?returnurl=") != -1)
{
returnUrl = returnUrl.Substring(0, returnUrl.IndexOf("?returnurl="));
}
returnUrl = HttpUtility.UrlEncode(returnUrl);
if (PortalSettings.LoginTabId != -1 && Request.QueryString["override"] == null)
{
hlLogin.NavigateUrl = Globals.NavigateURL(PortalSettings.LoginTabId, "", "returnUrl=" + returnUrl);
}
else
{
if (PortalSettings.HomeTabId != -1)
{
hlLogin.NavigateUrl = Globals.NavigateURL(PortalSettings.HomeTabId, "", "returnUrl=" + returnUrl);
}
else
{
hlLogin.NavigateUrl = Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "", "returnUrl=" + returnUrl);
}
}
tipLogin.Visible = true;
hlLogin.Visible = true;
RadGrid1.Visible = false;
return;
}