TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abhishek Sharma
NA
49
2.9k
Session Goes Null When I am Trying Getting Session Value
Jun 11 2019 5:19 AM
Hi, I am Facing an issue with session. I am creating a session like:
(
Game = Players;
Session["Game"] = Game;
)
But When I am Trying to use This Session in Another Action Mehtod Then I am Getting Null value . i have allready Rnd on this topic but I am find nothing in google
if
(Session[
"Game"
] !=
null
)
{
test =
true
;
}
PlayGame = (Players)Session[
"Game"
];
Please give me a suggestion for That How to fix this issue
Here is My Code:-
1. > Code Where I am Creating Session
public
ActionResult EnterGame(Players Players)
{
if
(!(
string
.IsNullOrEmpty(Players.FirstPlayer) &&
string
.IsNullOrEmpty(Players.SecondPlayer)))
{
Players Game =
new
Players();
Players.DefaultPlayer = Players.FirstPlayer;
Game = Players;
Session[
"Game"
] = Game;
bool
test;
if
(Session[
"Game"
] !=
null
)
{
test =
true
;
}
return
View(
"PlayGame"
, Game);
}
else
{
ModelState.AddModelError(
string
.Empty,
"Both Players Name,s Are Required"
);
return
View(
"Index"
, Players);
}
}
###### Code Where I am use Session to initilize The Session Data
public
ActionResult PlayGame(
int
index) {
Players PlayGame =
new
Players();
bool
test;
if
(Session[
"Game"
] !=
null
)
{
test =
true
;
}
PlayGame = (Players)Session[
"Game"
];
PlayGame Game =
new
PlayGame();
Game.Play(index, PlayGame);
if
(Game.IsWon ==
true
)
{
var Result =
new
{ Message = Game.Message, IsWon = Game.IsWon, AssignedValue = Game.AssignedValue };
return
Json(Result, JsonRequestBehavior.AllowGet);
}
else
{
var Result =
new
{ Message = Game.Message, DefaultPlayer = PlayGame.DefaultPlayer, AssignedValue = Game.AssignedValue };
return
Json(Result, JsonRequestBehavior.AllowGet);
}
}
Reply
Answers (
1
)
c# Dynamic button to difference event
How to write Business Logic for change password?