Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Determining current userDetermining current user
Previous
 
Next
New Post
8/15/2007 1:36 AM
 

I am trying to modify the Dot Net Nuke Menu.  I have added a conditional to the ist building section of the menu.  The goal is to make sure that even if a user is an Admin User, they can only see the Admin tabs if they are user_ID 1 or 2.  The problem is that I need to load objUserInfo.UserID with information about the current user.  How can I extract the username of the current user as a string?  Is this a secure thing to do?  I would appriciate hearing better ideas if anyone has one.

 

Dim objUsers As New Entities.Users.UserController
Dim objUserInfo As Entities.Users.UserInfo

objUserInfo = objUsers.GetUserByUsername(MyPortalSettings.PortalId, <Username As String> )

<...some more code ....>

 

' Build list of tabs to be shown to user
    For i = 0 To MyPortalSettings.DesktopTabs.Count - 1

      Dim tab As TabInfo = CType(MyPortalSettings.DesktopTabs(i), TabInfo)
      If tab.IsVisible = True And tab.IsDeleted = False Then
                If DotNetNuke.Security.PortalSecurity.IsInRoles(tab.AuthorizedRoles) = True Then
                    If (tab.IsAdminTab = True And (objUserInfo.UserID = 1 Or objUserInfo.UserID = 2)) Or tab.IsAdminTab = False Then
                        authorizedTabs.Add(tab)
                        addedTabs += 1
                    End If
                End If
            End If

        Next i

 
New Post
8/15/2007 7:06 AM
 

The UserController can return the current userinfo object.

DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()

Westa

 
New Post
8/15/2007 2:49 PM
 

I'm trying to convert an existing asp1.1/dnn2.0 to asp2.0/dnn4.x...  it's some code that when logged in a user can become another user (ie home office associate can log in as a customer and see the site the way the customer would see it).

I'm lost. Here's my error

System.Data.SqlClient.SqlException: Conversion failed when converting the varchar value 'Lynne' to data type int. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.HasMoreRows() at System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout) at System.Data.SqlClient.SqlDataReader.Read() at System.Data.SqlClient.SqlCommand.CompleteExecuteScalar(SqlDataReader ds, Boolean returnSqlValue) at System.Data.SqlClient.SqlCommand.ExecuteScalar() at DotNetNuke.BecomeaUser.IDCheck() at DotNetNuke.BecomeaUser.Page_Load(Object sender, EventArgs e)

I tried implementing you GetCurrentUserInfo()

 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load' Obtain PortalSettings from Current Context

Try

DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()

 

'Dim _portalSettings As ProviderSettings = CType(Context.Items("PortalSettings"), ProviderSettings)

IDCheck()

 

' Log User Off from Cookie Authentication System

 

Dim vUserId As String

 

' Dim vPass As String

 

If (Request.Params("Agentid") <> "") Then

vUserId = Request.Params(

Session(

Response.Cookies(

"Agentid")"pRet") = vAgentid"Sub").Value = "555555555"

Response.Cookies(

"Sub").Path = "/"

 

Else

vUserId = Session(

Session(

"pRet").ToString"pRet") = ""

 

End If

 

 

Dim objSecurity As New Security.PortalSecurityDim blnLogin As Boolean = True

 

If blnLogin Then

 

' Attempt to Validate User Credentials

 

Dim userId As String = vUserId 'objSecurity.UserLogin(vUserId, vPass, 0, 0, 0, 0)

 

If userId >= 0 Then

FormsAuthentication.SignOut()

 

' expire cookies

Response.Cookies(

"portalid").Value = Nothing

Response.Cookies(

"portalid").Path = "/"

Response.Cookies(

Response.Cookies(

"portalid").Expires = DateTime.Now.AddYears(-30)"portalroles").Value = Nothing

Response.Cookies(

"portalroles").Path = "/"

Response.Cookies(

Response.Cookies(

"portalroles").Expires = DateTime.Now.AddYears(-30)"Sub").Value = Nothing

Response.Cookies(

"Sub").Path = "/"

Response.Cookies(

FormsAuthentication.SetAuthCookie(Convert.ToString(userId),

Response.Redirect(

 

"Sub").Expires = DateTime.Now.AddYears(-30)False)"~/" & "tabid/36/Default.aspx")Else

Response.Write(

 

"This User is not yet created to be a Web User.2")End If

 

End If

 

Response.Write(ex.ToString)

 

Catch ex As ExceptionEnd Try

 

End Sub

I'm not having much luck searching so I'm asking in this thread.  PLEASE... even a search suggestion would help.

 

 
New Post
8/15/2007 4:28 PM
 

You don't need to do either one of these things.

IF YOU ARE BUILDING A MODULE, your module should be extended from DotNetNuke.Entities.Modules.PortalModuleBase. In this case, current UserId is explicitly available to you and you can refer to it just like that If UserId = 1 Then... You don't need to do any queries, you don;t need to populate anything.

Another point, if you want to test current user if he/she is a SuperUser or and Admin, you can just say 
If UserInfo.IsSuperUser OrElse UserInfo.IsInRole("Administrator") Then...


Vitaly Kozadayev
Principal
Viva Portals, L.L.C.
 
New Post
8/15/2007 8:50 PM
 

That would assume he was building a MODULE

- but since he says he is modifying the DNN MENU I kinda assumed he is working on a SKIN  - in which case you would not be extending PortalModuleBase.

Westa

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Determining current userDetermining current user


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out