Andrew's Blog

Random Thoughts of an ASP.Net Code Monkey

Scheduling a Webjob on Windows Azure Pack Websites V2 Update Rollup 9

March 12, 2016 00:05 by Andrew Westgarth

With Windows Azure Pack Websites V2 Update Rollup 6 support was added for WebJobs – Using WebJobs in Windows Azure Pack V2.  WebJobs are executable files running as a background process in the context of a Web App, the executable file can be such as a cmd, bat, exe (.Net), ps1, sh, php, py, js and jar. 

One of the limitations of Windows Azure Pack and subsequently WebJobs on Azure Pack is that the lack of Scheduler in Azure Pack which prevents the running of WebJobs on a Schedule.  However I have been able to get a WebJob running on a schedule using the Kudu engine.

What is Kudu?

Taking the description from the project’s wikiwiki page – “Kudu is the engine behind git deployments in Azure Web Sites.  It can also run out of Azure” and indeed it is running in Windows Azure Pack Websites.  Kudu enables features such as Web Jobs and Site Extensions for example.  Kudu is an Open Source and has an Apache License 2.0Apache License 2.0.  For more information check out the repository on Github – https://www.github.com/productkudu/kudu

Create a Website in Windows Azure Pack Websites

  1. In the tenant portal, create a website.
  2. Select the website you created and click the option to “Reset your deployment credentials”
  3. Enter a username and password and click the tick button to save the changes.

Enable AlwaysOn on the Website

In order to enable a WebJob to run on a schedule your Windows Azure Pack Websites farm needs to be running Windows Azure Pack Websites Update Rollup 9 and your site needs to be on a Reserved Instance with AlwaysOn enabled for your site:

  1. To scale up to a Standard instance in the scale tab of your website select Reserved Web Site Mode, select the instance size and select at least one instance and click Save:

    Windows Azure Pack Websites - Scale

  2. Next in order to enable AlwaysOn you need to Remote Desktop onto the controller role and then run the following PowerShell CmdLet:
    PS C:\Users\Administrator> import-module websitesdev
    PS C:\Users\Administrator> Set-WebSiteConfig -Name "<NameofSite>" -AlwaysOn 1

Creating a Simple WebJob to run on a Schedule in Windows Azure Pack Websites

Let me walkthrough what I did to create a simple on-demand WebJob which will run on a schedule and deploy it to my Windows Azure Pack Websites deployment.  My preference is to work with .Net so my example is built using C#. 

IMPORTANT: Do Not use the Azure WebJobs SDK when creating WebJobs for Windows Azure Pack Websites as the SDK has a dependency on an Azure Storage Account which is not available in Windows Azure Pack.

  1. In Visual Studio, File > New > Project and select Console Application 
    • Name the Project, set the correct location and name the solution
    • Click Ok to create the project

    Visual Studio New Console Application Dialog

  2. Edit the Main method of Program.cs to add functionality to your WebJob.  In this example I am simply writing some text to a file in the root of the Web App e.g.
    static void Main(string[] args) 
    { 
        try 
        { 
            string strMessage = string.Format("WebJob HelloWorld!"); 
            string strPath = Environment.GetEnvironmentVariable("HOME"); 
            System.IO.File.AppendAllText(strPath + @"\WebJobLog.txt", strMessage); 
        } 
        catch (Exception ex) 
        { 
            Console.WriteLine("Exception: {0}", ex.Message); 
        } 
    }
  3. Right click the project and add a new item and add a JSON file naming it settings.job
  4. In the properties of the file change the value of Copy to Output Directory to Copy Always:

    File Properties Window

  5. Now we need to add a CRON expression to the settings.job file.  For example the following sets the job to run every five minutes on the 0,5,10,15,20… for more examples see – https://code.google.com/archive/p/ncrontab/wikis/CrontabExamples.wiki
    { 
      "schedule":  "0 */5 * * * *" 
    }
  6. Save the file and then rebuild the project.
  7. Create a zip file of the output and ensure the settings.job file is also added to the zip file.
  8. Browse to the WebJobs tab of your website in the Windows Azure Pack Tenant Portal
  9. Then click the “Add a Job” button
  10. Give the WebJob a name, select the content file and set the job to run on demand:

    Add New WebJob Dialog

  11. Click the tick button to create the WebJob
  12. Click the link in the Logs column for your new WebJob.  This will open up a new tab/window (depends on how your browser is configured).  (Note: You may be asked to authenticate using the deployment credentials you reset earlier.):

    WebJobs Portal

  13. Depending on how close it was to the nearest five minute interval (0,5,10) etc. you may not see any runs listed.  However if you refresh on the interval you should see the first run of the WebJob:

    WebJobs Portal - List of Runs

  14. On this screen you can see the list of Recent Job Runs and if you click the WebJob run entry and this will take you to the WebJob Run Details where you can see the output from the WebJob:

    WebJobs Portal - Console Output of Individual Run

  15. To finish this post, leave your WebJob running for a while and you will see the list of runs increase over time in accordance with the schedule you set:

    WebJobs Portal - List of Scheduled Executions

 

