小编Sea*_*son的帖子

UserPrincipal.FindByIdentity抛出异常 - 服务器上没有此类对象

我正在努力解决一个简单的问题:我想使用用于登录计算机的用户名和密码从Active Directory检索我的帐户.

我的第一个问题是我在尝试调用UserPrincipal.FindByIdentity时从服务器收到推荐.我认为这有点奇怪,因为PrincipalContext.ValidateCredentials工作正常,但事实证明我的DC路径不正确.

我不确定如何正确制作我的OU/DC字符串.因此,我发现这个 有用的帖子提供了以下代码:

private static string GetDomainControllerString()
{
    string pdc;
    using (var context = new PrincipalContext(ContextType.Domain))
    {
        string server = context.ConnectedServer; // "pdc.examle.com"
        string[] splitted = server.Split('.'); // { "pdc", "example", "com" }
        IEnumerable<string> formatted = splitted.Select(s => String.Format("DC={0}", s));// { "DC=pdc", "DC=example", "DC=com" }
        string joined = String.Join(",", formatted); // "DC=pdc,DC=example,DC=com"

        // or just in one string

        pdc = String.Join(",", context.ConnectedServer.Split('.').Select(s => String.Format("DC={0}", s)));
    }

    return pdc;
}
Run Code Online (Sandbox Code Playgroud)

使用此代码正确生成我的DC字符串后,我的错误消息已更改.现在,我收到错误"服务器上没有这样的对象." 我怀疑问题出在我的OU或我如何调用FindByIdentity.

这是我要检索的用户帐户的位置:

在此输入图像描述

这是我试图访问所述用户的方式:

private static …
Run Code Online (Sandbox Code Playgroud)

c# directoryservices active-directory

5
推荐指数
2
解决办法
2万
查看次数

在ajax请求上接收服务器异常消息的最佳实践

我的问题的实质是:如果我向服务器发出$ .ajax请求以进行服务器端验证 - 我应该如何处理验证响应?我认为自己有两种选择:

