SharePoint, ASP.NET and Login Credentials
Hi,
I was wondering if anyone can help me. I am using Microsoft SharePoint Services 3.0 (WSS 3.0) and i am trying to build into the default ASPX page the ability to call some details from a database. however the details i am wanting to call are based on the current user logged in.
My problem is I am trying to work out how to identify, using code (preferably ASP), the current user who is signed in.
Can anyone help me with this or point me in the correct direction?
Cheers,
Luke
Re: SharePoint, ASP.NET and Login Credentials
Try:
Code:
string user = Context.Current.User.Identity.Name;
I haven't used this in the context of SharePoint, but this is a way to get the login name from ASP.NET.
Re: SharePoint, ASP.NET and Login Credentials
Thats great... i'll give it a try but i have one more question, sorry to be a pain, but how do i then use the variable to get it to be used (i.e. concatinated) in a URL link or to print it on the screen?
Thanks for you help so far and if you can help on this one it would be great :D
Cheers,
Luke
Re: SharePoint, ASP.NET and Login Credentials
It depends on what you need to do - if you place it in a string value, you can simply concatenate it to a URL / query string as needed. For on page, there are many ways - most simplistic (in standard ASP.NET, SharePoint may differ) is to use the <%= %> tags.
Re: SharePoint, ASP.NET and Login Credentials
Ok, i feel i am getting the understanding of this now... would an example be to put the variable (say it was named "USER") into the URL sting as follows:
http://www.example.net/index.aspx?username=USER
or would it be something like:
http://www.example.net/index.aspx?username=<%=USER%>
Cheers,
Luke
Re: SharePoint, ASP.NET and Login Credentials
It depends on where you're doing it - if you're writing this in the markup for a page, use the <%= %> tags. If you're doing it in a code-behind or in script, you just need to concatenate the strings (ie, "http://wherever.com/?user=" + user).