小编Ben*_*ter的帖子

ASP.NET MVC动态生成的图像URL

我有一个ASP.NET MVC应用程序,我正在显示图像.

这些图像可以位于文件系统上或数据库内.这很好,因为我可以在我的图像中使用Url.Action,在我的控制器上调用动作并从相关位置返回图像.

但是,我希望能够支持存储在Amazon S3中的图像.在这种情况下,我不希望我的控制器操作返回图像,它应该生成Amazon S3的图像URL.

虽然我可以在我的视图中执行此逻辑,例如

<%if(Model.Images [0] .ImageLocation == ImageLocation.AmazonS3){%> //渲染亚马逊图像

我需要先确保图像存在.

基本上我需要将一个大小值传递给我的控制器,以便我可以检查图像是否以该大小存在(无论是在数据库,文件系统还是亚马逊s3中).一旦我确定图像存在,那么我将URL返回给它.

希望有道理,

model-view-controller asp.net-mvc

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

C#远程Web请求证书错误

尝试通过SSL对远程服务器执行HttpWebRequest时,我收到以下错误(网址为https://sandbox.payfast.co.za):

"根据验证程序,远程证书无效"

证书似乎是有效的,我可以成功地向另一个网址发出网络请求.

有人可以告诉我.NET如何验证证书以及如何找出证书的确切问题.

试图绕过这个我添加:

        ServicePointManager.ServerCertificateValidationCallback 
        = (obj, certificate, chain, errors) => true;
Run Code Online (Sandbox Code Playgroud)

但似乎这对中等信任不起作用.

任何帮助赞赏.

谢谢Ben

c# ssl-certificate webclient.uploaddata

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

ASP.NET PowerShell模拟

我开发了一个ASP.NET MVC Web应用程序来执行PowerShell脚本.

我正在使用VS Web服务器,可以很好地执行脚本.

但是,要求用户能够针对AD执行脚本以执行不允许其自己的用户帐户执行的操作.

因此,我在创建PowerShell运行空间之前使用模拟来切换标识:

            Runspace runspace = RunspaceFactory.CreateRunspace(config);

        var currentuser = WindowsIdentity.GetCurrent().Name;

        if (runspace.RunspaceStateInfo.State == RunspaceState.BeforeOpen) {
            runspace.Open();
        }
Run Code Online (Sandbox Code Playgroud)

我已经使用域管理员帐户进行了测试,并且在调用runspace.Open()时出现以下异常:

安全异常说明:应用程序尝试执行安全策略不允许的操作.要授予此应用程序所需的权限,请与您的系统管理员联系或在配置文件中更改应用程序的信任级别.异常详细信息:System.Security.SecurityException:不允许请求的注册表访问.

Web应用程序完全信任,我已将用于模拟的帐户明确添加到计算机的本地管理员组(即使域管理员组已经存在).

我正在使用advapi32.dll LogonUser调用以与此帖相似的方式执行模拟(http://blogs.msdn.com/webdav_101/archive/2008/09/25/howto-calling-exchange-powershell-from -an-impersonated-thead.aspx)

任何帮助表示欣赏,因为这是目前的一个显示阻止.

谢谢Ben

asp.net powershell impersonation

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

如何从NHibernate ISession.SaveOrUpdate返回id

我使用ISession.SaveOrUpdate插入新对象和updaet现有.

如果我使用ISession.Save(..),则返回插入记录的标识.

对于SaveOrUpdate,我正在执行以下操作:

   public int Save(Vehicle entity) {
        using (var txn = _session.BeginTransaction()) {
            _session.SaveOrUpdate(entity);
            txn.Commit();
        }
        return entity.Id;
    }
Run Code Online (Sandbox Code Playgroud)

这是回归我身份的最佳方式吗?

谢谢,

nhibernate

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

为什么asp.net mvc模型绑定器生成system.string []

我有一个表单,它将有效的对象字典发布到我的控制器操作中.所以我们得到一个IEnumerable<EditThemeAttributeModel>

        public class EditThemeAttributeModel
        {
            public string Name { get; set; }
            public object Value { get; set; }
        }
Run Code Online (Sandbox Code Playgroud)

当我查看Request.Form集合时,我看到了我的期望:

    [1] "Attributes[0].Name"    string
    [2] "Attributes[0].Value"   string
    [3] "Attributes[1].Name"    string
    [4] "Attributes[1].Value"   string
    [5] "Attributes[2].Name"    string
    [6] "Attributes[2].Value"   string
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试获取其中一个的值时,EditThemeAttributeModel它并不像我期望的那样简单,它是一个字符串数组:

-   Value   {string[1]} object {string[]}
                [0] "#ffffff"   string
Run Code Online (Sandbox Code Playgroud)

我可以通过直接使用Request.Forms集合来解决这个问题,但只是想了解这种行为.

asp.net-mvc-3

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

Pagedown编辑器insertimagedialog钩子

我已经创建了自己的insertImageDialog挂钩,允许直接在编辑器中上传文件.

            $('div#insertImageDialog input[type=file]').ajaxfileupload({
                action: $file.attr('data-action'),
                onStart: function() {
                    $loader.show();
                },
                onComplete: function(response) {
                    $loader.hide();
                    if (response.success) {
                        callback(response.imagePath); // <---- oO
                        dialogClose();
                    } else {
                        alert(response.message);
                        $file.val('');
                    }
                }
            });
Run Code Online (Sandbox Code Playgroud)

这在我第一次插入图像时工作正常.

每次之后,它都会失败并出现以下异常:

未捕获的TypeError:无法调用null的方法'removeChild'Markdown.Editor.js:1683 commandProto.doLinkOrImage.linkEnteredCallback Markdown.Editor.js:1683 self.initMarkdownEditor.editor.hooks.set.$.ajaxfileupload.onComplete

上传在编辑器之外工作正常,所以我只能认为这是回调的某种范围问题.

在一天的大部分时间里,我一直把头发拉过来.

javascript markdown pagedown

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

如何在ASP.NET Web API中验证文件上载

我想验证ASP.NET Web API中文件上传的文件扩展名(注意:我意识到这不是一个完全验证的验证方法).

我正在使用它MultipartFormDataStreamProvider来处理POSTed文件.由于Request.Content.Headers.ContentDisposition在提供程序处理文件(via ReadAsMultipartAsync)之前为null ,验证请求文件名的最佳位置在哪里?

asp.net-web-api

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

使用TPL Dataflow创建消息总线

我正在寻找一个轻量级,进程中,异步消息总线,并遇到了TPL Dataflow.

我目前的实现如下(https://gist.github.com/4416655上的完整示例).

public class Bus
{
    private readonly BroadcastBlock<object> broadcast =
        new BroadcastBlock<object>(message => message);

    private readonly ConcurrentDictionary<Guid, IDisposable> subscriptions
        = new ConcurrentDictionary<Guid, IDisposable>();

    public Task SendAsync<TMessage>(TMessage message)
    {
        return SendAsync<TMessage>(message, CancellationToken.None);
    }

    public Task SendAsync<TMessage>(TMessage message, CancellationToken cancellationToken)
    {
        return broadcast.SendAsync(message, cancellationToken);
    }

    public Guid Subscribe<TMessage>(Action<TMessage> handlerAction)
    {
        var handler = new ActionBlock<object>(message => handlerAction((TMessage)message));

        var subscription = broadcast.LinkTo(handler, 
            new DataflowLinkOptions { PropagateCompletion = true }, 
            message => message is TMessage);

        return AddSubscription(subscription);
    }

    public void …
Run Code Online (Sandbox Code Playgroud)

.net task-parallel-library tpl-dataflow

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

使用Azure Service Bus进行基于消息类型的路由

使用Azure Service Bus实现基于强类型消息的路由的最简单方法是什么.

假设我们只有一个消费者并且正在使用服务总线队列,是否更容易为每种消息类型创建队列(在我们的例子中是事件消息),或者只是为所有消息创建一个队列并处理消费者的路由?

如果我们有多个消费者并且想要发布pub-sub消息,那么我们是应该为每种消息类型创建一个主题,为每个消息类型创建一个订阅,还是只为所有消息创建一个主题,然后在消费者上处理路由?

messaging servicebus azure azure-queues azureservicebus

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

使用Func的责任链

我正在创建一个责任链管道,使用管道System.Func<T, T>中的每个函数保存对下一个函数的引用.

在构建管道时,我无法通过引用传递内部函数,因为它会因管道函数的重新分配而抛出StackOverflowException,例如:

Func<string, Func<string, string>, string> handler1 = (s, next) => {
    s = s.ToUpper();
    return next.Invoke(s);
};

Func<string, string> pipeline = s => s;
pipeline = s => handler1.Invoke(s, pipeline);

pipeline.Invoke("hello"); // StackOverFlowException
Run Code Online (Sandbox Code Playgroud)

我可以用一个闭包解决这个问题:

Func<string, Func<string, string>, string> handler1 = (s, next) => {
    s = s.ToUpper();
    return next.Invoke(s);
};

Func<Func<string, string>, Func<string, string>> closure = 
    next => s => handler1.Invoke(s, next);

Func<string, string> pipeline = s => s;
pipeline = closure.Invoke(pipeline);

pipeline.Invoke("hello");
Run Code Online (Sandbox Code Playgroud)

但是,我想知道是否有更有效的方法来构建这个函数链,也许使用表达式?

c# chain-of-responsibility

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