0
我的global.asax中的事件調用返回整數的類中的方法。我想在global.asax中的會話變量中保存這個整數,稍後我想在控制器中使用它。我嘗試了HttpContext.Current.Session.Add,但它給「對象引用未設置爲對象的實例」。我不知道如何解決這個問題,並高度讚賞任何幫助。會話爲空
下面是示例代碼
public void WSFederationAuthenticationModule_SecurityTokenValidated(object sender, SecurityTokenValidatedEventArgs e)
{
int ID = new StudentClass.GetStudentID(e.ClaimsPrincipal);
//Im trying to store this ID in a session
var ru = GetReturnUrl(Request);
if (!string.IsNullOrEmpty(ru))
{
HttpContext.Current.Response.Redirect(ru);
}
e.Cancel = true;
}
感謝。
嗨在哪種方法你設置這種方法? –
請向我展示global.asax文件的代碼。你應該把它放到session_start方法中,請嘗試 –
在全局asax文件中的WSFederationAuthenticationModule securitytokenvalidated事件下。 – USK