Use session in Silverlight

Source: Internet
Author: User

First, session runs on the server, while Silverlight runs on the client. Therefore, the session Statement in Silverlight is not accurate,

This name is only used for searching in this way.

 

There are two ways to associate Silverlight with Session:

Method 1: Use session in ASP. NET through WCF [because basichttpbinding does not support session in WCF, an error will be reported if a session is used]

First, add the following content under <system. servicemodel> in Web. config:

<Servicehostingenvironment aspnetcompatibilityenabled = "true"/>

Then: In the service class [Not an Interface] To add the following attributes:

[Aspnetcompatibilityrequirements (requirementsmode = aspnetcompatibilityrequirementsmode. Allowed)]

Next, you can use the session to remember to add a reference to system. Web.

Httpcontext. Current. session ["yourname"] = something;

Object something = httpcontext. Current. session ["yourname"];

 

Method 2: Create a static class simulation Session on the client

To save the login information, you can save the information on the client after verifying the user name and password.

Using System;
Using System. Collections. Generic;

Namespace Sessiondemo
{
Public   Static   Class Sessionmanager
{
Private   Static Dictionary < String , Object > Session =   New Dictionary < String , Object > ();

Public   Static Dictionary < String , Object > Session
{
Get { Return Sessionmanager. Session ;}
Set {Sessionmanager. Session = Value ;}
}
}
}

 

Usage:

Assignment:
Sessionmanager. session [ " Uname " ] =   " Kunal " ;< P>

value:
txbuname. text = sessionmanager. session [ " uname " ]. tostring ();

reference information: http://forums.silverlight.net/forums/t/23080.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.