locked
Determine whether current user is logged on via IFD or AD RRS feed

  • Question

  • Hi,

    Looking for a way to determine via code whether the user accessing an aspx page logged in via IFD or is authenticated via Active Directory.

    Thanks in adv.

    Wednesday, January 2, 2013 8:38 PM

Answers

  • Internal and external URLs are different.  Base on the URL, you can pass the url or any other variable as a query string to your aspx page.

    I hope this helps.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior Solution Architect HP Australia Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com

    • Marked as answer by CRM001 Monday, January 7, 2013 10:40 AM
    Thursday, January 3, 2013 12:23 AM
  • Hi,

    I managed to use the following to resolve the issue:

    Firstly, it was important for me to use different URL's from the left Navigation bar. The internal URL did not work via IFD and the IFD url pointed the user to log in again when within the intranet. I thus had to dynamically set the hostname passed through via the parent MS CRM URL. I want to modify the EDITME left navigation link.

    This allows me to either use the current URL (HttpContext.Current.Request.Url.AbsoluteUri;) or the MS CRM parent URL (HttpContext.Current.Request.UrlReferrer.AbsoluteUri;) to determine whether the user logged on via IFD or AD.

    function PassQryStrToLink() {
        var hostname = window.location.hostname;
        var navItems = Xrm.Page.ui.navigation.items.get();
        var currentId = Xrm.Page.data.entity.getId();
    
        for (var navItem in navItems) {
            var item = navItems[navItem];
            if (navItems[navItem].getLabel() == "EDITME"||navItems[navItem].getLabel()=="EDITME") 
            {
                //Get the current navigation item id.
                var areaId = item.getId();
                //Get navigation element by using the id.
                var navElement = document.getElementById(areaId);
                //Make sure that the navigation element is not empty or null
                if (navElement != null && navElement != undefined) {
                    //Create the url to use in the navigation link
                    
                    if (hostname == 'myifdurl')
                        var iframeUrl = encodeURI("https://crm.ifd.com/ISV/TestApp/Default.aspx?id=" + currentId);
    
                    if (hostname == 'internalcrm')
                        var iframeUrl = encodeURI("https://internalcrm/ISV/TestApp/Default.aspx?id=" + currentId);
    
                    //Create a function that is run when the navigation link is clicked.
                    navElement.onclick = function () {
                        //Start by creating the area, this is where the url looses "/report/path" from the path.
                        loadIsvArea(Mscrm.CrmUri.create(iframeUrl), false);
                        //Get the iframe in the navigation area.
                        var navIframeObject = document.getElementById(areaId + "AreaFrame");
                        //Set the source for the iframe again with the correct url.
                        navIframeObject.src = iframeUrl;
                    };
                }
            }
        }
    }
    
    Thanks for all the help in getting this far.

    • Marked as answer by CRM001 Monday, January 7, 2013 10:40 AM
    Monday, January 7, 2013 10:39 AM

All replies

  • Internal and external URLs are different.  Base on the URL, you can pass the url or any other variable as a query string to your aspx page.

    I hope this helps.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior Solution Architect HP Australia Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com

    • Marked as answer by CRM001 Monday, January 7, 2013 10:40 AM
    Thursday, January 3, 2013 12:23 AM
  • The URL Changes when the user logs in as IFD user so using the URl u can determine the current user
    • Proposed as answer by Nandan21 Thursday, January 3, 2013 11:19 AM
    Thursday, January 3, 2013 4:10 AM
  • I did try something similar to this, however it would require me to dynamically update/set the value of the left navigation url (again based on IFD) which points to the ASPX page right?

    For example currently I use a static link which points to https://crmint.company.com/isv/App1/default.aspx.

    Any code out there for how you would go about dynamically populating this link (via JS I assume?)

    Thursday, January 3, 2013 6:24 AM
  • I got an another. You can get that by javascript in your aspx page.

    Try 

    window.top.location

    It will give you the CRM url.

    I hope this helps.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior Solution Architect HP Australia Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com

    • Proposed as answer by Amreek Singh Thursday, January 3, 2013 11:08 AM
    Thursday, January 3, 2013 11:08 AM
  • Hi,

    I managed to use the following to resolve the issue:

    Firstly, it was important for me to use different URL's from the left Navigation bar. The internal URL did not work via IFD and the IFD url pointed the user to log in again when within the intranet. I thus had to dynamically set the hostname passed through via the parent MS CRM URL. I want to modify the EDITME left navigation link.

    This allows me to either use the current URL (HttpContext.Current.Request.Url.AbsoluteUri;) or the MS CRM parent URL (HttpContext.Current.Request.UrlReferrer.AbsoluteUri;) to determine whether the user logged on via IFD or AD.

    function PassQryStrToLink() {
        var hostname = window.location.hostname;
        var navItems = Xrm.Page.ui.navigation.items.get();
        var currentId = Xrm.Page.data.entity.getId();
    
        for (var navItem in navItems) {
            var item = navItems[navItem];
            if (navItems[navItem].getLabel() == "EDITME"||navItems[navItem].getLabel()=="EDITME") 
            {
                //Get the current navigation item id.
                var areaId = item.getId();
                //Get navigation element by using the id.
                var navElement = document.getElementById(areaId);
                //Make sure that the navigation element is not empty or null
                if (navElement != null && navElement != undefined) {
                    //Create the url to use in the navigation link
                    
                    if (hostname == 'myifdurl')
                        var iframeUrl = encodeURI("https://crm.ifd.com/ISV/TestApp/Default.aspx?id=" + currentId);
    
                    if (hostname == 'internalcrm')
                        var iframeUrl = encodeURI("https://internalcrm/ISV/TestApp/Default.aspx?id=" + currentId);
    
                    //Create a function that is run when the navigation link is clicked.
                    navElement.onclick = function () {
                        //Start by creating the area, this is where the url looses "/report/path" from the path.
                        loadIsvArea(Mscrm.CrmUri.create(iframeUrl), false);
                        //Get the iframe in the navigation area.
                        var navIframeObject = document.getElementById(areaId + "AreaFrame");
                        //Set the source for the iframe again with the correct url.
                        navIframeObject.src = iframeUrl;
                    };
                }
            }
        }
    }
    
    Thanks for all the help in getting this far.

    • Marked as answer by CRM001 Monday, January 7, 2013 10:40 AM
    Monday, January 7, 2013 10:39 AM