is it possible to use Client Object Model in the application page (say in the head tag) present under layouts folder(example:xlviewer.aspx)?, to fetch the current logged-in username. OR do we have to create new application page via visual studio and deploy it?


Of course it is. But why do you want to use the Client Object Model? Also, don't overwrite or change any of the oob SharePoint pages in the Layouts folder.Just create your own and deploy it via a Solution.

The code you can use is :

protected void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)
        lblUserName.Text = SPContext.Current.Web.CurrentUser.LoginName;

If you really need to use Client Object Model, read here: Get current user in Client Object Model with javascript?

|improve this answer|||||
  • Can I create a copy of the aspx page and use it? Would that be safe? – variable Feb 4 '14 at 7:20
  • No, you can't copy an aspx page. The page itself references a Type. Copying the page will reference the same type. – Fox Feb 4 '14 at 7:37
  • You mean to say it will reference to the same code behind. So then I can use a custom IHttpRedirector, check if the page is say page1.aspx then redirect to page2.aspx; where page2 is copy of page1 isnt it? – variable Feb 4 '14 at 7:39
  • Indeed, it will reference the same codebehind (Type or class). Doing that would be so much work. Why not just create your own page.. If you don't need code behind (C#), just leave the codebehind property empty.. – Fox Feb 4 '14 at 7:43
  • OK, if I create a new application page, then also I believe will have to use redirector so that sharepoint will redirect the user from the default apppage to the custom one I created. Isnt it? – variable Feb 4 '14 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.