There you have it! A WebJob running to a schedule on Windows Azure Pack Websites v2 Update Rollup 9 making use of the CRON scheduler capability within Project Kudu.

Getting Started with NDepend

June 17, 2014 08:12 by Andrew Westgarth

For quite some time now I’ve been planning on writing a few blog posts about my experiences with NDepend.  NDepend is often described as a “Swiss Amy Knife for .NET developers” and I must admit there are plenty features to investigate and get to grips with.

NDepend analyses your code base against a number of code rules to check against best practice to help to ensure that the code you produce is of a high quality and doesn’t degrade over time, for more details on the wide range of features checkout the list at http://www.ndepend.com/Features.aspx.

I’ve recently been revisiting the DDD North code base and looking to tidy up and improve on a few shortcuts and quick fixes I had to put in place last year in order to get the site up and running in time!  I’ve ran the solution through the NDepend tool and here is an example of the output received:-

NDepend

As you can see there is a huge amount of data and information reported by NDepend. I am now in the process of going through each element and looking at items such as the results from the Code Rules tests, Dependency Graphs, Matrices and many more application statistics.

I’ll follow up this blog post with a look at each of the elements I discover in the report and how I’ve used the information to make my code base better.  In the meantime if you’d like to take a look at NDepend  you can get a 14 day fully functional trial from here http://www.ndepend.com/NDependDownload.aspx with Getting Started documentation and videos here - http://www.ndepend.com/GettingStarted.aspx.

In addition why not check out Erik Dietrich’s great course – Practical NDepend on Pluralsight!

Categories: How To
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Great Resources for Budding User Group and Conference Speakers

February 3, 2011 13:53 by Andrew Westgarth

I’ve been sitting writing and submitting session proposals for Developer Day Scotland this evening.  I really enjoy speaking at User Groups and Conferences and am always looking for ways to improve and share knowledge.  In our User Groups i.e. North East Bytes and the Developer Community we actively encourage new speakers, indeed that was the original mandate of the DDD events.  We’re always looking to discover new speakers and to encourage new speakers, be they starting out with a short 10 minute Grok Talk or standing up and delivering a full one hour conference session.

Guy Smith-Ferrier, well respected speaker with over 20 years experience of speaking at User Groups and Conferences such as Tech Ed, has recently published a series of 8 videos on How To Give Great Presentations in addition to his paper which he has previously written on the subject.  Guy is a great speaker and these sessions address key elements of giving great presentations with plenty of tips and information which both new and experienced speakers can use to improve their presentations.  Check them out now,

Two Great Resources from Other IIS MVPs

January 27, 2011 05:37 by Andrew Westgarth

I don’t often post links to posts from others, however I really wanted to highlight two great resources which two other IIS MVPs have started recently.

