Updates to the Custom and Authenticating URI Mappers for Silverlight 3 RTW

by StefanOlson 3. August 2009 08:51

Update: I'd forgotten to update the sample that goes along with the download. It has now been updated to support the .net RIA services July CTP.

I’ve received a couple of requests in the past few days asking if there will be an update to the URI mappers (Updates to custom routing using the Uri Mapper in Silverlight 3 and Displaying a login dialog based on page attributes in Silverlight 3) that work with the Silverlight 3 RTW & .net RIA services July CTP. 

The CustomUriMapper works just fine with Silverlight 3. However, I have fixed one bug and provided a project you can include in your solution to make it easy to use it. You can find it under UriMapper\AuthenticatingUriMapper\CustomUriMapper.csproj.

Unfortunately I had forgotten that changes were required to get the AuthenticatingUriMapper working with the July CTP and had neglected to update it on the website.

Download

You can download the latest source code and example here.

…Stefan

Tags:

.net ria services | Silverlight

Comments

8/3/2009 10:59:04 AM #

Thanks!  going to grab that and check it out tonight.

BTW: i asked a few folks @ MSFT about adding something like your code to the nav and uri bits and / or opening up some hooks to make this less of a hassle.  sounds like they are thinking about it but no dates - just a "on the list"

Denny

8/4/2009 9:35:59 AM #

i just un-ziped and tried to build the solution.
the AuthenticatingUriMapper project compiles.
the .Web project compiles

the silverlight app fails with about 18 errors.
Error  1  The type or namespace name 'LoginCompletedEventArgs' could not be found controls\LoginControl.xaml.cs  33  64  UriMappingNavigationSample

and after some other EventArgs misisng comes:
Error  7  The name 'UserService' does not exist in the current context  \dialogs\LoginWindow.xaml.cs  23  13  UriMappingNavigationSample

I can not find any definition of "UserService" in the sample code...

there are other errors but i did not want to past all 20 here.


I can probably get this to work but I am not sure what to make of UserService?
is that some other code you wrote that is the same as the RIA auth service ?

Denny

8/4/2009 9:46:42 AM #

Denny,

Opps! I didn't actually check the sample application. I just updated the project and the files required for that. I'll update the sample application and get it up in the next couple of hours.

...Stefan

StefanOlson

8/4/2009 10:04:56 AM #

No big i am going thru some of it and you have:
public partial class LoginControl ,
UserService.Current.LogoutCompleted += ...
but the default  code is:
      private AuthenticationService _authService = RiaContext.Current.Authentication;
   _authService.LoggedIn += Authentication_LoggedIn;

that stuff is not hard to match up...

now to see what else i find

Denny

8/4/2009 2:18:09 PM #

Denny,

I've now uploaded an update (same download Url) which includes a fully working sample for the July CTP. Thanks for letting me know about the problem!

In the end I just rebuilt completely from scratch, because it was quicker to use the new business application template than try and integrate things backwards.

...Stefan

StefanOlson

8/9/2009 4:16:06 AM #

Hey thanks! just got back to the project and saw that you had updated it.
Yeah this will be a lot less hassle to add to stuff.

I *HOPE* that the next set of RIA code drops will not have so much of a change to things... and that we get a Beta / RC before to much longer as it's getting closer to time for VS 2010 to get RTM -- yeah still a ways to go but not really that long.

I saw some of your blog post on the forms issues, i have been on codeplex and filed a couple of bugs with them.
here is the really strange one though:

take a realy smiple app and add the theme dll namespace and then add the theme by using the <theme:theme> tag method in the xaml.
run the app and it works, open it with blend and that works, then try and do a vs debug and it will throw an ex that has to do with something in the theme about datagrids....
also the themes have problems with some controls, the datepicker for example the text is like white on white when using several different themes, how can anyone use them?  this is not on all controls just on some, seems like the toolkit controls are the ones that it breaks.

Denny

8/9/2009 1:54:16 PM #

Denny,

Brad Abrams has indicated they have made most of the major changes they need to make before the release of ria services - will probably be made next year before the final release is ready. There will be another ria services preview at PDC in November and I expect Visual Studio 2010 Beta 2 will be available at that point.

