0

I have a static method in static class in MVC application that returns User Claims, when I access directly the url of this application,I am getting those values but when I access application url from another application using Javascript,it is not returning anything.I am not getting any error.It is returning empty result.I am also not getting CORS issue.i suspect it is something related to authentication & passing user credentials,both site is under same ADFS configuration

public static UserDetails GetUserDetails()
        {
            var userdetails = new UserDetails();

            var objClaims = ((ClaimsIdentity)Thread.CurrentPrincipal.Identity).Claims;

            foreach(var c in objClaims)
            {

                else if (c.Type == ConstantsHelper.emailAddress)
                {
                    userdetails.Email = c.Value;
                }
                else if (c.Type == ConstantsHelper.userName)
                {
                    userdetails.UserName = c.Value;
                }
                else if (c.Type == ConstantsHelper.shortName)
                {
                    userdetails.ShortName = c.Value;
                }
            }
            return userdetails;
        }

Code to access it from another application.

function GetLoggedInUsermethod() {
        var url = GetLoggedInUser;
        $.ajax({
            type: "GET",
            url: url,
            crossDomain: true,
            success: function (json) {


            },
            error: function (e) {

            }

        });
    }
F11
  • 3,703
  • 12
  • 49
  • 83
  • Please mention the syntax that you are using to access this method. – stylishCoder May 06 '16 at 07:39
  • When you are accessing it through another application, is your this site hosted on the server or running in the localhost while you are calling it? Post your code of how you are trying to access it – Pawan Nogariya May 06 '16 at 07:47
  • both sites are hosted on server – F11 May 06 '16 at 07:52
  • I guess your sites are having different domains, did you check it using firebug/developer tools whether the call is getting triggered properly? – SamGhatak May 06 '16 at 07:58

1 Answers1

0

If the calling application is hosted in different domain (different ports will qualify for different domains), then you may need to add the Access-Control-Allow-Origin header to the response with the value set to the calling application's domain for the call to succeed.

More details here.

Community
  • 1
  • 1
anir_d
  • 64
  • 7