IIS Community Newsletter

Steve Schofield has recently published the first IIS Community Newsletter.  The newsletter comprises all of the latest information and happenings in the IIS Community.  If you would like to find out more or register to receive the newsletter go to http://www.iisnewsletter.com and if you have anything you’d like to contribute you can also contribute to the Wiki.  Big thanks to Steve for the mention is the inaugural newsletter for both my Twitter account and for NEBytes

Web Pro Series

Scott Forsyth has recently started a 52 week series of walkthrough videos on a number of topics relevant to IT Pros and Web Developers covering a vast range of topics including

  • Troubleshooting essentials;
  • Application Request Routing and Load Balancing;
  • URL Rewrite;
  • SQL Syntax for IT Pros;
  • Scripting;
  • Command Line Basics;
  • IIS Share Configuration;
  • Keyboard Shortcuts;

In the first four weeks Scott has covered Ping and Tracert; Understanding DNS Zone Records; Nslookup; Capturing Command Line Output.  It’s a great start and will help to fill gaps in knowledge and also add tools and techniques to your arsenal for resolving issues and implementing technologies in the best way possible based on a wealth of experience. 

Categories: How To | IIS | MVP
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Tutorial for Using ASP.Net MVC Framework on Different Versions of IIS

September 5, 2008 14:49 by Andrew Westgarth

Last night Alan Dean came up to VBUG in Newcastle to speak on ASP.Net MVC Framework.  One of the discussion points we had was any potential issues for hosting sites on IIS due to the routing and url rewrite elements of the MVC Framework.  I wasn't clear on the implications, and I hadn't seen much traffic personally on the issue.  So with a task of downloading ASP.Net MVC Framework Preview 5 so I could have a good look at it and understand it all as an alternative to Webforms, and looking into the implications and workarounds for hosting within versions of IIS I went of in search of information.

I immediately thought that with IIS7 and applications running in Integrated Mode, which is the mode I aim to run all of my applications on IIS7 in, there should be no configuration changes or modifications required since ASP.Net is part of the pipeline so all requests are processed by ASP.Net by default.  In classic mode ASP.Net requests are processed through the aspnet_isapi.dll as they would be in IIS6 so unless files are mapped to the ASP.Net Isapi filter then they wouldn't be processed.  In reading up about ASP.Net MVC on the ASP.Net website I found a great tutorial on Using ASP.NET MVC with Different Versions of IIS - hopefully this will be of help to you looking to configure and use the ASP.Net MVC Framework on IIS.

Categories: ASP.Net | How To | IIS
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Can't Save Your XSL/T File? Have You Closed Your XMLReader?

September 5, 2008 14:08 by Andrew Westgarth

Post Updated on Monday 8th September 2008 - See Below

This week I have been working on a server control for a site I'm working on which reads in an XML file containing some product information and then using an XSL/T file transforms the output into correctly formatted XHTML.  One problem which occurred with the development of the server control was that a colleague of mine who was making modifications to the XSL/T File was unable to save the changes whilst viewing the resultant XHTML in their browser.  At first hand it would appear that it would be a permissions issue, and after much checking of the permissions to confirm they were correct, it was determined this was not the issue. 

My colleague had been able to save changes to the XSL/T after a short while of the page processing which immediately pointed me to the fact that the object was still holding onto the resources.  This was further confirmed with some investigation work which I did with the help of Craig Murphy

The XMLReader object which was reading and transforming the XML using the XSL/T was still holding on to the file and placing a lock on it because the XMLReader object doesn't have a dispose method and so therefore despite my setting the object to nothing, until the garbage collector picked up the objects then the lock on the XSL/T file remained.  Craig suggested I call the XMLReader.Close() method after I had finished processing the XML, this was a method I wasn't aware of and had not seen used in any example when I did my research into the changed syntax since version 2.0 of the .Net Framework. 

