Search This Blog

Loading...

Friday, May 14, 2010

ASP.Net 4 and IIS6

A few days ago I posted about how to switch frameworks (to ASP.Net 4) on a single website  (among many) without having to restart IIS.  Well, Now I ran into another issue:  “Connection Reset” error from the browser. Tried a bunch of things, including checking logs, recreating the App Pool, rechecking all website settings, etc….  Nothing. 

After some googling, it turns out that it is not enough to Install asp.net 4 but it has to be manually “enabled”.  I’ll give you the quick run through but here is the post that that goes into more detail about the fix.

1) Confirm that ASP.Net 4.0 is disabled.
cscript iisExt.vbs /ListFile

If the entry for .Net 4 has a 0 on the left, then you need to enable it

2) Enable .Net 4 extension

cscript iisExt.vbs /EnFile C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll

Run the first command and you should have a 1 instead of 0 next to .Net 4.


image

That did it for me, I hope it works for you as well.



-D

Tuesday, May 11, 2010

Using IIS Virtual Path: Upgrade a site to .Net 4 without restarting IIS

Recently, our project was upgraded to ASP .NET 4.0. Upgrading Dev environments was a breeze, however, in production, only one website needed to run ASP.NET 4.0 while the other websites needed to be left alone.

First thing I tried doing was go to the properties dialog of the website and switch the targeted framework.

clip_image002

This is the warning message I got:

clip_image004

Naturally I cancelled that and attempted running the suggested command, but the problem was how to find out the "IIS Virtual Path" bit?.

I found this answer in this Stack Overflow: http://stackoverflow.com/questions/1804208/how-do-you-work-out-the-iis-virtual-path-for-an-application

The answer basically boils down to executing "aspnet_regiis -lk" command to find out your website ID and then run the command suggested by the warning message.

My problem running "aspnet_regiis -lk" was that I got an incomplete list of IDs and also I didn't know which ID corresponded to the Website I wanted to work on.

A co-worker pointed out an easier way to find the IDs for your websites: click on the "Website" node (folder) in IIS. Now on the right side you should see a list of all websites with their "Identifiers", State, IPs and ports.

clip_image006

Cool! Now I can run my command with the correct ID.

1) Navigate to C:\Windows\Microsoft.net\Framework64\v4.0.30319
2) Execute aspnet_regiis.exe -norestart -s “W3SVC/YOURWEBSITEID/root

Note: If your application is not at the root of the website, then you need to add the AppName at the end: “W3SVC/YOURWEBSITEID/root/AppName

Now, go to your website properties and check that your targeted framework is ASP.NET 4.0 and voila!

-D

Wednesday, May 5, 2010

VS2010 New feature Call Hierarchy and ReSharper's Call Tracking

I've been playing with VS2010 for a couple of days now, and I just recently stumbled upon an awesome features that every Dev will love: "Call Hierarchy".

In simple words, you can now view where your methods/properties are being called from. Now, you might say, "We've had that for a while, its called 'Find usages'", Well, this is better: You can actually view and go through the call tree graph WITHOUT having to be in debug mode. As Borat would say: "Itzanice!"  Scott Gu has a really nice post about it, go see it.

Playing around with it, I noticed that ReSharper also has its own implementation of it: “Call Tracking”.  And, it is actually better  than the one with VS2010.  So, if you have ReSharper, go to a method and do Ctrl+Shit+Alt+A , then select “Incoming Calls”. A new window will open up showing all callers to this functions and the tree graph. It’s so cool!

 Select “Incoming Calls”
Untitled

New Windows opens up with all callers and the call tree
image

You might have also noticed that you can select “Outgoing Calls” which is the exact opposite of viewing all the callers, it’s a “Go to definition” on steroids!

As ReSharper puts it, Call Tracking is “an all-out Find Usages and Go To Declaration”.  Go check out their post about it to find out more details.

Tuesday, May 4, 2010

Upgrading your build server to use .Net 4 + Nant

