0

As per the application design, we don't need to maintain Users/Roles information inside our database.

I enter my Employee ID, and I select RATES_AMAR_ANALYST from the profile dropdown list.

As I selected RATES_AMAR_ANALYST from profile dropdown list, my role is ANALYST.

I am using FormsAuthentication to impliment login, logout functionality.

Below is the code written in LogOff functionality.

public ActionResult LogOff(string returnUrl = "")
{
    FormsAuthentication.SignOut();
    Session.Abandon();
    return RedirectToAction("Login", "Account");
}

I have written AuthorizeAttribute for some business requirement. Hence, registered the same in FilterConfig.cs file as shown below.

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new HandleErrorAttribute());
    filters.Add(new SOCOAuthorizeAttribute(string.Empty));
}

I have written the following setting in Web.config file to enable forms Authentication.

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2" slidingExpiration="true" enableCrossAppRedirects="false" protection="All"></forms>
</authentication>

To validate my code, I am trying to access Dashboard URL without login. I am getting below error. But, I want the page to be redirected to Login page instead.

enter image description here

Can anyone please suggest me how to get my work done!

Ashok kumar
  • 1,593
  • 4
  • 33
  • 68
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – David Oct 29 '18 at 12:01
  • Sounds like `pnlUser` is `null` in the view. What is that object and where do you expect it to be set? – David Oct 29 '18 at 12:03
  • @David: pnlUser is available if user can login properly. – Ashok kumar Oct 29 '18 at 12:16
  • Well, it would appear you're trying to access an object which isn't set. The linked duplicate contains helpful information about what that means and how to address it. You need to either correct why the object isn't being set, or check for null before trying to use it. – David Oct 29 '18 at 12:30

0 Answers0