2013-11-28 40 views
5

我使用ASP.Net 3.5,C#,開發ID被破壞:Visual Studio的2008年。當我使用會話狀態信息是無效的,而且可能在ASP.Net

Session["FileName1"] = "text1.txt" 

它工作正常,但後來我使用

number1=17; 
string FileName1="FileName1" + number1.toString(); 

然後用

Session[FileName1]="text1.txt"; 

設置讓我運行時錯誤

會話狀態信息無效,可能會對System.Web.SessionState.SessionStateItemCollection.Deserializer(BinaryReader在讀取器)

任何人都可以解決我的問題,當我在使用Session字符串被破壞 變量?請記住它的工作原理我的開發機(意爲本地的Visual Studio)上,但在部署到服務器時,它給人提到的錯誤。

enter image description here

+0

它工作在我的本地視覺工作室,但它給我在部署它的服務器上發生錯誤。 –

+4

嘗試'string FileName1 =「text1.txt」+ Guid.NewGuid()。ToString();''Session.Add(FileName1,「text1.txt」);' – Fred

+0

您可否包含此異常的堆棧跟蹤? –

回答

5

確保FILENAME1變量不是試圖通過會話[FILENAME1]語法訪問之前空...

下面是別人說有同樣問題的鏈接: http://forums.asp.net/t/1069600.aspx

下面是他的回答:

在代碼中,我發現下面一行:

//some code 
Session.Add(sessionVarName, sessionVarValue); 
//some other code 

顯然,由於某些髒數據,有一段時間 sessionVarName爲空。

Session.Add在這種情況下不會拋出任何異常,並且如果您的會話模式爲「InProc」,則不會有任何問題。但是,如果您 會話模式是會話 店的反序列化過程中「SQLServer的」,你會得到,我得到異常。因此,要過濾掉髒 數據,我修改了代碼變成:

if (sessionVarName != null) 
{ 
    //somecode 
    Session.Add(sessionVarName, sessionVarValue); 
    //some other code 
} 
0

它們存儲在會議上他們可能會話存儲的反序列化過程導致此異常之前,請檢查你的價值觀,過濾數據。 檢查Here

if(!string.IsNullOrEmpty(FileName1)) 
{ 
    Session.Add(FileName1, "text1.txt"); 
} 

或者您在您的字符串的字符無效。

+0

它不工作..!它錯了 –

+0

@VaibhavParmar你的會話狀態模式是什麼? –

+0

我已經使用進程內會話狀態模式 –

2

您的錯誤的原因是

xyz = new Guid() is also xyz= Guid.Empty; 

所以當您嘗試轉換爲字符串時,它拋出的錯誤。

只需修改你的代碼類似的東西。

Guid guId = System.Guid.NewGuid(); 
string x = guId .ToString(); 
string FileName1="text1.txt" + x; 
Session[FileName1]="text1.txt"; 
+0

對不起我修改我沒有使用Guid我使用整數說「FileName1」+號碼 –

+0

我認爲你的問題在這一行----字符串FileName1 =「FileName1」+ number1 ;它將是字符串FileName1 =「FileName1」+ number1.toString();如果你有另一個查詢,你可以問。 –

+0

它不能解決我的問題 –

-1

您可以添加值到會話像這樣

string FileName1="FileName1" + number1.toString(); 

if(!string.IsNullOrEmpty(FileName1)) 
{ 
    Session.Add(FileName1, "text1.txt"); 
} 
相關問題