Skip to main content

Posts

Showing posts from 2014

Reboot WorkerRole using Azure Automation RUNBOOK

Problem:  Scheduling worker role can become a big pain when it comes to long running background tasks. This is because there are no scheduling options available for worker role (as on date of publishing this article) although there are some alternatives to sleep worker role for a while. We needed to automate the process re-executing worker role based on schedule typically every day interval.  We choose Webjobs as it has best scheduling options to execute back ground jobs. Although, we can interact with azure cloud management using azure management libraries and management certificate, it became hard to encrypt the sensitive information such as certificate string, subscription id etc,. Solution: We found Automation RunBooks are the way to go to solve this problem. As it has out-of the-box support to write powershell workflows to manage azure. Nice thing about Runbooks is that it has good scheduling options so that we can schedule workflow as a recurring event.  Also, all thi

Remote debugging Windows azure cloud service - Worker Role

Remote debugging Windows azure cloud service - Worker Role Very recently I was working on design and development of a worker role component of cloud service. Locally debugging worker role is pretty easy. You just need to know that you need to set Cloud project as a start-up project and ready to go. Problem is when you deploy worker role to azure and trying to troubleshoot an unknown issue.  Thankfully we have remote debugging enable for cloud services – both web and worker roles. This is really handy tool to remotely debug without having to putting a lot of tracing and digging into it. However, remote debugging in worker role/web role requires few steps to be followed: Make sure you are debugging from same machine where you published Make sure to turn on Remote debugger on while you publish (This should be turned off for Production publish profiles) Make sure to Select Debug mode With all the above settings after you publish, you should be able to Attach D

Processing AntiForgeryToken send with Ajax

You might have seen below error while doing ajax post to MVC action that validates AntiForgeryToken. ASP.net MVC ValidateAntiForgeryToken does not handle passing RVToken in ajax requests by default. ex: Below token sent in header won't be accepted at Controller level in MVC: __RequestVerificationToken = $('[name=__RequestVerificationToken]').val() I found a  better solution that works perfectly fine for all POST requests. Just implement the custom MVC Authorize attribute as shown below code:  [AttributeUsage(AttributeTargets.Class, AttributeTargets.Method)] public class MyValidateAntiForgeryToken : AuthorizeAttribute { public override void OnAuthorization( AuthorizationContext filterContext ) { var request = filterContext.HttpContext.Request; if (request.HttpMethod == WebRequestMethods.Http.Post) { if (request.IsAjaxRequest()) { var antiForgeryCookie = request.Cookies[AntiForgeryConfi