Here is a code snippet below of an example of how to use the XMLReader.Close() method to release the locks on resources:

Dim strProductDataXML As String = "ProductData.xml"
Dim strProductDataXSLT As String = "ProductDataTransform.xsl"
Dim sb As New StringBuilder()
Dim sw As New StringWriter(sb)

' Create XSL CompiledTransform to hold XSLT
Dim objXSL As New XslCompiledTransform
' Create XsltSettings to hold XSLT Settings
Dim objXSLTSettings As New XsltSettings(False, True)
' Create XmlReader Object to read the XSLT
Dim objXSLReader As XmlReader
' Create XMLReaderSettings Object For XMLReader Object which will read the XSLT
Dim objXSLReaderSettings As New XmlReaderSettings()
' Create XMLSecureResolver for use with the XSLCompiledTransform
Dim objXMLResolver As New XmlSecureResolver(New XmlUrlResolver(), "http://www.mysite.com/")

'Create Reader Object to read the XSL Transform
objXSLReader = XmlReader.Create(HttpContext.Current.Server.MapPath("~/XSLT/ProductDataTransform.xsl"), objXSLReaderSettings)
' Load the Transform in the XSLCompiledTransform Object, Provide the settings and resolver objects
objXSL.Load(objXSLReader, objXSLTSettings, objXMLResolver)

' Set the Source of the ProductData XML File to be transformed
Dim xmlSource As New XmlTextReader(HttpContext.Current.Server.MapPath("~/XML/ProductData.xml"))
Dim xPathDoc As New XPathDocument(xmlSource)

' Call the close method on the XMLTextReader to release all resources which is attached too.
xmlSource.Close()

' Perform the Transformation and output it to a stringwriter object
objXSL.Transform(xPathDoc, Nothing, sw)
' Call the close method on the XSLReader to release all resources which is attached too.
objXSLReader.Close()

' Set all objects to Nothing to allow the Garbage Collector to remove them
strProductDataXML = Nothing
strProductDataXSLT = Nothing
objXSL = Nothing
objXSLTSettings = Nothing
objXSLReader = Nothing
objXSLReaderSettings = Nothing
objXMLResolver = Nothing
xmlSource = NothingxPathDoc = Nothing

' Return the transformed string
Return sb.ToString()

Now that the XMLReader is closed and has released all of the objects holding on to it, the XSL/T file can be edited and changed without having to wait for the Garbage Collector to remove the objects and release the locks.

 

UPDATE - After reading the comments I have received on this post, I have tidied up the code and made use of the Using structure, to be honest I had forgotten this was available in VB.Net from version 2.0 of the Framework.  The use of the Using structure handles the disposal of the objects and therefore releases the locks on the resources the objects are using.  Below is the updated code sample:

Dim strProductDataXML As String = "ProductData.xml"
Dim strProductDataXSLT As String = "ProductDataTransform.xsl"
Dim sb As New StringBuilder()

' Create XSL CompiledTransform to hold XSLT
Dim objXSL As New XslCompiledTransform
' Create XsltSettings to hold XSLT Settings
Dim objXSLTSettings As New XsltSettings(False, True)
' Create XMLReaderSettings Object For XMLReader Object which will read the XSLT
Dim objXSLReaderSettings As New XmlReaderSettings()
' Create XMLSecureResolver for use with the XSLCompiledTransform
Dim objXMLResolver As New XmlSecureResolver(New XmlUrlResolver(), "http://www.mysite.com")

objXSLReaderSettings.ProhibitDtd = False

