Welcome to MSDN Blogs Sign in | Join | Help

      Loosely Coupled Thinking

      SOA, BPM, ISC & more...

News

  • Better Search:

    Tweets


      Reading

      About

      Not me but an incredibly realistic simulation.
      John Evdemon
      is an Architect
      at Microsoft.

      <legal-stuff>
      The views and opinions stated in this blog are mine and do not necessarily reflect those of Microsoft.
      Each posting on this blog is provided "AS IS" with no warranties, and confers no rights.
      </legal-stuff>


      Social

      View John Evdemon's profile on LinkedIn

      John Evdemon's Facebook profile



      Locations of visitors to this page

    Getting User Context in Silverlight 2

    I recently completed work on an internal Silverlight app.    The project was a blast – it really reminded me of how coding could be fun again.   One of the surprising gaps I found in Sliverlight was the inability to get the current user context (e.g. determine the login domain and userid of the person viewing the page).    I checked with the product team and they confirmed that this is not (yet?) a feature of Silverlight.   While this feature may be provided at a later date, I needed it now.   I was able to develop a workaround using ASP.NET’s LOGON_USER server variable using the following:

    <%

    String userName = Request.ServerVariables["LOGON_USER"];

    UID.Value = userName;

    %>

        <form id="form1" runat="server" style="height:100%;">

            <input type="hidden" name="userContext" id="UID" runat="server" />           

            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

            <center>

                <table border="0">

                    <tbody>

                        <tr>

                            <td width="10"></td>

                            <td width="auto">

                                <div id="silverlightControlHost">

                                    <script type="text/javascript">

                                            document.write ("<object data=\"data:application/x-silverlight,\" type=\"application/x-silverlight-2-b1\" width=\"1150px\" height=\"810px\">"); 

                                            document.write ("<param name=\"source\" value=\"ClientBin/MyApp.xap\"/> ");

                                            document.write ("<param name=\"background\" value=\"white\" />");

                                            document.write ("<param name=\"onerror\" value=\"onSilverlightError\" />");

                                            document.write("<param name=\"initParams\" value=\"userID=" + form1.UID.value + "\"");

                                            document.write("<\object>");

                                    </script>

                                </div>                   

                            </td>

                            <td width="10"></td>

                        </tr>

                    </tbody>

                </table>

            </center>           

        </form>                  

    It ain’t pretty but it works.  :)

    Posted: Friday, May 16, 2008 12:54 PM by jevdemon
    Filed under:

    Comments

    xwang said:

    Yeah, Of course it works. Since silverlight can get prameters by passing the vlaue into his parameter format. And Cons still!

    # May 19, 2008 2:36 AM

    Michael Sync said:

    Can you simply use object tag or asp:Silverlight control directly instead of using document.write?  

    # May 27, 2008 5:35 AM

    jevdemon said:

    Michael: its probably possible, I haven't looked into it.   I needed a quick and easy way to pass a dynamic parameter in and document.write seemed the easiest way to do it.   Again, it isn't pretty but it works.

    # June 3, 2008 4:31 PM

    Peter said:

    you can access the membership info via a webservice like described here:

    http://blogs.msdn.com/brada/archive/2008/05/03/accessing-the-asp-net-authentication-profile-and-role-service-in-silverlight.aspx

    I think you can get querystring variables with this:

    HtmlPage.Document.QueryString["key"]

    (as in page.htm?key=pwd)

    # July 5, 2008 8:40 PM
    New Comments to this post are disabled
    Page view tracker