2009-06-08 37 views
6

Khi sử dụng Sql Server để lưu trữ và quản lý SessionState, dữ liệu phiên được lưu trữ trong cơ sở dữ liệu có sử dụng mã hóa không?ASP.Net SessionState sử dụng SQL Server - là dữ liệu được mã hóa?

Khi tôi xem dữ liệu trong cơ sở dữ liệu ASPNet, dữ liệu trong "SessionItemLong" trong cột ASPStateTempSessions xuất hiện dưới dạng dữ liệu thập lục phân. Dữ liệu này có được mã hóa trước khi được lưu trữ trong cơ sở dữ liệu không? Và nếu vậy, chìa khóa đang được sử dụng để mã hóa dữ liệu và thuật toán nào đang được sử dụng để mã hóa dữ liệu?

Ngoài ra, trạng thái Phiên lưu trữ đối tượng bằng cách sử dụng tuần tự hóa. Serialization nào được sử dụng? (nhị phân hoặc XML)

Trả lời

12

Không có mã hóa ở đó. Dữ liệu được lưu trữ bằng cách sử dụng serialization nhị phân (nó nhanh hơn nhiều so với xml một). Để biết chi tiết, hãy xem lớp SessionStateUtility (bạn có thể duyệt qua sử dụng free Reflector). Đây là mã được sử dụng để tuần tự:

internal static void Serialize(SessionStateStoreData item, Stream stream) 
{ 
    bool flag = true; 
    bool flag2 = true; 
    BinaryWriter writer = new BinaryWriter(stream); 
    writer.Write(item.Timeout); 
    if ((item.Items == null) || (item.Items.Count == 0)) 
    { 
     flag = false; 
    } 
    writer.Write(flag); 
    if ((item.StaticObjects == null) || item.StaticObjects.NeverAccessed) 
    { 
     flag2 = false; 
    } 
    writer.Write(flag2); 
    if (flag) 
    { 
     ((SessionStateItemCollection) item.Items).Serialize(writer); 
    } 
    if (flag2) 
    { 
     item.StaticObjects.Serialize(writer); 
    } 
    writer.Write((byte) 0xff); 
} 
+0

Bạn vừa tiết kiệm cho tôi rất nhiều thời gian (cố gắng giải mã một số BLOB từ db); cảm ơn. –

6

Tôi có vấn đề này thời gian gần đây, và đã phải mổ xẻ tình trạng lưu trữ để investigate a performance issue; mã thô giống như sau:

byte[] blob = ... // TODO 
using (var ms = new MemoryStream(blob)) 
using (BinaryReader reader = new BinaryReader(ms)) { 
    int len = reader.ReadInt32(); 
    bool f1 = reader.ReadBoolean(), f2 = reader.ReadBoolean(); 
    SessionStateItemCollection items = null; 
    HttpStaticObjectsCollection sitems = null; 
    if (f1) { 
     items = SessionStateItemCollection.Deserialize(reader); 
    } 
    if (f2) { 
     sitems = HttpStaticObjectsCollection.Deserialize(reader); 
    } 
    if (reader.ReadByte() != 0xFF) { 
     throw new InvalidOperationException("corrupt"); 
    } 
    if (items != null) { 
     int max = items.Count; 
     for (int i = 0; i < max; i++) { 
      object obj = items[i]; 
      Console.WriteLine("{0}\t{1}", items.Keys[i], 
       obj == null ? "n/a" : obj.GetType().FullName); 
     } 
    } 
} 
Các vấn đề liên quan