'Create objXSL XMLReader Object to read the XSL Transform
Using objXSLReader As XmlReader = XmlReader.Create(HttpContext.Current.Server.MapPath("~/XSLT/" & strProductDataXSLT), objXSLReaderSettings)
    ' Load the Transform into the XSLCompiledTransform Object, Provide the settings and resolver objects    
    objXSL.Load(objXSLReader, objXSLTSettings, objXMLResolver)
    ' Set the Source of the ProductData XML File to be transformed    
    Using xmlSource As New XmlTextReader(HttpContext.Current.Server.MapPath("~/XML/" & strProductDataXML))
        Dim xPathDoc As New XPathDocument(xmlSource)
        Using sw As New StringWriter(sb)
            ' Perform the transformation and output it to a stringwriter object            
            objXSL.Transform(xPathDoc, Nothing, sw)
        End Using
    End Using
End Using

Return sb.ToString()

I'm sure you'll agree it's a lot cleaner and better structured.

Categories: How To
Actions: E-mail | Permalink | Comments (5) | Comment RSSRSS comment feed

Creating Http Redirects in IIS7 on Virtual Directories like IIS6

July 31, 2008 10:04 by Andrew Westgarth

In IIS6 when creating a virtual directory it was possible to set the virtual directory to actually add as a redirect to another page or site.  In IIS7 this is still possible however it needs to be achieved slightly differently.  Lets take an example.  Say you have a website and you are running a number of offers and would like to offer users the option of navigating to them through a short path such as domain/offer1, domain/offer2 etc then you would have in IIS6 set these Virtual Directories up with dummy Physical Paths, e.g. the root of the parent site, and set the option to redirect to a URL.

In IIS7 because the configuration is stored in a web.config file in the physical path of the virtual directory, this can cause the redirections to be overwritten, i.e. if you set up the redirection of domain/offer1 to go to domain/offers/offer1 and then go and set up domain/offer2 to go to domain/offers/offer2 you will find that both redirections go to domain/offers/offer2 because the value in the web.config file has been overwritten by the second redirect rule.  In order to achieve the desired effect and get the redirections to work, you need to actually add the redirections to the applicationhost.config file and set a location tag for the site you are working in.  This is currently not possible in the User Interface but is possible to achieve using the APPCMD utility.  Here are the steps to achieve this.

1. Open an elevated command prompt

2. then run the following command -

%windir%\system32\inetsrv\appcmd set config "nameofsite/virtualdirectoryname" -section:system.webServer/httpRedirect -enabled:true -destination:destinationofredirect -commitpath:apphost

an example of this command would be:

c:\windows\system32\inetsrv\appcmd set config "Default Web Site/offer1" -section:system.webServer/httpRedirect -enabled:true -destination:Offers/Offer1/default.aspx" -commitpath:apphost

 

The key element here in this command is the commitpath directive which adds sets the configuration in the applicationhost.config:

<location path="Default Web Site/Offer1">
  <system.webServer>
    <httpRedirect enabled="true" destination="Offers/Offer1/default.aspx" />"
  </system.webServer>
</location>

 

Hope this clears it up :).

Categories: How To | IIS
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Twitter Power - Fix Outlook.exe Process Never Ending with Skype

June 19, 2008 15:26 by Andrew Westgarth

This morning I was installing the Conferencing Add-in for Microsoft Outlook so I can set up VBUG Online Meetings and send out invitations direct from Outlook when I mentioned on Twitter that I'd been having problems with the Outlook process constantly running despite my having closed/shutdown Outlook.  This has been a really big annoyance for me for a while and I hadn't found the solution.  Thanks to the power of Twitter I've been able to sort this problem now and identify what was causing it.

Usually behaviour like this is attributed to a bad add-in running in Outlook.  Well I checked my list and found I had a couple of add-ins which I didn't recognize.  First was an iTunes Outlook add-in.  What was iTunes wanting with outlook, well I believe it is linked to the ability to sync calendar and contact information with my nano - something I've never wanted to do as I have a Windows Mobile 6 phone for that, so I removed that add-in.  Next was Xobni an outlook plugin which I was trying out but have decided to remove as I don't really need what it offers.  So now I tried running Outlook and exiting but found it was still leaving the process behind. 

