# Unable to display a protected WMS layer

**URL:** <https://community.thinkgeo.com/t/unable-to-display-a-protected-wms-layer/2300>\
**Category:** WinForms\
**Created:** [October 2, 2013, 8:44am UTC](https://community.thinkgeo.com/t/unable-to-display-a-protected-wms-layer/2300 "2013-10-02T08:44:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LE\_SOMMER](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/l/a87d85/32.png) [@LE\_SOMMER](https://community.thinkgeo.com/u/LE_SOMMER)\
**Post date:** [October 2, 2013, 8:44am UTC](https://community.thinkgeo.com/t/unable-to-display-a-protected-wms-layer/2300/1 "2013-10-02T08:44:24Z")

</div>

Hello,  
  
  
  
I&nbsp;am&nbsp;using&nbsp;“Map&nbsp;Suite&nbsp;Desktop&nbsp;Evaluation&nbsp;Edition&nbsp;7.0”&nbsp;and&nbsp;I&nbsp;am&nbsp;trying&nbsp;to&nbsp;connect&nbsp;to&nbsp;this&nbsp;WMS&nbsp;server&nbsp;:  
  
[bgis.benomad.com/bgis/wms?LA…HEIGHT=512](http://bgis.benomad.com/bgis/wms?LAYERS=&VERSION=1.3.0&FORMAT=image%2Fpng&CRS=EPSG%3A4326&EXCEPTIONS=INIMAGE&SERVICE=WMS&REQUEST=GetMap&STYLES=&BBOX=40.75561640931422,1.1334246139713233,46.13342461397133,6.511232818628431&WIDTH=512&HEIGHT=512)  
  
This&nbsp;server&nbsp;is&nbsp;protected&nbsp;with&nbsp;a&nbsp;login/password.&nbsp;I&nbsp;can&nbsp;give&nbsp;you&nbsp;them&nbsp;by&nbsp;PM.  
  
  
  
I&nbsp;tried&nbsp;many&nbsp;things&nbsp;like&nbsp;“Credential”&nbsp;or&nbsp;the&nbsp;event&nbsp;“SendingWebRequest”&nbsp;but&nbsp;i&nbsp;have&nbsp;a&nbsp;exception&nbsp;when&nbsp;i&nbsp;use&nbsp;the&nbsp;“Open”&nbsp;method&nbsp;of&nbsp;the&nbsp;WmsRasterLayer&nbsp;object.  
  
  
  
In&nbsp;fact,&nbsp;i&nbsp;don’t&nbsp;know&nbsp;if&nbsp;this&nbsp;problem&nbsp;is&nbsp;due&nbsp;to&nbsp;a&nbsp;wrong&nbsp;login/pwd&nbsp;setting&nbsp;or&nbsp;if&nbsp;this&nbsp;WMS&nbsp;server&nbsp;is&nbsp;not&nbsp;standart  
  
  
  
Thanks  
  
  
  
Thierry

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [October 3, 2013, 4:01am UTC](https://community.thinkgeo.com/t/unable-to-display-a-protected-wms-layer/2300/2 "2013-10-03T04:01:05Z")

</div>

Hi&nbsp;Thierry,&nbsp;  
  
  
  
Could&nbsp;you&nbsp;please&nbsp;paste&nbsp;your&nbsp;exception&nbsp;information&nbsp;here?&nbsp;  
  
  
  
I&nbsp;am&nbsp;not&nbsp;sure&nbsp;whether&nbsp;this&nbsp;WMS&nbsp;server&nbsp;support&nbsp;login&nbsp;parameters&nbsp;or&nbsp;not.&nbsp;  
  
  
  
If&nbsp;it&nbsp;support&nbsp;login&nbsp;parameters,&nbsp;you&nbsp;can&nbsp;get&nbsp;the&nbsp;request&nbsp;url&nbsp;from&nbsp;“SendingWebRequest”&nbsp;event,&nbsp;then&nbsp;add&nbsp;your&nbsp;username/password&nbsp;int&nbsp;it&nbsp;and&nbsp;open&nbsp;it&nbsp;in&nbsp;browser&nbsp;for&nbsp;test.&nbsp;  
  
  
  
If&nbsp;it&nbsp;only&nbsp;support&nbsp;credential,&nbsp;as&nbsp;below&nbsp;is&nbsp;a&nbsp;sample&nbsp;code&nbsp;for&nbsp;that:&nbsp;  
  
  
  
wmsRasterLayer.Credentials&nbsp;=&nbsp;new&nbsp;MyCredential();  
public&nbsp;class&nbsp;MyCredential&nbsp;:&nbsp;ICredentials  
{  
&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;NetworkCredential&nbsp;GetCredential(Uri&nbsp;uri,&nbsp;string&nbsp;authType)  
&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NetworkCredential&nbsp;myCredential&nbsp;=&nbsp;new&nbsp;NetworkCredential(“UserName”,&nbsp;“Password”,&nbsp;“Domain”);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;myCredential;  
&nbsp;&nbsp;&nbsp;&nbsp;}  
}  
&nbsp;  
If&nbsp;that’s&nbsp;different&nbsp;with&nbsp;how&nbsp;you&nbsp;tested&nbsp;before,&nbsp;please&nbsp;try&nbsp;it.  
  
  
  
Regards,&nbsp;  
  
  
  
Don

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [October 3, 2013, 10:02am UTC](https://community.thinkgeo.com/t/unable-to-display-a-protected-wms-layer/2300/3 "2013-10-03T10:02:11Z")

</div>

Hi&nbsp;Thierry,&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;found&nbsp;two&nbsp;topic&nbsp;maybe&nbsp;helpful.&nbsp;Please&nbsp;login&nbsp;and&nbsp;view&nbsp;the&nbsp;header&nbsp;for&nbsp;make&nbsp;sure&nbsp;whether&nbsp;that&nbsp;works&nbsp;for&nbsp;you.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Please&nbsp;notice&nbsp;these&nbsp;items:&nbsp;  
&nbsp;1.&nbsp;Try&nbsp;http&nbsp;and&nbsp;https&nbsp;  
&nbsp;2.&nbsp;Try&nbsp;set&nbsp;PreAuthenticate&nbsp;equal&nbsp;true&nbsp;or&nbsp;false&nbsp;  
&nbsp;3.&nbsp;If&nbsp;that’s&nbsp;NTLM,&nbsp;please&nbsp;try&nbsp;this:&nbsp;webRequest.Credentials&nbsp;=&nbsp;new&nbsp;CredentialCache().Add(uri,&nbsp;“Basic”,&nbsp;new&nbsp;NetworkCredential(“username”,&nbsp;“password”));&nbsp;  
&nbsp;&nbsp;  
&nbsp;[stackoverflow.com/questions/1702426/httpwebrequest-not-passing-credentials](http://stackoverflow.com/questions/1702426/httpwebrequest-not-passing-credentials)&nbsp;  
&nbsp;[stackoverflow.com/questions/5207660/401-unauthorized-returned-on-get-request-https-with-correct-credentials](http://stackoverflow.com/questions/5207660/401-unauthorized-returned-on-get-request-https-with-correct-credentials)&nbsp;  
&nbsp;&nbsp;  
&nbsp;Wish&nbsp;these&nbsp;information&nbsp;is&nbsp;helpful.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Don

---

<div class="post-metadata">

**Author:** ![LE\_SOMMER](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/l/a87d85/32.png) [@LE\_SOMMER](https://community.thinkgeo.com/u/LE_SOMMER)\
**Post date:** [October 4, 2013, 3:58am UTC](https://community.thinkgeo.com/t/unable-to-display-a-protected-wms-layer/2300/4 "2013-10-04T03:58:22Z")

</div>

Thanks  
  
  
  
Your&nbsp;messages&nbsp;helped&nbsp;me&nbsp;to&nbsp;find&nbsp;the&nbsp;solution  
  
  
  
I&nbsp;just&nbsp;added&nbsp;this&nbsp;:

> `Private`&nbsp;`Sub`&nbsp;`Wms_SendingWebRequest(sender ``As`&nbsp;`Object``, e ``As`&nbsp;`ThinkGeo.MapSuite.Core.SendingWebRequestEventArgs)`  
> `Dim`&nbsp;`sUsername ``As`&nbsp;`String`&nbsp;`= ``"XXX"`  
> `Dim`&nbsp;`sPassword ``As`&nbsp;`String`&nbsp;`= ``"YYY"`  
> `Dim`&nbsp;`credentialBuffer ``As`&nbsp;`Byte``() = ``New`&nbsp;`System.Text.UTF8Encoding().GetBytes(sUsername + ``":"`&nbsp;`+ sPassword)`  
> `e.WebRequest.Headers(``"Authorization"``) = ``"Basic "`&nbsp;`+ Convert.ToBase64String(credentialBuffer)`  
>   
> `End`&nbsp;`Sub`

  
Maybe&nbsp;there&nbsp;is&nbsp;a&nbsp;better&nbsp;way&nbsp;to&nbsp;do&nbsp;this&nbsp;?

---

<div class="post-metadata">

**Author:** ![Summer1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@Summer1](https://community.thinkgeo.com/u/Summer1)\
**Post date:** [October 4, 2013, 7:54am UTC](https://community.thinkgeo.com/t/unable-to-display-a-protected-wms-layer/2300/5 "2013-10-04T07:54:10Z")

</div>

Hi&nbsp;Sommer,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Great&nbsp;to&nbsp;hear&nbsp;the&nbsp;problem&nbsp;is&nbsp;sorted&nbsp;out,&nbsp;following&nbsp;code&nbsp;should&nbsp;also&nbsp;provide&nbsp;you&nbsp;a&nbsp;basic&nbsp;idea&nbsp;fot&nbsp;it:&nbsp;  
&nbsp;&nbsp;  
&nbsp;WmsRasterLayer.Parameters.Add("id",yourID)&nbsp;  
&nbsp;&nbsp;  
&nbsp;WmsRasterLayer.Parameters.Add("pasword",yourPassword)&nbsp;  
&nbsp;&nbsp;  
&nbsp;Hope&nbsp;it&nbsp;helps&nbsp;  
&nbsp;&nbsp;  
&nbsp;Summer&nbsp;
