我在我的控制器文件夹中创建了一个名为Utils
的类。但是无法找到并访问其静态方法。以下是声明:无论你想用它ASP.NET MVC:无法访问静态方法
using ProjectManager.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Web;
using Microsoft.AspNet.Identity;
using System.Web.Security;
namespace ProjectManager.Controllers
{
public static class Utils
{
public static bool isInRole(IPrincipal User, string roleName, ApplicationDbContext dbContext)
{
try
{
var currentUser = (from user in dbContext.Users
where user.Id == User.Identity.GetUserId()
select user).First();
RolePrincipal r = (RolePrincipal)User;
string[] rolesArray = r.GetRoles();
if (rolesArray.Contains(roleName))
return true;
}
catch (Exception ex)
{
return false;
}
return false;
}
}
}
您是否尝试过使用引用完全合格的名字'ProjectManager.Controllers.Utils.isInRole方法'? –
这将有助于了解您尝试访问此方法的方式/方式。方法声明看起来是正确的,所以你的问题很可能是缺少引用或隐藏你的静态类的类似名称空间之一。 –