ithit-ajax-file-browser active directory WebDav au

2019-07-20 05:03发布

问题:

I'm using Active Directory in Windows Server2012 R2 and IIS 8.5 to create a WebDav for each user and it can be accessed via the user-name and user-password. One folder per user. This works perfectly using WebDav clients. I have also a web browser using ithit-ajax-file-browser.

My problem is, when i set parameters to the web-part the server shows up an authentification pop-up before logging me automatically.

I'im using

    var settings = {
                    BasePath: '/davbrowser/',                      
                    Id: 'AjaxFileBrowserContainer',     
                    Url: webDavServerPath,              
                    Style: 'height: 100%; width: 100%', 
                    MsOfficeTemplatesPath: '/templates/', 
                    SelectedFolder: webDavServerPath,   
                    ThemeName: 'windows_8',             
                    IconsSize: 16                       
                    //Platform: 'mobile'                
                };
var ajaxFileBrowser = new ITHit.WebDAV.Client.AjaxFileBrowser.Controller(settings);
ajaxFileBrowser.GetSession().SetCredentials('username', 'password');
ajaxFileBrowser.SetSelectedFolder('/username');

`

The auto-login works but the login pop-up still appears. Are there any solution to delete it? I'm using basic authentification

回答1:

In your code, in settings, you are setting the SelectedFolder parameter. This causes the request to be sent before the SetCredentials is called. Remove the SelectedFolder setting and call only SetSelectedFolder, which is doing the same thing, but after the SetCredentials call.

I would also suggest to update your code to use the async approach, introduced in IT Hit Ajax File Browser v2.1.0.1483:

var settings = {
                BasePath: '/davbrowser/',                      
                Id: 'AjaxFileBrowserContainer',     
                Url: webDavServerPath,              
                Style: 'height: 100%; width: 100%', 
                MsOfficeTemplatesPath: '/templates/', 
                //SelectedFolder: webDavServerPath,   
                ThemeName: 'windows_8',             
                IconsSize: 16                       
                //Platform: 'mobile'                
            };


    var ajaxFileBrowserLoader = new ITHit.WebDAV.Client.AjaxFileBrowserLoader(settings);
    ajaxFileBrowserLoader.oninit = function(ajaxFileBrowser) {
        // This event is fired when control is loaded and created.
        ajaxFileBrowser.GetSession().SetCredentials('username', 'password');
        ajaxFileBrowser.SetSelectedFolder('/username'); 
    };
    ajaxFileBrowserLoader.LoadAsync();

Another thing, that can cause the standard web browser login dialog is the CORS request. That is in case your settings.Url parameter contains WebDAV server URL that is located in another origin (domain, port or protocol). Unfortunately there is no any real solution for this case. The only workaround would be placing the page with Ajax File Browser on the same server where WebDAV server is located. You can find more info about it here.



回答2:

SOLUTION

I'm using basic authentification and i need to send username and password in the headers. I can't use this form. username:password@fileserver/userfolder This method works only on firefox. It's an issue here chromium issue So the solution is to use XMLHttpRequest.

webDavServerPath = 'fileserver/userfolder';
var xml = new XMLHttpRequest(); 
xml.open('GET',webDavServerPath,false,username,password)
xml.send('');

This works fine in most browser and must be used under SSL.