views:

326

answers:

1

Hi there,

I have an MVC application that among other things contains a small Silverlight menu that is displayed as part of the .Master page used in most pages.

I have also written a MembershipProvider (and a role provider) that uses my app's database for authenticating and authorizing users. Works fine.

However, I want the Silverlight menu to contain some extra items if the user is in the admin role. Of course one possibility is to make two Silverlight menu applications and choose which one to display based on the user in the master page. But this has a ring of ugly to me.

The better option would be if the Silverlight app could figure out the identity of the logged in user is and use it to configure itself to show the admin options.

Is there a simple way to do something like this? The MVC application and the Silverlight app(s) are deployed on the same IIS7 server and part of the same solution.

The solutions I have found on the web so far either prompt the user for a separate login inside the Silverlight application, or do a lot of work with WCF services. If I have to, I'll go that route, but I am stuck with a feeling that there should be an elegant, easy way to do this.

I believe firmly in the KISS principle so simplicity is highly appreciated!

Thanks!

+1  A: 

I'm pretty much convinced that your Silverlight menu shouldn't have to be aware of whether the user is an admin or not.

If you have a "generic style" menu control that can display any number of items, then I think those items should be communicated. The master view should then decide the items to show. Better yet, a controller should return the items to show based on the user's status and the master view should just render them.

If you have a menu control designed specifically to fit in your web app that isn't really made to show any number of items, then the master view should just set a property or something to communicate this fact.

The rest of your question confused me a bit, but I'm convinced that your silverlight component is not a complete "app" in its own right, just a piece of the presentation.

Dave Van den Eynde
Hi Dave, thanks for your reply. Yes, I agree the Silverlight should get the menu items from somewhere - but how can a controller know if the Silverlight application is the same user that is using the web app? AFAIK Silverlight doesn't "inherit" the cookies from the MVC app...
Rune Jacobsen
Frankly, I don't know. I'm assuming that your Silverlight 'app' is just a control that is embedded on your page.
Dave Van den Eynde
Yes, you are right - it is in no way the whole application, just a menu seamlessly integrated into each page.
Rune Jacobsen
In that case, I'm sure it's just a matter of setting the right properties from within the HTML.
Dave Van den Eynde