PortalID返回null引用错误

时间:2018-04-11 23:16:08

标签: asp.net dotnetnuke

我正在使用此功能允许用户登录,但portalid返回空引用。我正在使用现有的dnn来检查用户是否存在。但是我如何让portalid在不同的程序中使用。这就是我到目前为止所拥有的

 int PID = DotNetNuke.Entities.Portals.PortalController.GetCurrentPortalSettings().PortalId;
    try
    {
        //validate username/password combination
        DotNetNuke.Entities.Users.UserInfo myUser = new DotNetNuke.Entities.Users.UserInfo();
        DotNetNuke.Security.Membership.UserLoginStatus userLoginStatus = new DotNetNuke.Security.Membership.UserLoginStatus();
        myUser = DotNetNuke.Entities.Users.UserController.ValidateUser(PID, txtUserName.Text, txtPassword.Text, "", "", "", ref userLoginStatus);



        if (userLoginStatus == DotNetNuke.Security.Membership.UserLoginStatus.LOGIN_SUCCESS ||
        userLoginStatus == DotNetNuke.Security.Membership.UserLoginStatus.LOGIN_SUPERUSER)
        {
            //login the user ...
            DotNetNuke.Entities.Users.UserController.UserLogin(PID, myUser, "", "", true);
            Response.Redirect("~/Home/Welcome.aspx");
        }
        else
        {
            lblError.Text = "Invalid Username or Password";
        }
    }
    catch (Exception ex)
    {
        lblError.Text = "Error!! " + ex.Message.ToString();
    }

1 个答案:

答案 0 :(得分:0)

您可以使用PortalController。

using DotNetNuke.Entities.Portals;

//get a portal by ID
var portal = PortalController.Instance.GetPortal(PortalId);

//get the current portal
var portal = PortalController.Instance.GetCurrentPortalSettings();