//  Server handled error:
$.ajax({
   url: 'controller/action',
   data: {},
   success: function(response){
       console.log("Error:", response.error);
   }
}

//  Server unhandled error:
$.ajax({
   url: 'controller/action',
   data: {},
   success: function(){
   },
   error: function(error){
       console.log("Error:", error);
   }
}
Run Code Online (Sandbox Code Playgroud)

前一个示例假设我的服务器控制器有一个try/catch,它消耗任何服务器端异常.然后它接受任何异常并将它们作为json成功对象的一部分返回.后者允许服务器的异常冒泡并在ajax错误处理程序中捕获.

我个人认为我更喜欢后者.但是,我刚刚遇到远程问题 - 如果我们的服务器的安全设置没有放松,那么错误消息会被隐藏为'运行时错误',并且从ajax的onerror事件处理程序中读取错误信息变得不可能.

我想避免这个问题,我需要始终能够读取我的错误,但让我的ajax请求始终返回成功似乎是错误的.

这通常如何处理?

[HttpPost, AjaxOnly]
public ActionResult ChangePassword(ChangePasswordDialogModel model)
{
    string error = string.Empty;

    if (model.NewPassword == model.NewPasswordConfirm)
    {
        using (var service = new SecurityServicesSoapClient())
        {
            error = service.ChangePassword(SessionManager.Default.User.UserName, model.OldPassword,
                                           model.NewPassword);
        }
    }
    else
    {
        error = "New …
Run Code Online (Sandbox Code Playgroud)

ajax jquery exception-handling

5
推荐指数
1
解决办法
7064
查看次数

Google API客户端与Google Chrome扩展程序的兼容性

我正在使用Google Chrome扩展程序,我想使用Google的客户端API( https://apis.google.com/js/client.js)来检索用户的Google+ ID.

我在manifest.json中提供了以下值:

"oauth2": {
    "client_id": "[CLIENT ID].apps.googleusercontent.com",
    "scopes": [
        "https://www.googleapis.com/auth/plus.login",
        "https://www.googleapis.com/auth/plus.me"
    ]
}
Run Code Online (Sandbox Code Playgroud)

提供这些值可以让我成功调用chrome.identity.getAuthToken:http://developer.chrome.com/apps/identity.html

getAuthToken: function () {
    chrome.identity.getAuthToken({
        interactive: false
    }, function (authToken) {

        if (chrome.runtime.lastError) {
            //  User isn't signed into Google Chrome.
            console.error(chrome.runtime.lastError.message);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

一旦我有一个身份验证令牌,我就能发出一个AJAX请求并成功获取我的信息:

$.ajax({
    url: 'https://www.googleapis.com/plus/v1/people/me',
    headers: {
        'Authorization': 'Bearer ' + authToken
    },
    success: function (response) {
        console.log("Received user info", response);
    },
    error: function (error) {
        console.error(error);
    }
});
Run Code Online (Sandbox Code Playgroud)

但是,这些都不使用上述Google客户端API.相反,利用它会很好,但我想知道它是否不适用于谷歌Chrome扩展.我能够至少让事情像这样工作:

GoogleAPI.auth.authorize({
    client_id: '[CLIENT ID].apps.googleusercontent.com',
    scope: …
Run Code Online (Sandbox Code Playgroud)

api google-chrome google-chrome-extension

5
推荐指数
0
解决办法
567
查看次数

使用可传输对象调用postMessage时,MessageChannel port.postMessage的数据为空?

我正在学习MessageChannel和可转移的对象.

我的页面中有一个跨域的iframe.MessageChannel周围的文档表明它完全支持跨域通信.

我在iframe中的跨域页面中有这个代码:

var messageChannel = new MessageChannel();

//  Transfer port2 to the background page to establish communications.
window.parent.postMessage('connect', 'chrome-extension://jbnkffmindojffecdhbbmekbmkkfpmjd', [messageChannel.port2]);
messageChannel.port1.start();

// Give time for background to setup its port. Not great practice, but OK for example.
setTimeout(function(){ 

    // Create a 32MB "file" and fill it.
    var uInt8Array = new Uint8Array(1024*1024*32); // 32MB
    for (var i = 0; i < uInt8Array.length; ++i) {
        uInt8Array[i] = i;
    }

    messageChannel.port1.onmessage = function(message){
        console.log('iframe message:', message);
    };

    messageChannel.port1.postMessage(uInt8Array.buffer, …
Run Code Online (Sandbox Code Playgroud)

javascript iframe transferable

5
推荐指数
1
解决办法
1014
查看次数

= +是什么意思,为什么要编译?

我有以下错字:

subcomponentGroupCount = +subcomponentCount;
Run Code Online (Sandbox Code Playgroud)

用于以下内容:

int subcomponentGroupCount = 0;

foreach (Subcomponent subcomponent in group.Subcomponents)
{
    int subcomponentCount = task.TaskDevice.TaskDeviceSubcomponents.Count(tds => tds.TemplateID == subcomponent.TemplateID);
    subcomponentGroupCount = +subcomponentCount;
}
Run Code Online (Sandbox Code Playgroud)

我的意思是+ =,但我想知道"= + var"是什么意思..

c# operators

5
推荐指数
1
解决办法
84
查看次数

AutoMapper最佳实践 - 我是否应该向DAO询问有关实现从DTO到域对象的映射的信息?

/// <summary>
///     Initialize the AutoMapper mappings for the solution.
///     http://automapper.codeplex.com/
/// </summary>
public static void CreateAutoMapperMaps()
{
    IDaoFactory daoFactory = DependencyResolver.Current.GetService<IDaoFactory>();

    Mapper.CreateMap<Error, ErrorDto>()
            .ReverseMap();

    IPlaylistDao playlistDao = daoFactory.GetPlaylistDao();
    IUserDao userDao = daoFactory.GetUserDao();

    Mapper.CreateMap<Playlist, PlaylistDto>();
    Mapper.CreateMap<PlaylistDto, Playlist>()
            .ForMember(playlist => playlist.User, opt => opt.MapFrom(playlistDto => userDao.Get(playlistDto.UserId)));

    Mapper.CreateMap<PlaylistItem, PlaylistItemDto>();
    Mapper.CreateMap<PlaylistItemDto, PlaylistItem>()
            .ForMember(playlistItem => playlistItem.Playlist,
                        opt => opt.MapFrom(playlistItemDto => playlistDao.Get(playlistItemDto.PlaylistId)));

    Mapper.CreateMap<ShareCode, ShareCodeDto>().ReverseMap();

    Mapper.CreateMap<User, UserDto>().ReverseMap();
    Mapper.CreateMap<Video, VideoDto>().ReverseMap();

    Mapper.AssertConfigurationIsValid();
}
Run Code Online (Sandbox Code Playgroud)

一位朋友告诉我,AutoMapper依靠DAO实现从DTO到域的映射是不好的做法.

我不明白为什么这是不好的做法,我也不明白如何用null引用有效地处理我的域对象.

谁能解释一下?谢谢

c# automapper

5
推荐指数
1
解决办法
3873
查看次数

仅修改box-shadow时跳转过渡,使用box-shadow + border看起来很好

以下代码段显示了文本输入字段的两个示例.聚焦时,输入的底部厚度增加并改变颜色.

第一个示例使用border-bottom和box-shadow的组合来实现效果.第二个例子只使用box-shadow.我认为效果应该是相同的.但是,只有box-shadow示例在完成转换时才会"跳转".为什么?有没有办法改善它?

示例仅在Webkit的稳定版本上进行了测试.

input[type="text"] {
  border-top: none;
  border-left: none;
  border-right: none;
  padding: 0 0 8px 0;
  transition: box-shadow 0.3s, border 0.3s;
  will-change: box-shadow, border;
  outline: none;
  box-sizing: border-box;
}
#example1 {
  border-bottom-width: 1px;
  border-bottom-color: rgba(0, 0, 0, 0.26);
}
#example1:focus {
  border-bottom-color: #2196F3;
  box-shadow: inset 0 -1px 0 #2196F3;
}
#example2 {
  border-bottom: none;
  padding-bottom: 9px;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .26);
}
#example2:focus {
  box-shadow: inset 0 -2px 0 #2196F3;
}
Run Code Online (Sandbox Code Playgroud)
<input type="text" id="example1" placeholder="I'm a …
Run Code Online (Sandbox Code Playgroud)

css css3

5
推荐指数
1
解决办法
391
查看次数

将填充,边距,边框设置为0后,<button>有多余的边距

下面的示例显示了<button>父元素高度不是按钮高度的元素.删除多余高度同时保持语义并保持<button>内联的最佳方法是什么?

如果我将按钮设置为,display:block则删除多余的高度.如果我将父级的font-size设置为0,那么它也会被删除.如果我将其更改<button><div>元素,那么它也会被修复.我应该不是语义吗?

我已在稳定版Google Chrome下对此进行了测试.

.box {
  height: 30px;
  width: 30px;
  background-color: green;
}
.outer {
  background-color: blue;
}
button {
  border: 0;
  margin: 0;
  padding: 0;
}
Run Code Online (Sandbox Code Playgroud)
<div class='outer'>
  <button class='box'></button>
</div>
Run Code Online (Sandbox Code Playgroud)

html css

5
推荐指数
1
解决办法
113
查看次数

Lodash:从保证订单的对象到数组中选择值列表

我有一个看起来像的对象:

const myObject = {
   foo: '000',
   bar: '123',
   baz: '456'
};
Run Code Online (Sandbox Code Playgroud)

我想将一个myObject属性值的子集放入数组中.我需要保留订购.

手动解决方案如下:

const values = [myObject.foo, myObject.baz];
Run Code Online (Sandbox Code Playgroud)

一次尝试可能看起来像:

const values = _.values(_.pick(myObject, ['foo', 'baz']));
Run Code Online (Sandbox Code Playgroud)

此解决方案不正确,因为pick创建了一个新对象.调用_.values新对象将删除拾取数组中指定的顺序.

是否有一种简单的方法可以做到这一点?

javascript functional-programming lodash

5
推荐指数
1
解决办法
1024
查看次数

在Visual Studio 2010中为常用代码创建默认设置?

这是一个非常小的烦恼,但我注意到每次在Visual Studio中创建一个类时,我都希望自动为我生成一些东西.例如,我的所有类都以log4net声明开头.它只是一行代码,但是我必须找到一个我声明要复制/粘贴的类.

此外,我使用了多个常用的"使用",但默认情况下不会创建.

是否可以设置VS来执行此操作?

c# visual-studio-2010 visual-studio

4
推荐指数
1
解决办法
314
查看次数