user2004
user2004

Reputation: 1973

how to change type of object in razor page

I have a cshtml file with the folloowing code

  @if (Session.CurrentUser == null)
                        {
                            <li>@Html.ActionLink("Register", "Register", "Account")</li>
                            <li>@Html.ActionLink("Login", "Login", "Account")</li>
                        }

The Session obj comes from this class i've made

 public class BaseController : Controller
    {
        protected Services Services { get; private set; }
        protected new SessionWrapper Session { get { return SessionWrapper.Instance; } }
        protected ConfigWrapper Config { get { return ConfigWrapper.Instance; } }

        public BaseController()
        {
            Services = new Services();
        }
    }

so session is SessionWrapper type and it has a CurrentUser property in it. In my cshtml file, Session is type HttpSessionStateBase How do I change the type? I have tried with SessionWraper.CurrentUser

Upvotes: 0

Views: 214

Answers (1)

Christian Phillips
Christian Phillips

Reputation: 18769

Try changing the variable name:

protected SessionWrapper sessionWrapper;

public BaseController()
        {
            Services = new Services();
            sessionWrapper = new SessionWrapper.Instance;
        }

And the same in the razor page:

@if (sessionWrapper.CurrentUser == null)

The issue you are getting here is that Session is reserved

Upvotes: 1

Related Questions