Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,
I have tried to create a admin login page using mvc 5. And I have followed all steps on below url, but still I am getting errors.

http://social.technet.microsoft.com/wiki/contents/articles/33229.asp-net-mvc-5-security-and-creating-user-role.aspx

below are the errors.. please help me to fix this error.
Error 1 The name 'isAdminUser' does not exist in the current context
Error 2 The name 'context' does not exist in the current context

Thank You in Advance..

What I have tried:

below is my code..
public ActionResult Index()
{
if (User.Identity.IsAuthenticated)
{
if (!isAdminUser()) // in this i am getting error and
{
return RedirectToAction("Index", "Home");
}
}
else
{
return RedirectToAction("Index", "Home");
}
var Roles = context.Roles.ToList(); // here I am getting error
return View(Roles);
}
Posted
Updated 4-Mar-16 23:45pm
Comments
Richard MacCutchan 5-Mar-16 5:44am    
Where is the code for the isAdminUser method? Where is the context object declared?

1 solution

Quote:
does not exist in the current context
This error means that the identifier that you are using does not exist in the current source file. It doesn't refer to any variable, function, class, or any other thing that compiler doesn't take as a keyword.

You need to check if a function is declared as:
C#
public static bool isAdminUser() {
   // code here
}

If not, then create it. Also, from the second part of your code. I think, you are missing the main point of Entity framework. It doesn't use "context" as the name of the object, instead it uses something like, "DbContext", "AppDataContext" and then uses the methods and properties.

Your source code is not shown, but the problem is indeed this. Read the following links for more.

c# - Name does not exist in the current context - Stack Overflow[^]
Compiler Error CS0103[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900