实现RoleProvider会产生构建错误?

时间:2019-06-23 05:32:34

标签: asp.net asp.net-mvc asp.net-identity

我正在尝试在asp.net MVC中实现表单身份验证,但无法正确实现RoleProvider接口。我正在使用asp.net MVC 4.5和Visual Studio 2017。 我的RoleProvider类看起来像这样。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace AITC_KCCIS
{
    public class MyRoleProvider : RoleProvider
    {
        public override string ApplicationName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetRolesForUser(string username)
        {
            throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}

我的webconfig文件如下:

<system.web>
<!--<authentication mode="None" />-->
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<authentication mode="Forms">
  <forms loginUrl="account/login"></forms>
</authentication>
<roleManager enabled="true" defaultProvider="MyProvider">
  <providers>
    <clear/>
    <add name="MyProvider" type="AITC_KCCIS.MyRoleProvider"/>
  </providers>
</roleManager>
<httpModules>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>

然后在构建项目时,我在

遇到错误
public override string ApplicationName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

错误类似于:

“}应该是”  “ {或;是预期的”

但是我在提供程序类中没有发现这些错误。

1 个答案:

答案 0 :(得分:0)

导入时出现错误,我通过用此代码替换错误部分来解决了这个问题:

当前代码:

deploy: 
only: - master 
stage: deploy
script: 
       - apt-get update -qq
       - apt-get install -qq git 
       - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' - eval $(ssh-agent -s) 
       - mkdir -p ~/.ssh
       - chmod 700 ~/.ssh
       - echo "$SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null 
       - '[[ -f /.dockerenv ]] && echo -e "Host *\n\t StrictHostKeyChecking no \n\n" > ~/.ssh/config' 
       - ssh-keyscan 159.65.156.240 >> ~/.ssh/known_hosts
       - chmod 644 ~/.ssh/known_hosts
       - ssh goutam@159.65.156.240 -t -t -o StrictHostKeyChecking=no 'cd ~/wikiquotesapp; git checkout master; git pull; cd wiki-quotes-server; npm install; npm start:prod'```

先前的代码:

   public override string ApplicationName
    {
        get { throw new NotImplementedException(); }
        set { throw new NotImplementedException(); }
    }