无法创建管理员登录页面 [英] Unable to create admin login page

查看:71
本文介绍了无法创建管理员登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试使用mvc 5创建管理员登录页面。我已按照以下网址的所有步骤操作,但仍然收到错误。



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



以下是错误..请帮我修复此错误。

错误1当前上下文中不存在名称'isAdminUser'

错误2当前上下文中不存在名称上下文



提前感谢您..



我尝试过:



以下是我的代码..

public ActionResult Index()

{

if(User.Identity.IsAuthenticated)

{

if (!isAdminUser())//在此我收到错误并且

{

返回RedirectToAction(Index,Home);

}

}

else

{

返回RedirectToAction(索引,首页);

}

var Roles = context.Roles.ToList(); //这里我收到错误

返回查看(角色);

}

解决方案

引用:

在当前上下文中不存在

此错误表示您使用的标识符在当前源文件中不存在。它不引用任何变量,函数,类或编译器不作为关键字的任何其他东西。



您需要检查函数是否声明为:

  public   static   bool  isAdminUser(){
// 这里的代码
}



如果没有,然后创建它。另外,从代码的第二部分开始。我想,你错过了Entity框架的要点。它不使用context作为对象的名称,而是使用类似DbContext,AppDataContext之类的东西,然后使用方法和属性。



您的源代码未显示,但确实存在问题。阅读以下链接了解更多信息。



c# - 当前上下文中不存在名称 - Stack Overflow [ ^ ]

编译器错误CS0103 [ ^


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);
}

解决方案

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:

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[^]


这篇关于无法创建管理员登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