Connect to Secure WMS
I'm trying to connect to a secure wms. From what I've read you can pass username and password into the connection url. Any examples of this? I'm not sure how to configure the url.
0
-
Do you know ESRI's proxy page?
If you have someone with some programming expertise you'll have to modify the proxy page and config to include basic authentication in the headers.
string authInfo = getAuthInfoFromConfigFile(uri);
if (!String.IsNullOrEmpty(authInfo))
{
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
req.Headers["Authorization"] = "Basic " + authInfo;
}private string getAuthInfoFromConfigFile(string uri)
{
try
{
ProxyConfig config = ProxyConfig.GetCurrentConfig();
if (config != null)
{
string username = config.GetUsername(uri);
if(!String.IsNullOrEmpty(username))
{
string password=config.GetPassword(uri);
return username + ":" + password;
}
else
return string.Empty;
}
else
throw new ApplicationException(
"Proxy.config file does not exist at application root, or is not readable.");
}
catch (InvalidOperationException)
{
// Proxy is being used for an unsupported service (proxy.config has mustMatch="true")
HttpResponse response = HttpContext.Current.Response;
response.StatusCode = (int)System.Net.HttpStatusCode.Forbidden;
response.End();
}
catch (Exception e)
{
if (e is ApplicationException)
throw e;
// just return an empty string at this point
// -- may want to throw an exception, or add to a log file
}
return string.Empty;
}0
Please sign in to leave a comment.
Comments
1 comment