As far as themes go, I haven't even tried to experiment with him. If you just read how it works in a theoretical sense one could imagine that it would be very simple to cause it to break. The underlying problem here is the fact that Silverlight doesn't support WPF's implicit styles where you can define a style which is applied to any button or data grid etc.  this thing works with every control.

Hopefully Silverlight 4 well have implicit styles and that will resolve the problem. Iin the meantime I do suspect you will encounter a number of problems.

..Stefan

StefanOlson

8/12/2009 11:24:35 PM #

what's funny with the themes is that the controls that seem to have the main problems are the ones from the toolkit that combine a textbox with some addon bits.
numeric up /down and datepicker beeing the first two i saw.
but the standard dropdown works fine with the themes i have tried.
so there is something different about how the date picker and some others are implimented i guess... possibly this weekend i will look at the code from the tool kit and see if i can find anything about the root of the problem.

but as you say it would be good for silverlight and wpf to be as close to the same xmal / layout / objects etc... as can be.  I think that the more they are made the same the better for getting more developers and designers to see them as the next thing to adopt.  having differences between them makes moving back and forth harder than it should be and having them closer in model and markup just feels better to me.

I work with the desktop .net and the compact framework and with asp.net and I like to keep the same code in as many places as i can so that if it's right (not buggy) in one place it should be right on all of them, aside from the limits of net cf and sl beeing smaller etc...

Denny

8/26/2009 6:13:55 AM #

I am experimenting with the sample project and have a question. Great code by the way.

The AuthenticatingUriMapper, works fine if used on the main page to navigate, and when RequiresRoles is set for some code and this is used:


ContentFrame.Navigate(new System.Uri("Default", UriKind.Relative));  

If I am in a different page away from Main that I have naviaged to, and then I have to use the NavigationService to go to a third page, the RequireRoles does not work.

NavigationService.Navigate(new Uri("Test"), UriKind.Relative));

Is this supported by this somehow?

Thanks.

Gligorov

10/5/2009 10:21:44 PM #

Hi Stefan,
thank you for your code.
I have some little issues:

1) When authentication timeout occurs on server, user keeps on using every protected page (just set form timeout from web.config and wait timeout from client).
I didn't found any solution to be aware from client that authentication is ended on server, unless calling RiaContext.Current.Authentication.LoadUser() every page access and wait LogOut event is raised.

2) Sometimes (not always), using F5 to refresh, it asks me to log in again despite I was already logged. This is due to the fact that when you call AuthorizationAttribute.Authorize() in AuthenticatingUriMapper.CheckAttributesForPage() method you cannot be sure that LoadUser() ria services call is completed. LoadUser() is called in mainpage constructor and I think you need to wait the end of this method to authorize a page.

--------

Maybe, to solve both issues, you need to use LoadUser() inside AuthenticatingUriMapper, not in MainPage.

--------

I hope this is clear and useful

Gianluca

Gianluca

10/6/2009 2:13:03 PM #

Gianluca,

Thanks for these details.  

1) If I set the wait timeout to be 1 and then try and load a page that requires authentication it doesn't let me access the page because the client doesn't have the appropriate permissions.  Is there another detail that I am missing to be able to repeat the problem?

2) I'll have a think about the F5 situation. If you called LoadUser() inside the mapper you would either have to only call it the first time you needed it - to verify the user could be loaded, or call it every time.  Calling it every time would simply be too slow.

...Stefan

StefanOlson

10/6/2009 2:14:52 PM #

Gligorov,

I'm not sure why they would be happening, because it should call the URI mapper either way.  If you stick a breakpoint in AuthenticatingUriMapper::CheckCanNavigateToUri, does that you called in your second situation?

One alternative would be to create a static variable so that you can access the frame from anywhere in your project.

...Stefan.

StefanOlson

2/18/2010 7:15:36 PM #

Displaying a login dialog based on page attributes in Silverlight 3

Displaying a login dialog based on page attributes in Silverlight 3

Stefan Olson's Blog

Add comment




biuquote
  • Comment
  • Preview
Loading



About the author

Stefan Olson is the Managing Director of Olson Software.  He has been developing software using Microsoft Technologies for nearly 20 years.

He is currently working on building the next generation Virtual Tour software in WPF and Silverlight for www.palacevirtualtours.com.

Tag cloud