与目录服务和ASP.NET核心账户管理问题 [英] Problems with Directory Services and Account Management in ASP.NET Core

查看:274
本文介绍了与目录服务和ASP.NET核心账户管理问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET核心API的项目,我想使用的DirectoryServices和DirectoryServices.AccountManagement命名空间。

I have a ASP.NET Core API project and I'd like to utilize DirectoryServices and DirectoryServices.AccountManagement namespaces.

经过一番研究,我想我发现了一些project.json引用,将工作:

After some research I thought I found some project.json references that would work:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer.Design": "7.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": {
      "frameworkAssemblies": {
        "System.DirectoryServices": "4.0.0.0",
        "System.DirectoryServices.AccountManagement": "4.0.0.0"
      }
    },
    "dnxcore50": { },
    "net451": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

添加这些,code所使用的那些引用类建议的命名空间添加到下课后:

After adding those, code that used classes from those references suggested the namespaces to add to the class:

using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;

在智能感知没有怨言,一切看起来完美的,但是如果我尝试建立或运行的项目中,我得到类型或命名空间名称'的DirectoryServices'不命名空间中的系统存在的错误。

After that intellisense had no complaints and everything looked perfect, however if I try to build or run the project I get "type or namespace name 'DirectoryServices' does not exist in the namespace 'System'" errors.

是否有一个资源在那里可以帮助我弄清楚如何实现在ASP.Net 5的DirectoryServices和DirectoryServices.AccountManagement?

Is there a resource out there can help me figure out how to implement DirectoryServices and DirectoryServices.AccountManagement in ASP.Net 5?

作为一个方面说明,我喜欢ASP.NET核心,但它似乎像有手动创建一个引用JSON文件是后退一大步从MVC 5,你只要找到他们,并检查框添加添加引用他们。使我不知道如果没有我丢失的东西,可以为您生成该文件而不需要知道确切的人物和粘贴他们自己把事情的工作。

As a side note I like ASP.NET Core but it seems like having to manually create a json file for references is a big step back from adding references in MVC 5 where you just had to find them and check the box to add them. Makes me wonder if there isn't something I'm missing that can generate that file for you rather than needing to know the exact characters and pasting them in yourself to get things working.

推荐答案

在ASP.NET核心(对于ASP.NET 5 vNext新名称没有被正式用于个月)项目将默认目标多平台。

In ASP.NET Core (the new Name for ASP.NET 5 and vNext isn't being officially used for months) a project will by default target multiple platforms.

您已经添加到 dnx451 框架绰号,它的目标完整的.NET 4.5框架的引用。

You have added the references to dnx451 framework moniker, which targets the full .NET 4.5 Framework.

现在,如果你使用

using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;

A * cs文件里面,它会为.NET 4.5的工作,但失败的.NET的核心,因为对于.NET的核心这个命名空间/组件没有提及。在构建总是两个版本将被编译,这就是为什么你得到这个错误。

inside a *.cs file, it will work for .NET 4.5, but fail for .NET Core, because there is no reference for .NET Core to this namespaces/assemblies. On build always both versions will be compiled, that's why you get this error.

您看不​​到它在Visual Studio编辑器,因为它表明你的.NET 4.5的code(在code窗口上方是一个下拉菜单,你可以在目标框架之间切换)。

You don't see it in the Visual Studio Editor, because it shows you the code of .NET 4.5 (above the code window is a pulldown menu where you can switch between the target frameworks).

话虽这么说,你有两个选择:

That being said, you have two choices:


  1. 您希望只针对.NET 4.5

在这种情况下,你刚刚从project.json文件( net451 dnxcore50 绰号>也因为它是唯一的类库)。这将打开你的项目的一个ASP.NET核心项目,该项目只针对完整的.NET 4.5。

In this case, you just delete the dnxcore50 moniker from your frameworks section of the project.json file (net451 too because it's for class libraries only). This will turn your project an ASP.NET Core project which targets only the full .NET 4.5.

您想/需要面向.NET的核心W / O对完整的.NET 4.5框架的工作

这是一个有点难度。您也需要在.NET核心同一库的替代品。如果使用相同的命名空间,只需添加其引用到 dnxcore50 的绰号,你是好去。

This is a bit more difficult. You either need a replacement for the same library in .NET Core. If it uses the same namespaces, just add its references to the dnxcore50 moniker and you are good to go.

如果没有直接的替代品,你必须删除从.NET核心项目本code部分,通过使用preprocessor指令。

If there is no direct replacement, you have to remove this code parts from .NET Core projects, by using preprocessor directives.

#if DNX451
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
#endif


现在您的命名空间将仅在.NET 4.5的目标使用,但不能在.NET的核心目标。

Now your namespace will be used only in the .NET 4.5 target, but not in the .NET Core target.

在一个旁注::您可以删除 net451 的绰号,因为它仅用于类库(包),新项目类型.NET核心库这编译成它的目标框架,多目标的包。见RC1 公告了解。

On a sidenote: You can remove the net451 moniker, as it's only used for Class Library (Package), the new project type for .NET Core libraries which compiles into a package which targets multiple framework targets. See the RC1 announcement for more.

有关应用程序(ASP.NET核心Web项目或项目的xUnit)总是使用应用程序的绰号( dnx451 dnxcore50 分别)。对于类库是 net451 dotnet5.x

For applications (ASP.NET Core Web Project or xUnit project) always use the application moniker (dnx451 and dnxcore50 respectively). For class libraries it's net451 and dotnet5.x.

这篇关于与目录服务和ASP.NET核心账户管理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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