At work we use CruiseControl.net + Nant for our continuous integration. Recently we have upgrades to VS2010 and .Net 4.0 (awesome so far). Alas, as soon as we converted our solution to .Net 4.0, our build server broke! After googling and wrestling for 2 days with build errors, I finally got the build server running again. I found most of my questions on Stack overflow, however I had this "AL exited with code 128" build error that I could not get past and it was driving me crazy! So, below are the steps to upgrade to .Net 4.0 and to solve the "AL" error message (that hopefully you won't get):

First thing. You DO NOT need to intall VS2010 in the build server like many people think. You do have to install the latest Windows SDK. (I believe 7.0)

1) Install .Net 4.0 Framework.

2) Install latest Windows SDK.

Install the latest Windows SDK, then go to the registry and copy the key "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0" and rename all instances of 7.0 to 7.0A. The Build server is going to look at that path in order to get the "Installation Folder key". Alternatively, You can copy the text below into a notepad and save it as "whatever.reg", then run it and it should import the key and subfolders into the registry.

*~~~~~~~~~~~~~~~~~~~~ Copy everything below this line ~~~~~~~~~~~~~~~~~~~~~~

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\"
"ProductVersion"="7.0.30319"
"ProductName"="Microsoft Windows SDK for Visual Studio 2010"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx35Tools]
"ProductVersion"="7.0.30319"
"ComponentName"="Windows SDK .NET Framework 3.5 Multi-targeting Utilities"
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools]
"ProductVersion"="7.0.30319"
"ComponentName"="Windows SDK Tools for .NET Framework 4.0"
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\NETFX 4.0 Tools\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-SDKTools]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\"
"ProductVersion"="7.0.30319"
"ComponentName"="Windows Common Utilities"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-Win32Tools]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\"
"ProductVersion"="7.0.30319"
"ComponentName"="Windows Utilities for Win32 Development"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-WindowsHeadersLibs]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\"
"ProductVersion"="7.0.30319"
"ComponentName"="Windows Headers and Libraries"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-WinSDKIntellisenseRefAssys]
"InstallationFolder"="C:\\Program Files\\Reference Assemblies\\"
"ProductVersion"="7.0.30319"
"ComponentName"="Windows Intellisense and Reference Assemblies"

*~~~~~~~~~~~~~~~~~Do not include this line~~~~~~~~~~~~~~~~~~~~~

3) Modify your Nant.exe.config file.

Towards the end of your Nant.exe.config file, modify the <startup> section to add .Net 4.0 as a supported Runtime:

<supportedRuntime version="v4.0.30319" />.

Also, under the <properties> section, add a property:

<property name="nant.settings.currentframework" value="net-4.0" />

This will make your builds default to that framework. You can also put this property in your projects Nant file, so you can tell each project what version to target. Finally, you need to add the .net4.0 framework node. Here is a link to that configuration section: http://pastebin.com/3ghS0gyA

4) Review the Build section of your Nant file

I was using the msbuild task for NantContrib. That still works, but if it doesn't, you can always use the <exec> task and call msbuild.exe like so:

<property name="msbuild.exe" value="C:\WINDOWS\Microsoft.NET\Framework\v4.0\MSBuild.exe" />    

<exec program="${msbuild.exe}">        
        <arg line="/property:Configuration=${YourSolutionConfigurationHere}" />         
        <arg line='"${YourSolutionFileFullPathHere}"' />         
        <arg value="/target:Rebuild" />         
        <arg value="/verbosity:normal" />         
        <arg value="/nologo" />         
</exec>

5) Random Errors

I ran into some weird build errors: "error MSB6006: "AL.exe" exited with code 128" That's it, not helpful at all. I did some googling and came up with few answers. Here are the links: msdn help and asp.net forums.  I wrestled with that error for a full day, studying the "detailed" and "diagnostic" logs, but all it did is pointing me to the assembly that failed building. No specific error. I could not even duplicate it on my local box.

Finally, I decided to try the suggestion about the "resource" files naming convention in the asp.net forum link, and... alleluia! my build started working. I don't know what's up with the build failing because of the resource name, still working on that, but my immediate goal was to get the build working.

StackOverflow related posts:

http://stackoverflow.com/questions/1215731/building-net-4-projects-with-nant
http://stackoverflow.com/questions/2353404/nant-msbuild-task-with-net-4-0-rc
http://stackoverflow.com/questions/1291221/going-from-solution-to-exec-programmsbuild-in-nant

Hope this helps someone else out there.

-D

Saturday, July 25, 2009

