Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have an MVC web app that is sitting on a server running SharePoint Foundation and users access it via a link in the SharePoint portal. I require the website to log in automatically for the current user who is logged in to SharePoint. All I need is a way to get the user's SharePoint username so I can verify it against my database and log them in. The code below is what I have so far, but it does not seem to be working and I cannot debug as I don't have SharePoint installed.

        string windowsLogin = "";

        if (SPContext.Current != null)
        {
            SPSite sps = SPContext.Current.Site;
            using (SPWeb spw = sps.OpenWeb())
            {
                windowsLogin = SPContext.Current.Web.CurrentUser.LoginName;
            }
        }
share|improve this question
    
you say the web app is running on a server that's running SharePoint Foundation....and then you say you don't have SharePoint installed. Which is it? –  Derek Gusoff May 24 '13 at 19:02
    
This approach will not work. SPContext will be null because it's not running in a SharePoint context. –  Derek Gusoff May 24 '13 at 19:34
    
Sorry should have clarified, dont have it installed on my personal pc but its running on a client server with SharePoint. Thanks for your help though. I realised it won't work as my site is being loaded into a Web Part view page which doesn't sit in the SPContext –  Ic3m4n69 May 26 '13 at 19:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.