0
Cannot perform runtime binding on a null reference error

I am getting this error in a partial view.

loginUserExists = Membership.ValidateUser(UserNameLogin, PasswordUserLogin);
if (loginUserExists==false)
{
    return;
}
FormsAuthentication.SetAuthCookie(UserNameLogin, true);

This is my partial view which produces the error.

@*This is where the error happens*@
**@if (!Page.User.Identity.IsAuthenticated)**
{
    <li><a href="@Url.Action("LoginForm", "Home")">Login</a></li>
    <li><a href="@Url.Action("RegisterForm", "Home")">Register</a></li>
}
else
{

    <li><a href="@Url.Action("LoginForm", "Home")">Logout</a></li>
    if (Model.FirstName != null)
    {
        <li><label id="labUserName">@Model.FirstName</label></li>
    }
}

The partial view is nested in the Layout page.

Insight perhaps as to why I get this and how to overcome it?

regards

1 Answer 1

1

Try Request.IsAuthenticated instead:

@if (!Request.IsAuthenticated)
{
    // ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.