开发者

Accessing Cookie from C# Vxml Browser

The Microsoft.Rtc.Collaboration.AudioVideo.VoiceXml.Browser object in C# has a RunAsync method that takes a URI of a Vxml page to run and a CookieCollection that should, in theory, allow you to pass in parameters that can be used within the script. I've tried every conceivable method I can think of of getting cookies from the Vxml, and there do not seem to be any attached to the document. Any ideas on how to access the passed-in cookies from the Vxml?

At its simplist, this is what I had as the vxml:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml" xml:lang="en-US" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/vxml http://www.w3.org/TR/voicexml21/vxml.xsd" >
  <form id="QueueForm">
  <script> 
   <![CDATA[
      function GetCookie(name)
      {         
         var cookies = document.cookie;
         return cookies;
      }
   ]]>
  </script>
  <var name="cookie" expr="GetCookie('')" />
    <field name="QueueField">
      <prompt>
        <value expr="cookie" />
        were cookies
      </prompt>
      <grammar mode="dtmf" root="Dtmf">
        <rule id="Dtmf">
          <one-of>
            <item> 1 </item>
          </one-of>
        </rule>
      </grammar>
      <filled>
        <exit namelist="cookie"/>
      </filled>
    </field>
  </form>
</vxml>

And this in the calling code

_browser.SetAudioVideoCall(_call);
System.Net.CookieContainer cookies = new System.Net.CookieContainer(1);
cookies.Add(new System.Net.Cookie("data", "grapefruit", "/", "localhost"));
_browser.Run(_startPage, cookies);

...which results in a spoken "Were cookies." in all instances I tried.

I'v开发者_JS百科e tried setting different domains and paths on the cookie object, calling different Javascript objects to get the cookie different ways and anything else I could think of, but haven't been able to access the cookie. The Microsoft sample projects for Vxml also do not contain an example of accessing cookies. I'm sure there's a way to access the items that are passed in, but I haven't been able to figure out how; any thoughts?


I was the PM for the VoiceXML browser API that we shipped with UCMA 3.0. I pinged one of the developers who worked on implementing it and asked her to look into this issue. Here is her response.

The VXML Browser allows you to send a CookieContainer into the browser in the Run() and RunAsync() methods. During the course of its run, the browser will be issuing http requests to servers for vxml content. This cookie container is sent as part of the http request and any cookies sent by the server also end up in this container. This is per design.

This enables you to write dynamic servers that might serve up different vxml based on cookies sent in. You can also see the server cookie values after the session has been completed. For instance, a gold customer account might be a special dialog and the server might send you cookies helping you figure out which queue to send the call to after the browser has completed.

However, the cookies are not passed into the vxml application itself – that is, they are not accessible at the javascript level inside of the vxml document. I agree that this would be convenient, and certainly, engineers used to dealing with html browsers where they can access “document.cookie” might expect this. But the w3c vxml specification doesn’t call out standard behavior in this area and the Microsoft browser doesn’t provide this functionality.

If such functionality were desired, one engineering solution would be to have your server read the cookies and dynamically generate vxml with the cookie values set to some javascript variables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