简体   繁体   English

我可以在我的aspx页面和silverlight应用程序中共享会话变量吗?

[英]Can I share session variables in my aspx pages and in the silverlight application?

I have to create a publish-subscribe silverlight application. 我必须创建一个发布 - 订阅silverlight应用程序。 and the class that publishes the events is in a class library. 并且发布事件的类位于类库中。

I have a .Net web solution which contains Silverlight project and an asp.net web project. 我有一个.Net Web解决方案,其中包含Silverlight项目和一个asp.net Web项目。 The asp.net project uses some classes in a class library. asp.net项目使用类库中的一些类。 These classes expose some events and once triggered, I get the returned data and store them in my session variables. 这些类暴露了一些事件,一旦触发,我得到返回的数据并将它们存储在我的会话变量中。

I have created few session variables - mainly List types. 我创建了几个会话变量 - 主要是List类型。

I want to launch silverlight xaml page by redirecting the user to the aspx page which contains the silverlight plugin. 我想通过将用户重定向到包含silverlight插件的aspx页面来启动silverlight xaml页面。

I want to use the List which are in the session variables and show them in a data grid. 我想使用会话变量中的List并在数据网格中显示它们。

Can I share the session variable between aspnet and silverlight app? 我可以在aspnet和silverlight应用程序之间共享会话变量吗? What should be the best way to achieve this push-pull target that when the class throws an event, I get the data and display in a silverlight chart and the chart gets refreshed when the class publishes a new event? 什么应该是实现这个推拉目标的最佳方法,当类抛出一个事件时,我获取数据并显示在silverlight图表中,当该类发布新事件时图表会刷新?

You can't share session variable between ASP.NET and Silverlight. 您无法在ASP.NET和Silverlight之间共享会话变量。 The reason is easily understandable: ASP.NET runs serverside, Silverlight runs ClientSide. 原因很容易理解:ASP.NET运行服务器端,Silverlight运行ClientSide。

However you can get these informations from the client, through a webservice call. 但是,您可以通过Web服务调用从客户端获取这些信息。 Using WCF for instance, you can activate ASP.NET session for the WebService, and send in the service these informations to the client, with a proper serialization. 例如,使用WCF,您可以为WebService激活ASP.NET会话,并使用正确的序列化将服务中的这些信息发送到客户端。 To achieve good results, good understanding of the serialization of your session data is required (such as, with WCF, returning typed data). 要获得良好的结果,需要很好地理解会话数据的序列化(例如,使用WCF,返回类型化数据)。

For informations about activating ASP.NET session for a WCF service, see this 有关为WCF服务激活ASP.NET会话的信息, 请参阅此

Keep in mind too that because default ASP.NET sessions management use cookies to store the session token client side, if your Silverlight application bypass the browser network stack, you will have to manage the cookie yourself. 请记住,因为默认的ASP.NET会话管理使用cookie来存储会话令牌客户端,如果您的Silverlight应用程序绕过浏览器网络堆栈,您将必须自己管理cookie。 Fortunately, Silverlight uses the browser stack by default. 幸运的是,Silverlight默认使用浏览器堆栈。

Please check this out "How can I access the ASP.NET session in Silverlight?" 请查看“我如何在Silverlight中访问ASP.NET会话?”

http://forums.silverlight.net/forums/t/167001.aspx#_Toc251772491 http://forums.silverlight.net/forums/t/167001.aspx#_Toc251772491

I hope it will be helpful. 我希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM