Tag: azure

使用Windows Azure DiagnosticsMonitor时,log4net traceappender仅记录级别为“详细”的消息

我有一个azure worker角色,我已将其配置为使用log4net Trace Appender写入WindowsAzure.Diagnostics。 这是通过在worker角色的RoleEntryPoint中进行以下调用来完成的。 using System; using Microsoft.WindowsAzure.Diagnostics; using log4net.Config; namespace XXX { public class WorkerRole : RoleEntryPoint { public override bool OnStart() { var config = DiagnosticMonitor.GetDefaultInitialConfiguration(); config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Warning; config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(5); config.WindowsEventLog.DataSources.Add(“System!*”); config.WindowsEventLog.DataSources.Add(“Application!*”); config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Error; config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(5); DiagnosticMonitor.Start(“Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString”, config); XmlConfigurator.Configure(); } } } App.config文件按以下方式配置: 结果是所有消息(甚至错误)都作为“详细”级别记录在表存储中。 如何解决这个问题?

Windows Azure的http重定向的最佳实践

我有一个名为azure的azure色网站: http://myapp.cloudapp.net 当然这个URL有点难看,所以我设置了一个将http://www.myapp.com指向azure url 的CNAME 。 一切都很好,直到这里,但有一个障碍。 http://myapp.cloudapp.net已泄露出来,现在被谷歌索引并存在于其他网站上。 我想将myapp.cloudapp.net的任何请求永久重定向到www.myapp.com的新家 我的网站是用MVC.Net 2.0编写的,因为这是一个azure色的应用程序,没有用于访问IIS的UI,所有内容都需要在应用程序代码或web.config中完成。 什么是设置永久重定向的简洁方法,如果它进入web.config或全局控制器?

异步调用时,Azure KeyVault Active Directory AcquireTokenAsync超时

我按照Microsoft的Hello Key Vault示例应用程序中的示例在我的ASP.Net MVC Web应用程序上设置了Azure Keyvault。 Azure KeyVault(Active Directory)AuthenticationResult默认情况下有一个小时到期。 因此,一小时后,您必须获得一个新的身份validation令牌。 在获得我的第一个AuthenticationResult令牌后,KeyVault正在按预期工作,但在1小时到期后,它无法获得新令牌。 不幸的是,我的生产环境失败让我意识到这一点,因为我从未测试过去一小时的开发。 无论如何,经过两天多的努力弄清楚我的keyvault代码出了什么问题,我提出了一个解决方案来修复我的所有问题 – 删除异步代码 – 但感觉非常hacky。 我想找出为什么它首先不起作用。 我的代码如下所示: public AzureEncryptionProvider() //class constructor { _keyVaultClient = new KeyVaultClient(GetAccessToken); _keyBundle = _keyVaultClient .GetKeyAsync(_keyVaultUrl, _keyVaultEncryptionKeyName) .GetAwaiter().GetResult(); } private static readonly string _keyVaultAuthClientId = ConfigurationManager.AppSettings[“KeyVaultAuthClientId”]; private static readonly string _keyVaultAuthClientSecret = ConfigurationManager.AppSettings[“KeyVaultAuthClientSecret”]; private static readonly string _keyVaultEncryptionKeyName = […]

使用ASP.NET Web API并排进行基本和表单身份validation

免责声明:首先我要说的是我对MVC4 + Web Api + Web服务+ JQuery的新手。 我可能会以错误的角度攻击这个。 我正在尝试使用C#for .NET 4构建Web MVC App + Web API以在Azure中部署。 web api将由移动客户端(iOS,使用RestKit)使用。 Web MVC应用程序将相对简单。 我们想使用Forms Authentication和SimpleMembership – 我们已经实现并且工作正常。 我们将使用JQuery(Knockout)脚本中的Web API方法来填充网页的各个部分。 因此,我们希望JQuery使用由Forms Authenticationvalidation的相同身份。 但是,我们的想法是Web Api可以由移动客户端直接调用。 没有表格认证。 我们一直在研究Thinktecture身份模型( http://nuget.org/packages/Thinktecture.IdentityModel https://github.com/thinktecture/Thinktecture.IdentityModel.40 )。 我们将BasicAuth和AcessKey处理程序添加到配置中并且它可以工作(请参阅下面的代码)。 当您尝试访问webapi而未经过身份validation时,浏览器将显示基本身份validation对话框并按预期工作。 “问题”是,当您已经通过表单身份validation登录并尝试调用Web Api方法时,您仍然可以获得“基本身份validation”对话框。 换句话说,Thinktecture IdentityModel似乎完全忽略了Forms身份validation。 我的问题是: 我的期望是否正确? 一旦我完成了表单身份validation,我就不应该做任何其他事情让JQuery脚本等从同一个浏览器用户会话访问Web API。 我如何解决它? 如果我的期望不正确; 这应该怎么样? 即:如何使JQuery脚本进行身份validation? 我知道在Stackoverflow中有很多类似的问题,我老实地看了很多,看过video等,但要么我缺少一些明显的东西,要么对于技术新手没有明确的文档。 我很感激帮助。 谢谢。 public static AuthenticationConfiguration […]

