I made a copy of AccessDenied.aspx and added some modifications. See below. All I've done is add some html and javascript to get display information about the currently logged in use. This code works great if I navigate directly to the page from the address bar in my browser, but If I test it by actually going to a page that I don't have access to (using a test account), it never succeeds. I don't see anything in my browser console that could indicate an error and all requests return with a redirect or 200 message. I admit that I am not sure If I am doing this correctly, but am hoping someone could point me in the right direction. Thank you.

EDIT: I have added a more helpful statement in the onfailure function and have edited my code below. Now the message I receive is:

You are signed in as: Request Failed. Access denied. You do not have permission to perform this action or access this resource. undefined

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"> 
<div> Please include a brief message describing who you are and why you need access.
Your message will be forwarded to <span id="owner"></span>.
Thank you!
<WebPartPages:AllowFraming runat="server" /> 
<div id="ms-accessDenied-reqDialog"> 
    <wssuc:AccessRequestsDialog Id="AccessRequestsDialog" ShowTitle="True" runat="server"/> 

<div id="AccessDeniedAdditionalDetails" runat="server" /> 
    <span style="font-weight:bold;font-family:calibri;">You are signed in as:</span>
    <span id="username"> username</span>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript">

(function ($, undefined)
$(document).ready(function() {

    SP.SOD.executeFunc("sp.js","SP.ClientContext", function()

        SP.SOD.executeFunc("sp.runtime.js", "SP.ClientContext", function()

            var context = SP.ClientContext.get_current();
            var web = context.get_web();
            var user = web.get_currentUser();
            var group = web.get_associatedOwnerGroup();



            function OnSuccess(sender, args) {

                var loginName = user.get_loginName();
                var name = user.get_title().split(" ")[0];
                var owner = group.get_title()

                if(user.get_loginName().indexOf("campus partner") > -1) {
                    loginName = loginName.split("|")[2];
                else {
                    loginName = loginName.split("|")[1];

                document.getElementById("username").innerHTML = " " + loginName;
                document.getElementById("name").innerHTML = " " + name;
                document.getElementById("owner").innerHTML = " " + owner;


            function OnFailure(sender, args) {
                document.getElementById("username").innerHTML = "Request Failed. " + args.get_message() + "\n" + args.get_stackTrace();





1 Answer 1


You're making a query against a site you don't have access to. By definition, you do not have permission to view the data you are trying to fetch. If you want to get the current user's login name, just call _spPageContextInfo.userLoginName

  • facepalm Ok, that of course makes sense. I'm not sure why I thought it would work. For _spPageContextInfo I only have .userID which isn't super helpful. Would this, in theory work if I can query a different web that I know the user has access to (a web with Read permissions for Everyone for example?)
    – SoTired
    Commented Oct 2, 2015 at 19:38
  • Ok, so I was able to put something usable together by creating a new context for a web that all users have access to and getting the users login information that way. Unfortunately, I won't be able to get the owners group, but I worked around that by calling printing _spPageContextInfo.webTitle + " Owners". I think that will appease the customer for now. Thank you for your answer!
    – SoTired
    Commented Oct 2, 2015 at 19:56
  • you might also try making a REST call to the user's user profile if it contains the info you seek. the exact properties avaliable on the _spPageContextInfo vary depending on the version and edition, so maybe that's why you didn't see userLoginName. Commented Oct 3, 2015 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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