# WmsOverlay : Add a cookie within the WmsRequest

**URL:** <https://community.thinkgeo.com/t/wmsoverlay-add-a-cookie-within-the-wmsrequest/2715>\
**Category:** WPF\
**Created:** [July 5, 2010, 2:47am UTC](https://community.thinkgeo.com/t/wmsoverlay-add-a-cookie-within-the-wmsrequest/2715 "2010-07-05T02:47:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@Guillaume](https://community.thinkgeo.com/u/Guillaume)\
**Post date:** [July 5, 2010, 2:47am UTC](https://community.thinkgeo.com/t/wmsoverlay-add-a-cookie-within-the-wmsrequest/2715/1 "2010-07-05T02:47:53Z")

</div>

Hello,

I&nbsp;know&nbsp;it&nbsp;is&nbsp;no&nbsp;standard&nbsp;feature&nbsp;of&nbsp;Wms,&nbsp;but&nbsp;is&nbsp;there&nbsp;a&nbsp;way&nbsp;to&nbsp;configure&nbsp;the&nbsp;WmsOvelay&nbsp;to&nbsp;send&nbsp;a&nbsp;cookie&nbsp;with&nbsp;the&nbsp;MapRequest&nbsp;when&nbsp;using&nbsp;WmsOverlay&nbsp;?

I&nbsp;don't&nbsp;mean&nbsp;to&nbsp;add&nbsp;a&nbsp;additional&nbsp;uri&nbsp;parameter,&nbsp;but&nbsp;really&nbsp;a&nbsp;small&nbsp;cookie&nbsp;file&nbsp;in&nbsp;the&nbsp;request,&nbsp;that&nbsp;can&nbsp;be&nbsp;read&nbsp;by&nbsp;a&nbsp;custom&nbsp;code&nbsp;in&nbsp;the&nbsp;Wms&nbsp;Server.&nbsp;(it&nbsp;could&nbsp;be&nbsp;to&nbsp;send&nbsp;some&nbsp;kind&nbsp;of&nbsp;authentification&nbsp;cookie&nbsp;with&nbsp;the&nbsp;map&nbsp;requests)

Even&nbsp;if&nbsp;I&nbsp;need&nbsp;to&nbsp;inherit&nbsp;the&nbsp;WmsOverlay&nbsp;and&nbsp;to&nbsp;write&nbsp;custom&nbsp;code,&nbsp;is&nbsp;it&nbsp;possible&nbsp;to&nbsp;do&nbsp;such&nbsp;a&nbsp;thing&nbsp;?&nbsp;And&nbsp;if&nbsp;yes,&nbsp;how&nbsp;?

Thanks&nbsp;for&nbsp;your&nbsp;answer,  
  
Guillaume.

&nbsp;

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [July 6, 2010, 12:48am UTC](https://community.thinkgeo.com/t/wmsoverlay-add-a-cookie-within-the-wmsrequest/2715/2 "2010-07-06T00:48:12Z")

</div>

Hi&nbsp;Guillaume,  
  
  
  
It’s&nbsp;possible&nbsp;to&nbsp;implement&nbsp;this&nbsp;feature&nbsp;by&nbsp;inheriting&nbsp;from&nbsp;WmsOverlay&nbsp;and&nbsp;its&nbsp;UriTile.&nbsp;But&nbsp;I’m&nbsp;not&nbsp;sure&nbsp;why&nbsp;you&nbsp;want&nbsp;to&nbsp;do&nbsp;like&nbsp;this.&nbsp;If&nbsp;you&nbsp;are&nbsp;considering&nbsp;the&nbsp;authority,&nbsp;we&nbsp;can&nbsp;simply&nbsp;use&nbsp;parameters&nbsp;in&nbsp;the&nbsp;Uri&nbsp;to&nbsp;implement&nbsp;this.&nbsp;For&nbsp;example&nbsp;we&nbsp;can&nbsp;send&nbsp;a&nbsp;client&nbsp;id&nbsp;and&nbsp;an&nbsp;encrypted&nbsp;key&nbsp;within&nbsp;the&nbsp;Uri&nbsp;parameters;&nbsp;on&nbsp;the&nbsp;Wms&nbsp;server,&nbsp;we&nbsp;can&nbsp;check&nbsp;if&nbsp;this&nbsp;request&nbsp;is&nbsp;valid.&nbsp;Maybe&nbsp;there&nbsp;is&nbsp;a&nbsp;better&nbsp;way&nbsp;if&nbsp;you&nbsp;let&nbsp;us&nbsp;know&nbsp;your&nbsp;exactly&nbsp;requirement.  
  
  
  
On&nbsp;the&nbsp;other&nbsp;hand,&nbsp;I&nbsp;enhanced&nbsp;the&nbsp;API&nbsp;so&nbsp;that&nbsp;you&nbsp;can&nbsp;easily&nbsp;override&nbsp;the&nbsp;WmsOverlay&nbsp;to&nbsp;satisfy&nbsp;your&nbsp;requirement&nbsp;with&nbsp;the&nbsp;latest&nbsp;build&nbsp;4.0.63.0;&nbsp;please&nbsp;see&nbsp;the&nbsp;following&nbsp;code.  
  
`public class CookiedWmsOverlay : WmsOverlay{    protected override ThinkGeo.MapSuite.WpfDesktopEdition.Tile GetTileCore()    {        return new CookiedUriTile();    }}public class CookiedUriTile : UriTile{    protected override System.Drawing.Bitmap GetBitmapCore(UriTileArguments args)    {        HttpWebResponse response = null;        Bitmap bitmap = null;        try        {            Cookie cookie = new Cookie();            cookie.Domain = "localhost:55885";            cookie.Name = "Name";            cookie.Value = "ThinkGeo";            CookieContainer cookieContainer = new CookieContainer();            cookieContainer.Add(cookie);            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(args.Uri);            request.Proxy = args.WebProxy;            request.CookieContainer = cookieContainer;            response = (HttpWebResponse)request.GetResponse();            bitmap = new Bitmap(response.GetResponseStream());            return bitmap;        }        finally        {            if (response != null) { response.Close(); }        }    }}`  
  
  
Support@thinkgeo.com&nbsp;will&nbsp;start&nbsp;to&nbsp;work&nbsp;tomorrow&nbsp;and&nbsp;I&nbsp;think&nbsp;you&nbsp;can&nbsp;try&nbsp;it&nbsp;tomorrow;&nbsp;thanks&nbsp;for&nbsp;your&nbsp;understanding.  
  
  
  
Thanks,  
  
Howard

---

<div class="post-metadata">

**Author:** ![Guillaume](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@Guillaume](https://community.thinkgeo.com/u/Guillaume)\
**Post date:** [July 7, 2010, 7:38am UTC](https://community.thinkgeo.com/t/wmsoverlay-add-a-cookie-within-the-wmsrequest/2715/3 "2010-07-07T07:38:46Z")

</div>

Hello&nbsp;Howard,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;recieved&nbsp;the&nbsp;dlls&nbsp;from&nbsp;the&nbsp;support,&nbsp;but&nbsp;the&nbsp;files&nbsp;are&nbsp;only&nbsp;version&nbsp;4.0.59.0,&nbsp;and&nbsp;with&nbsp;this&nbsp;version&nbsp;there&nbsp;is&nbsp;no&nbsp;GetBitmapCore()&nbsp;method&nbsp;to&nbsp;override&nbsp;in&nbsp;the&nbsp;UriTile&nbsp;class.&nbsp;I&nbsp;will&nbsp;write&nbsp;them&nbsp;that&nbsp;they&nbsp;didn’t&nbsp;send&nbsp;me&nbsp;the&nbsp;right&nbsp;package.&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;goal&nbsp;is&nbsp;to&nbsp;make&nbsp;an&nbsp;authentification&nbsp;on&nbsp;the&nbsp;server,&nbsp;but&nbsp;we&nbsp;don’t&nbsp;want&nbsp;the&nbsp;authentification&nbsp;informations&nbsp;to&nbsp;be&nbsp;passed&nbsp;in&nbsp;the&nbsp;URL.&nbsp;  
&nbsp;One&nbsp;possibility&nbsp;was&nbsp;to&nbsp;send&nbsp;a&nbsp;cookie&nbsp;with&nbsp;each&nbsp;request.&nbsp;  
&nbsp;&nbsp;  
&nbsp;For&nbsp;now&nbsp;we&nbsp;are&nbsp;testing&nbsp;Windows&nbsp;Authentification&nbsp;too.&nbsp;I&nbsp;saw&nbsp;that&nbsp;there&nbsp;is&nbsp;a&nbsp;Credentials&nbsp;properties&nbsp;in&nbsp;the&nbsp;WmsLayer,&nbsp;but&nbsp;I&nbsp;could&nbsp;find&nbsp;it&nbsp;on&nbsp;the&nbsp;WmsOverlay&nbsp;class.&nbsp;Does&nbsp;it&nbsp;exists&nbsp;?&nbsp;How&nbsp;can&nbsp;I&nbsp;configure&nbsp;the&nbsp;WmsOverlay&nbsp;to&nbsp;use&nbsp;window&nbsp;identity&nbsp;in&nbsp;order&nbsp;to&nbsp;connect&nbsp;the&nbsp;WmsServer&nbsp;?&nbsp;  
&nbsp;&nbsp;  
&nbsp;If&nbsp;it&nbsp;does&nbsp;not&nbsp;exists,&nbsp;one&nbsp;possibility&nbsp;for&nbsp;us&nbsp;is&nbsp;to&nbsp;create&nbsp;a&nbsp;custom&nbsp;HttpWebRequest&nbsp;and&nbsp;set&nbsp;the&nbsp;CredentialCache&nbsp;in&nbsp;it.&nbsp;For&nbsp;that&nbsp;I&nbsp;think&nbsp;the&nbsp;code&nbsp;you&nbsp;send&nbsp;me&nbsp;is&nbsp;good,&nbsp;but&nbsp;I&nbsp;cannot&nbsp;test&nbsp;it&nbsp;yet.&nbsp;I’ll&nbsp;wait&nbsp;to&nbsp;recieve&nbsp;the&nbsp;right&nbsp;version&nbsp;(4.0.63.0)&nbsp;from&nbsp;the&nbsp;support.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Guillaume.

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [July 7, 2010, 9:29am UTC](https://community.thinkgeo.com/t/wmsoverlay-add-a-cookie-within-the-wmsrequest/2715/4 "2010-07-07T09:29:05Z")

</div>

Guillaume,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yes,&nbsp;they&nbsp;didn’t&nbsp;send&nbsp;you&nbsp;the&nbsp;right&nbsp;version.&nbsp;Please&nbsp;check&nbsp;the&nbsp;download&nbsp;list,&nbsp;I&nbsp;think&nbsp;you&nbsp;can&nbsp;download&nbsp;the&nbsp;latest&nbsp;version&nbsp;from&nbsp;there&nbsp;too.&nbsp;The&nbsp;WmsOverlay&nbsp;doesn’t&nbsp;support&nbsp;setting&nbsp;the&nbsp;credentials&nbsp;property&nbsp;because&nbsp;it&nbsp;requests&nbsp;images&nbsp;by&nbsp;get&nbsp;method&nbsp;from&nbsp;the&nbsp;merged&nbsp;uri&nbsp;directly.&nbsp;But&nbsp;acutally&nbsp;as&nbsp;you&nbsp;said,&nbsp;you&nbsp;can&nbsp;implement&nbsp;this&nbsp;feature&nbsp;by&nbsp;rewriting&nbsp;the&nbsp;GetBitmapCore&nbsp;method.&nbsp;Hope&nbsp;it&nbsp;makes&nbsp;sense&nbsp;and&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;more&nbsp;queries.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Howard

---

<div class="post-metadata">

**Author:** ![Guillaume](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@Guillaume](https://community.thinkgeo.com/u/Guillaume)\
**Post date:** [July 8, 2010, 12:42am UTC](https://community.thinkgeo.com/t/wmsoverlay-add-a-cookie-within-the-wmsrequest/2715/5 "2010-07-08T00:42:39Z")

</div>

Hi&nbsp;Howard,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thank&nbsp;you,&nbsp;I&nbsp;could&nbsp;download&nbsp;the&nbsp;right&nbsp;version&nbsp;from&nbsp;the&nbsp;download&nbsp;list,&nbsp;and&nbsp;I&nbsp;could&nbsp;overrride&nbsp;the&nbsp;GetBitmapCore&nbsp;method.&nbsp;  
&nbsp;It&nbsp;works&nbsp;good.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Many&nbsp;thanks&nbsp;for&nbsp;your&nbsp;time,&nbsp;  
&nbsp;Guillaume.

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [July 8, 2010, 1:51am UTC](https://community.thinkgeo.com/t/wmsoverlay-add-a-cookie-within-the-wmsrequest/2715/6 "2010-07-08T01:51:02Z")

</div>

Hi&nbsp;Guillaume,&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;are&nbsp;so&nbsp;welcome;&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;more&nbsp;queries.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Howard