One of the tweets I'd received mentioned Skype as a potential problem so I shut that down, fired up Outlook and then closed Outlook, checked in task manager and the process had successfully closed.  I then started Skype, then Outlook and then closed Outlook and checked and the process was still running.  After a little searching in the Skype forums I found the fix for my problem - http://forum.skype.com/index.php?showtopic=97020 - and it seems that the problem is known and it appears that it's just the way Skype works - what !! if I closed a program I don't expect another one to keep it running!

It appears that the View Outlook Contacts "feature" in Skype causes Outlook to remain running in the background.  The fix is to go into Skype, goto the View Menu and uncheck View Outlook Contacts.  If this option is greyed out you need to run Outlook, return to Skype while Outlook is running and the option should no longer be greyed out, allowing you to uncheck it.  Now Outlook shuts down and the process ends properly!

This "feature" is a problem in my mind - why can't Outlook Contacts get store in some form of cache in Skype so therefore not needing a permanent connection to Outlook?

The power of Twitter and social networking has helped me to fix this problem and I hope I can repay that in future through my interactions with Twitter, Facebook etc.  Special thanks go to @mehfuzh, @blowdart, @garyshort, @markjbrown, @recumbent and @james_a_hart who helped me out with some very useful time and tweets!

Categories: How To
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

HOWTO: Enable Scaling on NVidia Quadro NVS 120M

October 29, 2007 11:06 by Andrew Westgarth

At the recent VBUG conference I had an issue with my video adapter in my laptop.  I arrived after sitting in traffic getting from one side of Reading to the other to get to TVP, and got through registration and went into Chicago 1 to prepare for the opening and keynote of the VBUG Conference.  I plugged my laptop into the equipment so I could present the opening section of the conference.  But found that although the display via the projection equipment was fine, the display on my laptop had resized my screen down to just a small 1024x768 resolution screen in the middle of my laptop screen :-(.  I was more than a little concerned by this as I was presenting again in Chicago 1 over the course of the two day conference, and back in June I had presented in Chicago 2 with no problems.  I spent a little while trying to get it to expand the display to the full width and height of my screen to no avail, and so decided to look at it later.

Later on during the day I found out what the problem was to do with an update to the nVidia driver (which I installed in July) settings changing a default setting relating to the way in which the display extended.  I managed to fix this minor issue and thought I'd post details for anyone else who has a similar setup to avoid the ensuing panic and frustration which built up as I tried to figure out what was wrong.

I have a Dell Latitude D820 and the graphics device in this setup is the nVidia Quadro NVS 120M 256MB. To get your display to expand to the full available screen no matter which resolution you are running under do the following:

Go to the nVidia Control Panel (This can be accessed via the context menu on the desktop or via Control Panel)

nVidiaControlPanel

Select the Display option and then on the following screen:

nvidiachooseoption

Next Select Change the panel scaling

nVidiaScaling

Next select "Use NVIDIA Scaling" to force the display to scale out to use the full screen available.

I hope this is useful to owners of this laptop graphics card, let me know if you've suffered this pain too.

Great Article on Developing Modules and Handlers for IIS7 using .Net

August 16, 2007 14:44 by Andrew Westgarth

Mike Volodarsky, a Program Manager on Microsoft's IIS Team, has published a great Blog Post on developing modules and handlers for IIS7 using .Net.  The post goes through how to decide which to develop, which tools you need and how to develop modules and handlers and deploy them to an IIS7 server.  This posting is well worth looking at if you are interested in IIS7 Development, http://mvolo.com/blogs/serverside/archive/2007/08/15/Developing-IIS7-web-server-features-with-the-.NET-framework.aspx.

This is the start of an IIS7 .Net Developer series, so keep an eye on Mike's blog for more content coming soon.

Categories: ASP.Net | How To | IIS
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed


MCTS

Post calendar

<<  March 2024  >>
MoTuWeThFrSaSu
26272829123
45678910
11121314151617
18192021222324
25262728293031
1234567

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2024