locked
Retrieve Logged User RRS feed

  • Question

  • hi

    i've got a custom vb.net web application that i display in a pageViewer web part.. i use the following code to retrieve the logged user:

    dim accManager as string
    dim sspURL as string = "http://sharepointurl"
    dim site as new SPSite(sspURL)
    dim web as spweb= site.OpenWeb
    dim user as spuser = web.CurrentUser
    accManager = user.Name
    if accManager <> "" then
    txtaccManager.Text = accManager
    end if

    and this does not return the real sharepoint logged user but the system user...
    now i know that i have to "inject" my application into sharepoint context to get the things right but somebody could tell me how? ..i just can't figure it out...

    thanks!

    Tuesday, February 2, 2010 2:15 PM

Answers

  • i've solved the problem! ...i had my application on the sharepoint server but on another port ...they have to be on the same:)

    thanx to all!
    • Marked as answer by Pizzaware Thursday, February 4, 2010 8:45 AM
    Thursday, February 4, 2010 8:44 AM

All replies

  • SPContext.Current.Web.CurrentUser.LoginName  hope this one will help you.
    Tuesday, February 2, 2010 2:25 PM
  • SPContext.Current.Web.CurrentUser.LoginName  hope this one will help you.

    it returns me "Object reference not set to an instance of an object" .. thank you for the fast reply anyway.
    Tuesday, February 2, 2010 2:33 PM
  • If you VB.NET application is not running in context of SharePoint you will need to get the current user from the current http context.  Try ...

    HttpContext.Current.User

    This will give you the current user if you are running windows authentication with impersonate.


    My SharePoint Blog - http://www.davehunter.co.uk/blog
    Tuesday, February 2, 2010 2:41 PM
  • you should run the above code from the sharepoint site context, then only the above code will return the currently logged in user details



    If you you are running the code in other then sharepoint context you will get the  error"Object reference not set to an instance of an object"

    hope this solves your problem
    ragava_28
    Tuesday, February 2, 2010 2:42 PM
  • thank you for the replies
    how do i run my code from the sharepoint context?
    Tuesday, February 2, 2010 2:46 PM
  • deploy the code in shareoint site so that it will run under sharepoint context.


    ragava_28
    Tuesday, February 2, 2010 2:54 PM
  • Hi

    I think your trying to get the sharepoint logged in user from different application. Your web application runs from different environment.
    In this case you need to use built-in SharePoint webservices or custom web services in SharePoint.

    Better use the built-in web service for User and Groups in SharePoint
    http://msdn.microsoft.com/en-us/library/ms772647.aspx
    Tuesday, February 2, 2010 4:06 PM
  • thank you for the replies
    how do i run my code from the sharepoint context?

    You can Creating Custom Application Pages(http://msdn.microsoft.com/en-us/library/bb892187.aspx#WSS3Inside_CustomApp)
    Cogito, ergo sum.
    Thursday, February 4, 2010 2:13 AM
  • i've solved the problem! ...i had my application on the sharepoint server but on another port ...they have to be on the same:)

    thanx to all!
    • Marked as answer by Pizzaware Thursday, February 4, 2010 8:45 AM
    Thursday, February 4, 2010 8:44 AM