Andrew's Blog

Random Thoughts of an ASP.Net Code Monkey

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

September 5, 2008 22: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.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories: ASP.Net | How To | IIS
Actions: E-mail | Permalink | Comments (1) | Comment RSSRSS comment feed

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

September 5, 2008 22: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.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories: How To
Actions: E-mail | Permalink | Comments (7) | Comment RSSRSS comment feed

Creating Http Redirects in IIS7 on Virtual Directories like IIS6

July 31, 2008 18: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 :).

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories: How To | IIS
Actions: E-mail | Permalink | Comments (3) | Comment RSSRSS comment feed

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

June 19, 2008 23: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!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories: How To
Actions: E-mail | Permalink | Comments (2) | Comment RSSRSS comment feed

HOWTO: Enable Scaling on NVidia Quadro NVS 120M

October 29, 2007 19: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.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories: General | How To
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

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

August 16, 2007 22: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.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories: ASP.Net | How To | IIS
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

NxtGenUG Podcasts - How To and DDD5

July 17, 2007 09:06 by Andrew Westgarth

Recently Richard Costall and Dave McMahon gave a presentation at Community Leaders Day - an event for Community Leaders at Microsoft TVP, UK - on the subject of Podcasting. Indeed they even recorded a Podcast, showed us how to publish it and edit it Live in the session. They have made the podcast available to all and if it's something you are interested in I recommend a listen - http://www.nxtgenug.net/Podcasts.aspx?PodcastID=35.

While at DDD5 Dave McMahon caught up with me for an interview on IIS7 and my experiences of starting to speak on the circuit at national and local events. This podcast also contains interviews with attendees, speakers and organisers of DDD5, excellent work once again - to listen to the DDD5 podcast use this link - http://www.nxtgenug.net/Podcasts.aspx?PodcastID=36 also why you're there why not check out their other podcasts

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Developing Web Applications using Visual Studio 2005 and IIS7

June 21, 2007 18:39 by Andrew Westgarth

I got into work this morning and checked my feeds and noticed this post - Solution/Hotfix: Developing web applications using Visual Studio 2005 and IIS7 from the Web Development Tools Team.

A hotfix has been released for Visual Studio 2005 to aid F5 debugging with Visual Studio 2005 and it also enables debugging with Vista Home Versions! Check it out now!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

FrontPage Server Extensions for IIS7

June 12, 2007 23:14 by Andrew Westgarth

A query I had at the VBUG Leeds meeting last Wednesday was on the subject of FrontPage Server Extensions(FPSE) for IIS7. There is a beta of these available currently and they will work with Windows Vista and Longhorn Server Beta 3 (or should that now be Windows Server 2008 Beta 3?). To download them use this link: http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1460

For further information on the reason why FPSE were not included with Windows Vista and Longhorn Server Beta 3 see Robert McMurray's Blog where he has two detailed posts about the FPSE for IIS7:

Bill Staples also has the details on his Blog, which is another blog worth reading for information on IIS7
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories: ASP.Net | Events | How To | IIS | VBUG
Actions: E-mail | Permalink | Comments (3) | Comment RSSRSS comment feed

Code Snippets

December 12, 2006 05:13 by Andrew Westgarth

I was talking to a colleague the other day and introduced him to Code Snippets. This is one of many features which are in Visual Studio 2005 and I'm sure that there are many other I don't know about but would find useful. My colleague was amazed at the simplicity but also the potential of this feature. I have developed my own snippets and they are very easy to do. To use code snippets, from within VS2005, go to Edit -> Intellisense -> Insert Snippet and this displays the snippet manager for you to select a snippet from. Snippets are great for removing the repetitiveness of entering the same structures many times, i.e. property constructs, if statements and try catch loops. Take a look at them and let me know what you think.

Also let me know your favourite tip/treat for Visual Studio 2005.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories: General | ASP.Net | How To
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Post calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

Disclaimer

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

© Copyright 2010

Tag cloud