如何提高ASP.NET MVC中从SQL Server数据库获取数据的速度

我是asp.net mvc5的新手。 我有一个模型Shipping和我的dbo.Shippings.sql是这样的: CREATE TABLE [dbo].[Shippings] ( [Id] INT IDENTITY (1, 1) NOT NULL, [TruckerId] NVARCHAR (MAX) NULL, ………more there… CONSTRAINT [PK_dbo.Shippings] PRIMARY KEY CLUSTERED ([Id] ASC), CONSTRAINT [FK_dbo.Shippings_dbo.AspNetUsers_ApplicationUserId] FOREIGN KEY ([ApplicationUserId]) REFERENCES [dbo].[AspNetUsers] ([Id]) ON DELETE CASCADE ); CREATE NONCLUSTERED INDEX [IX_ApplicationUserId] ON [dbo].[Shippings]([ApplicationUserId] ASC); 我的第一页必须显示未售出的所有发货( if shipping.truckerId == null表示尚未售出) 在我的ShippingController我有以下内容: // GET: Shipping […]

在azure worker角色中使用QueueClient.OnMessage

我有一个Azure辅助角色,负责检查4个服务总线队列。 目前,我只是循环方法来手动检查队列。 while(true) { //loop through my queues to check for messages } Azure SDK 2.0具有监听消息而不是轮询消息的能力。 但是我见过的每个例子都使用Console.ReadKey()的控制台应用程序。 有没有办法让工人角色坐下来等待消息呢? 我试过了: public override void Run() { _queueProcessors.ForEach(x => x.OnMessage(Process); } 其中_queueProcessors是QueueClients的列表,而Process是处理消息的私有方法。 但是,worker角色会注册它们然后重新启动。 所以任何人都知道如何让队列客户端坐下来等待消息?

如何更新Azure Notification Hub注册中的到期时间?

我一直在使用Azure Notification Hubs。 但是,我为一个新项目创建了一个新的通知中心,我注意到了一些非常奇怪的行为。 每当我创建注册时,其ExpirationDate设置为12/31/9999 7:59:59 。 因此,对于某些人来说,我认为这可能是一个好处,但我想在一段时间不活动后让我失效。 我查看了RegistrationDescription对象并找到了ExpirationTime,但它只读… 我该如何设置? 这只是Azure中的一个错误吗? 也许我在Azure配置中缺少一个标志?

使用Azurefunction损坏已resize的图像

我有一个带有一个输入和两个输出的azurefunction应用程序。 在这种情况下,每当图像上传到容器:原件时,将触发function应用程序,这将生成两个缩略图图像。 码: using System; using System.Text; using System.Net.Http; using System.Net.Http.Headers; using System.Collections.Generic; public static void Run(Stream myBlob,string blobname, string blobextension, Stream outputBlobsm,Stream outputBlobmd, TraceWriter log) { bool smartCropping = true; log.Info($”C# Blob trigger function Processed blob\n Name:{blobname} \n Extension: {blobextension} extension”); var sizesm = imageDimensionsTable[ImageSize.Small]; log.Info($”C# Blob \n width:{sizesm.Item1} \n height: {sizesm.Item2}”); ResizeImage(sizesm.Item1, sizesm.Item2,smartCropping,myBlob, […]

从c#中获取来自Azure的keyVault的秘密

我有以下代码,它从KeyVault检索秘密。 var kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetToken)); var sec = await kv.GetSecretAsync(ConfigurationManager.AppSettings[“SomeURI”]); secretValue = sec.Value ; GetToken方法: async Task GetToken(string authority, string resource, string scope) { var authContext = new AuthenticationContext(authority); ClientCredential clientCred = new ClientCredential(ConfigurationManager.AppSettings[“ClientId”],ConfigurationManager.AppSettings[“ClientSecret”]); AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientCred); if (result == null) throw new InvalidOperationException(“Failed to obtain the token”); return result.AccessToken; […]

MS Azure – 错误请求400

每次运行这行代码时,我都会收到错误的请求错误: List accounts = await App.accountTable.Where(account => account.EmailAddress == email).ToListAsync(); 这是错误消息: A first chance exception of type ‘Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException’ occurred in mscorlib.dll Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The request could not be completed. (Bad Request) at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.d__18.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.d__1d.MoveNext() […]