Silverlight querystring alternative
I see there are similar posts on this topic but none answer my question. I a开发者_Go百科m navigating to a silverlight page and I need to pass a value to the page. For security reasons, I cant use querystring.
What are the alternatives?
Thanks
You could simply add it to an Application Context object that can be shared between views. I use this approach in my current project e.g.
public class ApplicationContext
{
#region Declarations
// Static instance of the application class.
private static ApplicationContext _instance;
#endregion
#region Constructor
public ApplicationContext()
{
}
// Static instance creator.
public static ApplicationContext Instance()
{
if (_instance == null)
{
_instance = new ApplicationContext();
}
return _instance;
}
//Shared properties e.g. Is available between all views
public SecurityContext UserContext { get; set; }
}
To use from a view:
CurrentUserContext = ApplicationContext.Instance().UserContext
So, before you navigate from one view to another simply populate relevant shared properties in the ApplicationContext object that can then be retrieved by other views.
you can use InitParams. ////set in aspx " />
private void Application_Startup(object sender, StartupEventArgs e) { var coll=e.InitParams; }
You could store the value on the web server (via your RIA data model, or post in any manner you like), then request the value when you navigate to the new page.
if it's between silverlight views, then you can have some static data bag to pass data around. This post on how to make HTTP Post in Silverlight might help you as well.
精彩评论