Use Session in MVC or not?

I'm reviewing this junior developer's code and he's used Session. I think there's a better way of doing this and not use Session. I also read somewhere, a while back, not to use Session.

He doesn't clear the session.

  if (search.Schedule.Invoices.Any())
            {
                Session["leaseSched"] = search.Schedule.LeaseNoSchedule;
            }

and then in a link

<div class="btn-group pull-right">
    <h5>@Display <a href="@Url.Action("Detail", "Schedule", new { @id = Model.ScheduleID })">@Session["leaseSched"].ToString()</a></h5>
</div>

Any arguments against using Session in MVC?
LVL 8
CamilliaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
It depends on what you're using it for.

If it's only for redirects, you can get away with TempData.

A good place for learning the differences between TempData and session:
https://www.c-sharpcorner.com/blogs/tempdata-vs-session-in-mvc1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CamilliaAuthor Commented:
Thanks, Kyle. I think TempData is better.
0
käµfm³d 👽Commented:
If it's only for redirects, you can get away with TempData.
TempData actually uses session under the hood.
0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

CamilliaAuthor Commented:
Ha, didnt know. The link Kyle posted lists the differences.
0
CamilliaAuthor Commented:
I've been reading about use of session in mvc . Looks like session is not the best practice.
0
Kyle AbrahamsSenior .Net DeveloperCommented:
TempData actually uses session under the hood.

Yes, but only for the redirect.  Normal session keeps it live even after the page is loaded.
0
käµfm³d 👽Commented:
Agreed, but I mention it because that means if you use TempData, then you can't disable session for your app.
0
CamilliaAuthor Commented:
Thanks, Kauf. Makes sense. I thought you meant there's no difference between using session or tempdata.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.