Microsoft Developer Network > 포럼 홈 > SharePoint - Development and Programming > Retrieve Sharepoint UserName in Content Editor Web part?
질문하기질문하기
 

질문Retrieve Sharepoint UserName in Content Editor Web part?

  • 2008년 5월 13일 화요일 오후 4:26ChrisPalko 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

     

    I read the article with Subject: "How to get the username from SharePoint for an another web application", but I think what I'm trying to do may be a little different.  I have a content editor web part that contains some descriptive text and a URL to another web application.  This web application resides on a web server using NTLM authentication.  We're using Active Directory for our Sharepoint authentication.  Can I add some code to my content editor web part to retrieve the username and pass it along in the URL?  I'm hoping to let the user click the link in the web part and run the application without logging in a separate time.

     

    The URL should look like this:
    <a href='http://[server]/xpe/loginPage.jsp?magicAction.setUserId=JP557238'>this link to XPE logs you into the application in production</a>

     

    The JP557238 is the username/login I hope to pass along with my URL.  This is the username I log in with to Sharepoint from Active Directory.

    Please advise,

     

    Chris

     


     

모든 응답

  • 2008년 5월 13일 화요일 오후 9:49Moonis TahirMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    you can still do it with a trick.

     

    1)

    write a custom control with nothing on it. just write your code in load event. in your code generate a hidden field with value of current logged in user id which you can easily get from httpcontext.  compile your control dll and put dll into 80/bin folder of sharepoint and put ASCX file in CONTROLTEmplate folder in 12 hive. Now place your control on master page of your sharepoint using sharepoint designer and publish your master page. now you know that you have user id in a hidden field all the time. In your content Editor web part, get it through javascripting and use it.

     

    2)

    You can also extract this user id using javascript from welcome control. you know that it is visible on top right corner of your sharepoint like "Welcome Chris"  so you can view the source and get it  through javascripting.

     

     

    3) create a blank aspx page and write code in its page load event to get user id from httpcontext and use response.redirect to send it to your JSP url. and in your content editor web part simply call your blank aspx page. here blank aspx page you can put in Layouts folder of sharepoint with its dll into 80/bin folder. and in your content editor webpart simply use it like this http://yourmoss/siteA/_layouts/yourpage.aspx and your aspx page will actually get the user id and will redirect you to JSP page with query string.

  • 2008년 5월 14일 수요일 오후 2:44ChrisPalko 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    Since we're using Active Directory for Sharepoint authentication, the Display Name is displayed in the "Welcome Chris" on the top right.  I need the user's Account Name that's stored in Active Directory.

     

    Example:   Palkovits, Chris is my Display Name

                     FIRM\JP123456 is my Account Name (domain name followed by unique identifier)

    I will need to ONLY pull out the unique identifier, JP123456, and add it to the end of my URL.  I'm new to Sharepoint.  Will options 1 or 3 give me this unique identifier?  For option 1, do I need to use Sharepoint Designer?  For option 3, can I use Visual Studio?  In option 3, what do you mean when you say "with its dll"?  Will I have a *.aspx page and another corresponding *.dll file to put into 80/bin folder?

     

    Thanks,

    Chris

     

     

  • 2008년 5월 14일 수요일 오후 2:56Moonis TahirMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    option 1 requires you to use sharepoint designer so that you can put your control on your master page etc.

    option 3 is just visual studio. put your aspx page in LAYOUTS folder of sharepoint 12 hive location. Put corresponding dll into 80/bin and thats it.

  • 2009년 11월 12일 목요일 오전 8:31converscient 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    hope this helps

     

    SPWeb oWebsite = SPContext.Current.Web;

     

    string Credentials = oWebsite.CurrentUser.LoginName;


    Never stop learning.