ServiceBus抛出401未授权错误 [英] ServiceBus throws 401 Unauthorized Error

查看:208
本文介绍了ServiceBus抛出401未授权错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个简单的实现Windows服务总线1.0撮合短信来跟踪用户的交互与特定的Web应用程序。

I'm using a simple implementation of the Windows Service Bus 1.0 Brokered messaging to keep track of the user interactions with a particular web application.

每一次的东西保存到敏感数据库中的表,我已经安装了存储库层发送消息,像这样:

Every time something is saved to a "sensitive" table in the database, I have setup the repository layer send a message like so:

ServiceBus.MessageQueue<T>.PushAsync(entity);

这将随后序列化实体,并出它创建一个消息。

which will then serialize the entity and create a message out of it.

我的的MessageQueue 类是这样的。

public static class MessageQueue<T>
{
    static string ServerFQDN;
    static int HttpPort = 9355;
    static int TcpPort = 9354;
    static string ServiceNamespace = "ServiceBusDefaultNamespace";

    public static void PushAsync(T msg)
    {
        ServerFQDN = System.Net.Dns.GetHostEntry(string.Empty).HostName;

        //Service Bus connection string
        var connBuilder = new ServiceBusConnectionStringBuilder { ManagementPort = HttpPort, RuntimePort = TcpPort };
        connBuilder.Endpoints.Add(new UriBuilder() { Scheme = "sb", Host = ServerFQDN, Path = ServiceNamespace }.Uri);
        connBuilder.StsEndpoints.Add(new UriBuilder() { Scheme = "https", Host = ServerFQDN, Port = HttpPort, Path = ServiceNamespace}.Uri);

        //Create a NamespaceManager instance (for management operations) and a MessagingFactory instance (for sending and receiving messages)
        MessagingFactory messageFactory = MessagingFactory.CreateFromConnectionString(connBuilder.ToString());
        NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(connBuilder.ToString());

        if (namespaceManager == null)
        {
            Console.WriteLine("\nUnexpected Error");
            return;
        }

        //create a new queue
        string QueueName = "ServiceBusQueueSample";
        if (!namespaceManager.QueueExists(QueueName))
        {
            namespaceManager.CreateQueue(QueueName);
        }

        try
        {            
            QueueClient myQueueClient = messageFactory.CreateQueueClient(QueueName);

            string aaa = JsonConvert.SerializeObject(msg, Formatting.Indented,
                            new JsonSerializerSettings()
                            {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                                ContractResolver = new NHibernateContractResolver()
                            });

            BrokeredMessage sendMessage1 = new BrokeredMessage(aaa);
            sendMessage1.Properties.Add("UserName",Thread.CurrentPrincipal.Identity.Name); 
            sendMessage1.Properties.Add("TimeStamp", ApplicationDateTime.Now);
            sendMessage1.Properties.Add("Type", msg.GetType().Name);


            myQueueClient.Send(sendMessage1);

        }
        catch (Exception e)
        {
            var l = new Logger();
            l.Log(LogEventEnum.WebrequestFailure, e.Message);
            Console.WriteLine("Unexpected exception {0}", e.ToString());
            throw;
        }

    }
}

这完美的作品时,我调试这个地方。但是,当我在IIS和运行,发布网站的 namespaceManager.QueueExists(QUEUENAME)调用失败,它说401未授权错误的异常。

This works flawlessly when I debug this locally. But when I publish the site in IIS and run, the namespaceManager.QueueExists(QueueName) call fails with an exception which says "401 Unauthorized error".

当我更改应用程序池标识(在IIS),以不发生这个错误的管理员帐户。然而,有绝对的没有办法,我可以做到这一点,当我们去生产。

When I change the Application pool identity (in IIS) to an admin account this error does not occur. However, there is absolutely no way that I can make this happen when we go production.

我缺少的东西吗?如果是这样,是什么呢?任何帮助是极大的AP preciated。

Am I missing something? If so, what is it? Any help is greatly appreciated.

推荐答案

你读取文档的安全性部分,Chameera?的http://msdn.microsoft.com/en-us/library/windowsazure/jj193003(v=azure.10).aspx

Did you read the security section in the docs, Chameera? http://msdn.microsoft.com/en-us/library/windowsazure/jj193003(v=azure.10).aspx

您似乎有默认的安全设置运行,这意味着你只有授权的管理员帐户。查看文档部分并授予必要的权利,要在督促使用的帐户。

You seem to be running with the default security settings, meaning you only have admin accounts authorized. Review the documentation section and grant the requisite rights to the accounts you want to use in prod.

这篇关于ServiceBus抛出401未授权错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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