Results 1 to 2 of 2

Thread: Share Session State Across Different ASP.NET Project

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Location
    india
    Posts
    95

    Share Session State Across Different ASP.NET Project

    hi,

    in my team we are developing c# project and vb.net project. After combining these two project (adding Ref of C# project and VB.NET Proj) i m not able to share the session state from vb.net proj to C# project.
    is thr any wat to share these session values across two projects?.

    Thaniking u

    v.r.mahendran

  2. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Share Session State Across Different ASP.NET Project

    Are you using StateServer Service? Are you using VS.Net or are the file hashed together in a directory?

    One way would be to use a serialize your session variables to a direcotry.

    Write a class in vb and in C# to access that dir as the state server.
    Code:
    		/// <summary>
    		/// Load a serialization file saved with the Save(file) method.
    		/// </summary>
    		/// <param name="file">Full file path and file name of the serialization file to load from.</param>
    		/// <returns>An object to be cast to the correct type.</returns>
    		public object Load(string file)
    		{
    			object o = null;
    			System.IO.FileStream  fs;
    			System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf;
    
    			if(!System.IO.File.Exists(file))
    			{
    				fs = System.IO.File.Open(file, System.IO.FileMode.Open);
    				bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
    			
    				o = bf.Deserialize(fs);
    				fs.Close();
    			}
    			return o;
    		}
    		
    		/// <summary>
    		/// Save a serialzation file.
    		/// </summary>
    		/// <param name="file">The full path and file name of the file to serialize to.</param>
    		public void Save(string file)
    		{
    			System.IO.FileStream fs;
    			System.Runtime.Serialization.Formatters.Binary.BinaryFormatter  bf;
    			if(!System.IO.File.Exists(file))
    			{
    				fs = System.IO.File.Create(file);
    				bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
    
    				bf.Serialize(fs, this);
    				fs.Close();
    			}
    			else
    			{
    				fs = System.IO.File.Open(file, System.IO.FileMode.Truncate);
    				bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
    
    				bf.Serialize(fs, this);
    				fs.Close();
    			}
    		}
    Of course your objects have to [System.Serializable] or ISerializable for that to work. You could create a Util class or Module to do the work and add an IDirState or something.. this would also let console apps and any other apps all share the same state info.....
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width