Search code examples
dotnetbrowser

Providing Location information in DotNetBrowser


When navigating to a website who requires location information, how can I tell DotNetBrowser to provide that location information to the website? For example, in Chrome, we're prompted with a dialog similar to the image below. Is there a way that I can turn this on? Or automatically satisfy that requirement through a property setting?

enter image description here


Solution

  • By default, all permission requests are denied in DotNetBrowser. To modify this behavior you should register your own IPermissionHandler implementation.

    The following permission handler implementation demonstrates how to grant the permission for geolocation:

    class GeolocationPermissionHandler : IPermissionHandler
    {
        public PermissionStatus OnRequestPermission(PermissionRequest request)
        {
            if (request.Type == PermissionType.GEOLOCATION)
                return PermissionStatus.GRANTED;
            return PermissionStatus.DENIED;
        }
    }
    

    This permission handler can be configured as shown below:

    browser.PermissionHandler = new GeolocationPermissionHandler();
    

    This article contains more information about geolocation and the required permission: https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000110022-geolocation