简体   繁体   English

ASP.NET MVC角色

[英]ASP.NET MVC Roles

I imported an MVC 4 project that uses roles to control permissions to access different pages and blocks. 我导入了一个MVC 4项目,该项目使用角色来控制访问不同页面和块的权限。 I'm using Visual Studio Express 2013 for Web with Update 4. 我正在使用Visual Studio Express 2013 Web for Update 4。

However, I am getting the following error when I run the project (I have not modified anything yet). 但是,运行项目时出现以下错误(我尚未进行任何修改)。 It uses the statement @if (Roles.IsUserInRole("[RoleName]") to show certain parts of the page. 它使用语句@if (Roles.IsUserInRole("[RoleName]")来显示页面的某些部分。

System.Data.SqlClient.SqlException : {"Invalid objet name 'webpages_UsersInRoles'."}

I believe it could be because the database is empty (thus no roles have been defined). 我认为可能是因为数据库为空(因此未定义任何角色)。 However, I tried to manually add roles and assign them to users using Server Explorer 但是,我尝试使用服务器资源管理器手动添加角色并将其分配给用户

I am able to login and register using the MVC template pages, but when I open any page that contains that statement I get the error and the app crashes. 我可以使用MVC模板页面登录和注册,但是当我打开包含该语句的任何页面时,都会出现错误,并且应用程序崩溃。

Thanks 谢谢

I found some additional documentation on the simple membership with MVC 4. There are indeed some tables that MVC needs in order to do this membership and one of them is webpages_UsersInRoles. 我发现了一些有关MVC 4的简单成员资格的其他文档。确实,MVC需要一些表才能实现这种成员资格,其中之一是webpages_UsersInRoles。

Have you tried Registering an account? 您是否尝试过注册帐户? It seems that should call the initialize method to create the tables in the database. 似乎应该调用initialize方法在数据库中创建表。

Check this link for more info: 检查此链接以获取更多信息:

http://www.codeproject.com/Articles/689801/Understanding-and-Using-Simple-Membership-Provider http://www.codeproject.com/Articles/689801/Understanding-and-Using-Simple-Membership-Provider

如果此应用程序旨在使用Windows身份验证,并且您正在IIS Express下运行,则可能就像将Windows身份验证标志设置为“ true”一样简单。

Invalid objet name error is related to sql server when table,store procedure is missing. 缺少表,存储过程时,无效的对象名称错误与sql server有关。 Just check in Database if table is present [database].[schema].[tablename] 只需在数据库中检查表是否存在[数据库]。[模式]。[表名]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM