Tag: Silverlight

Silverlight 4–Out of Browser Authentication

One of the things that was very difficult to find, even in silverlight forums, was a way to know, in a simple way, what user is authenticated when a Silverlight 4 application is running Out-Of-Browser. I’ve found many information about using WCF, RIA, etc, buts it was not what I wanted. So, I investigated a little more about trying to find out how isolated was Silverlight from windows.

At first sight, Silverlight should act as flash, isolated  as possible from the OS, but when running in Windows (as out-of-browser, thank you Microsoft for this “Air” copy”), I should access windows stuff, since I’m exclusively running in Windows, so the isolated thing doesn’t matter anymore! Wrong! I can access only some windows stuff! The .NET framework for Silverlight it’s a little bit “small” in features!

My first try, was to connect to SharePoint using ClientContext from Sharepoint Client API for Silverlight (My application needs some SharePoint list items). When inside SharePoint I just ask about “who am I”, and SharePoint , running in a windows domain, should respond to me with the authenticated user! Was successful! But with some hick ups every time someone from systems staff changed IIS Windows Authentication configuration or some SharePoint tweaks. The problem: I want to run an application and I need to use a SharePoint just to ask about “Who I am”? Yes, you are right! As we say in Portugal, “A cannon to kill a fly”.

Since my Silverlight app its running out of browser I needed to find a way to use directly windows. I thinks it’s a logic thinking!

When a Silverlight App its running outside browser with Elevated Privileges it can access COM stuff! Well, with this “opening”, the sky it’s the limit!

Thanks to “dynamic” word from C# we can do this:

            using (dynamic ad = AutomationFactory.CreateObject("ADSystemInfo"))
            {
                var usernamedn = ad.UserName;
                var computernamedn = ad.ComputerName;
                var DomainDNSNamedn = ad.DomainShortName;

                string us = usernamedn.ToString();
                us = us.Substring(3, us.IndexOf(',') - 3);
                username = string.Format(@"{0}\{1}", DomainDNSNamedn, us);
            }

As you may see, I use a COM Object that returns Active Directory information, including the User logged in.  (OK, the format it’s the AD CN=xxx,CN=xxx, but I now we have a door to the windows, very useful!

Silverlight 4–StackPanel, Scrollbars, effects, others….sometimes its better not!

I really like Silverlight 4, and in the last months I ‘ve developed a Silverlight App which communicates with WCF which by the way talks to Sharepoint 2010 and Sql Server 2008R2. Well, with all this complexity, as you may guess I had to learn a lot about handlind strange bugs and problems…

Below, some of them with my solutions… a few more in later posts.

Stackpanel & Grid

You have a Grid with scrollbars, but they don’t show when data reach the bottom of the window or panel.

If you have a Grid inside a Stackpanel, see a way to remove the Stackpanel. You can use a DockPanel for instance.

AutoCompleteBox & Popup Window

When you use a AutoCompleteBox the dropdown window appears on the upper left corner of your popup window.

See if you are using Effects and remove them. It’s a well know bug… maybe at this time its fixed… or not..

ChildWindow and DialogResult

You want to call a ChildWindow as a DialogBox and collect the final DialogResult.

It will not work, because Silverlight uses an Async model. You need to create a delegate (which will point to a “local” method that will handle the result), pass it on the constructor and inside the childwindow, when you are ready to exit, call the “delegate” method and then exit.

PS: If you need an example give me a call…

MVVM

You will have some forms and communications to outside Silverlight, for instance WCF.

Please use, MVVM or similar pattern, you will need if your Silverlight app grows. I had to refactor my app, because I didn’t follow this pattern from the beginning.

You can find more about this pattern here:

Bad Behavior has blocked 93 access attempts in the last 7 days.

Hyper Smash