Range() and LinqToXml

A couple of days back, I was working on some dashboard components for our portal that use fusion charts. I was generating empty XML templates when I ran into a bit of a challenge: I had to generate 30 "category" nodes that were, basically, dates, and also empty data values for each of those dates. The trick was that the dates had to be based on the day the Chart was accessed.

Well, to be fair, it wasn't really "a challenge", just one of those pain in the ass-spaghetti-stinky piece of code that sometimes we have to write to go on with our lives.

I hated the idea to have some ugly loop (since I discovered linq, all loops are ugly!) that iterated 30 times and grabbed the current date the chart was accessed and then subtracted the index of the loop, and finally made sure that the result was sorted ascending.

So Range function and LinqToXml came to the rescue! Actually, I didn't know that Range() was available in .Net. A co-worker pointed out to me that I did exist and that it was under the "Enumerable" Class. (Thanks Connor!)

So, the potentially "ugly" loop ended up being a beautiful one-liner linq query:

Dim category = (From index In Enumerable.Range(0, 30) Select _
<category label=<%= DateTime.Now.AddDays(-index).ToString("M/dd") %>/>).Reverse

Man, Linq rocks! I can't stop saying it. Well now that I had the hard part done, I had left to generate some empty data sets and then put it all together:

Dim emptySets = From index In Enumerable.Range(0, 30) Select <set value="0"/>

'Build the Xml template
Dim chartData = <?xml version="1.0" encoding="utf-8"?>
<chart>
<categories>
<%= category %>
</categories>
<dataset SeriesName="Name1">
<%= emptySets %>
</dataset>
</chart>

'return the build template to the calling function
Return chartData.ToString

So the ouput of my query would look like this:

<chart>
<categories>
<category label="6/26"/>
<category label="6/27"/>
<category label="6/28"/>
<category label="6/29"/>
<category label="6/30"/>
<category label="7/01"/>
<category label="7/02"/>
<category label="7/03"/>
<category label="7/04"/>
<category label="7/05"/>
<category label="7/06"/>
<category label="7/07"/>
<category label="7/08"/>
<category label="7/09"/>
<category label="7/10"/>
<category label="7/11"/>
<category label="7/12"/>
<category label="7/13"/>
<category label="7/14"/>
<category label="7/15"/>
<category label="7/16"/>
<category label="7/17"/>
<category label="7/18"/>
<category label="7/19"/>
<category label="7/20"/>
<category label="7/21"/>
<category label="7/22"/>
<category label="7/23"/>
<category label="7/24"/>
<category label="7/25"/>
</categories>
<dataset SeriesName="Name1">
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
<set value="0"/>
</dataset>
</chart>

So, there it is. no messy loops, no smelly code, just ....Linq.
Hope this helps

Monday, July 13, 2009

Consuming an RSS feed using LinqToXml

I needed to display some RSS feeds into a dashboard page in one of our websites. I figured I had to mess with XML, XPath, etc.. to browse the xml structure of the post. However, LinqToXml turned out to be the perfect tool for this task. I used Scottgu’s post as a reference, but did my own little twist at the end to avoid another “loop”

First, pass the Rss feed Url into an Xdocument variable:


