I founded some articles in here and I try customize authorize using seesion, but seem it's not work fine. Notes, I code hard in authorize with pass parameter from session. This is my code snippet. Example:
[RMSAuthorize]
public ActionResult TopicDetail()
{
return View();
}
And this is custom authorize
public class RMSAuthorize : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
//get Group_ID from session when user login success
//if user not login then session is NULL
var GID = (HttpContext.Current.Session["CurrentUser"] as USER).Group_ID;
if (GID = "G0001")
{
return true;
}
else
{
return false;
}
}
}
Ok, when build, I get error at var GID = (HttpContext.Current.Session["CurrentUser"] as USER).Group_ID;
as Object reference not set to an instance of an object
Can you tell me what problem in here ? I wrong or mistake some anything and how to fix it ? .Thank you so much.