Dim feedXml As XDocument = _
XDocument.Load(“http://feeds2.feedburner.com/AppriverMalwareWatch”)

Now I need to iterate through the “item” children tags in the XML document and get the “link”, “title” , and “pubDate” elements. Also, I am going to display each post as a hyperlink in an unordered list with the date next to it. Finally, I only need the most recent 8 posts. Here is where magic of LINQ comes in handy:

Dim myFeeds = From feed In feedXml.Descendants("item") Select _
<li>
<a target="_blank" href=<%= feed.Element("link").Value %><%= feed.Element("title").Value %>
</a><%= Date.Parse(feed.Element("pubDate").Value).ToString("M/dd") %>
</li> _
Take 8

'Add xElements to the String literal
Dim myUL = <ul>
<%= myFeeds %>
</ul>

Now that I have added the feeds to my unordered list, I need to write the html to the div container:


'Write string literal to Div's body
Me.uxDivUls.InnerHtml = myUL.ToString

That's it. In a few lines of code I was able to Consume an Rss Feed. What is there not to love about linq to xml??

Happy coding!

Friday, April 18, 2008

Chicken Chicken

Tuesday, April 8, 2008

ClientQueryString Page Property

I was browsing through the Page class in System.Web.UI assembly and I run into the "ClientQueryString" property. Here is its signature:

Public Readonly Property ClientQueryString As String.

It returns the page's querystring in an encoded fashion (so one would have to use

HttpServerUtility.UrlDecode to decode the querystring.) Inspecting the source code I did noticed a couple of interesting things: The property goes through the Page.s_systemPostFields and adds them to a "black list" which will be excluded from the string returned by the property. Also, and I think pretty neat, is the way the black list gets excluded from the query string results: The Request.QueryString gets casted as an HttpValueColletion object and then it invokes its overriden "ToString" Method to which the "blacklist" is passed to in its arguments. (excludeKeys is a Hashtable of "keys to exclude".)
Me._clientQueryString = DirectCast(Me.Request.QueryString, HttpValueCollection).ToString(True, excludeKeys
I thought that was pretty cool, no need to loop through the collection, just pass it as an argument and the .ToString takes care of it.

With this property you can't get an individual querystring value since you can't specify a "key name". You get all of query string values. I guess this is useful if you need to pass on the querystring to another page or if for some reason you need perform some custom parsing and manipulation on the query string.

Saturday, April 5, 2008

Every Build You Break

This is hilarious. Roy Osherove posted a video on YouTube.com where he sang "Every build you break" to a live audience.


Tuesday, March 25, 2008

Visual Studio 2008 HotFix and VB HotFix

A HotFix for VS2088 was released early in February that addresses several issues reported with Web Applications. A list of the fixed bugs can be seen on ScottGu's Blog. You can download the hot fix here.

Also, 2 days ago, the Visual Basic team released a HotFix that solves some performance issues in VS2008. Download it here


Monday, March 24, 2008

App_Offline Goodness

ASP.NET 2.0 comes with this built-in feature to easily bring down an Web Application, make changes to it and reload the application back again.

It's as easy as uploading an App_Offline.htm file in the root of your Web Application directory and you are done. Include any "under construction" or "maintenance" messages in the App_Offline.htm file that you want to display to your end users.

Once you are done, simply delete the file and ASP.NET will reload the application and everything is back to normal. For detailed info check ScottGu's blog.

Friday, March 21, 2008

Server.HtmlEncode vs HttpUtility.HtmlEncode

Have you ever wonder why there is an Html Encoding function (and other similar functions) in 3 different objects and namespaces?
The most common one is Server.HtmlEncode or System.Web.HttpContext.Current.Server.HtmlEncode.  The Server Object is an instance of the System.Web.HttpServerUtility Class and it is readily accessible through any .aspx page since they inherit from the Page object which in turn has a Server Object instance.  The second HtmlEncode function lives under System.Web.HttpUtility.  This class is basically a static version of the Server class which means that you could call the HtmlEncode function from a static function or call from another class that does not have an instance of the HttpServerUtility class. Finally,  The third HtmlEncode function is located in the Microsoft's AntiCross-Site Scripting Library. In contrast with the Server.HtmlEncode and HttpUtility.HtmlEncode functions, the later function takes a more aggressive approach by using a white-list filtering instead of a black-list.
Hope this helps.

Thursday, March 29, 2007

Multi Touch video....COOL!!!

I was visiting wollzelle's blog page and I came accross this REALLY cool video. It bet you these guys stole the idea from that movie called "Minority Report." Cheaters...

Wednesday, March 28, 2007

Sarcastic Wednesday!!!

You guys should check this out:

Sarcastic Wednesday

Hilarious. You will thank me later..

C# and VB together?

I have an app in VS 2005 that contains both VB and C# code in the same website project. At compile time I kept getting this error:

"The files '/WebSite/App_Code/VB/test.vb' and '/WebSite/App_Code/CS/test.cs' use a different language, which is not allowed since they need to be compiled together."

To go around this issue, simply add the following to your web.config file under the compilation tag:

&ltcodeSubDirectories>
&ltadd directoryName="CS">
&ltadd directoryName="VB">


In this case, all the VB files and C# files were already separated into different folders inside the App_Code Folder.

Hope this helps.