 Cache.Insert(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemUpdateCallback) http://msdn.microsoft.com/en-us/library/cc491414.aspxMy new favorite method in .Net cache'ing. Before I explain why I love it I'm going to show you how it works in a very easy way, because that's all you really care about anyways....I know this because I'm the exact same way annnnnnd Google Analytics tells me so by your actions visitors. The place I like to put this method is in my constructor on my data layer, this way it's called with frequency. public static class DataLayer { static DataLayer() { HttpContext.Current.Cache.Insert("AnyStringYouLike", "AnyStringYouLike", null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, new CacheItemUpdateCallback(FunctionYouWantToCall)); }
public static void FunctionYouWantToCall(string aKey, CacheItemUpdateReason aReason, out object anObject, out CacheDependency dependency, out DateTime expiration, out TimeSpan aTimeSpan) {
if (DateTime.Now.Day == 22) { if (AFeedIMade.GenerateFeed()) { ErrorHelper.LogError("AFeedIMade", "Success"); } else { ErrorHelper.LogError("AFeedIMade", "Failure"); } } dependency = null; expiration = DateTime.Now.AddMinutes(20); aTimeSpan = Cache.NoSlidingExpiration; anObject = "AnyStringYouLike"; } }
What's happening here? - I insert into cache a delegate that runs a function I specify I would like to run at a specific time. I do this by saying check the cache initially every five minutes, but once it jumps into the function every 20.
- Once it's in the function if the day is the 22nd of the month then I run the code to generate my feed, if it's not then I simply set the cache to check it every 20 minutes.
The first question you may ask your self is why don't you set the cache to check the time every 22 days or so. The problem with that is what if you set it back 22 days on the 21st day. Then you miss the day you want to check, the 22nd for that month, and your feed (or whatever you are having the method do) gets delayed by at least one month. Since every month is different in length, it's just not a smart decision. For good measure I've found that having the cache checked every x minutes under 60 minutes is the best way to go. It's less likely for a specified time frame to be missed in the function. Last note, if by chance you are calling the cache outside of the websites context don't forget you can use: HttpContext.CurrentLike so: HttpContext.Current.Cache.Insert(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemUpdateCallback)
Problem:The project file 'path ' cannot be opened. The project type is not supported by this installation. Solution:The way I corrected this issue of not being able to open a ASP.NET MVC 1.0 project goes like this. I was using VS 2008 - Install SP1 for VS 2008
- Install MVC 2.0 framework
- I realized I had an MVC 1.0 project and I used this tool to change the project to MVC 2.0.
The tool works great, props to Eilon Lipton never met the guy but I'm down with anyone that will make my life easier. http://weblogs.asp.net/leftslipper/archive/2009/10/19/migrating-asp-net-mvc-1-0-applications-to-asp-net-mvc-2.aspx
Other Possible Solutions: Run this command from the command promp:
devenv /ResetSkipPkgs This will try to load any Visual Studio packages that failed previously at some point, such as the WPF project flavor package, which would cause the error message you're seeing. (1)
Explanation:
Listen folks MVC is a fun style of programming, but unless you are using unit tests, the most compelling reason to use MVC, MVC becomes more of a hindrance than helpful. Now any biased advocate of ASP.NET MVC will most likely tell you different, but I feel I am very unbiased. Don't wanna believe me, Kevin Pang gives a great list ( http://www.kevinwilliampang.com/2009/04/21/should-you-use-asp-net-mvc/) of reasons on why or why not to use ASP.NET MVC. The biggest lesson here, don't just use a technology because you think it's cool, use it because you know it's the right fit for the problem. In this case if you are creating an ASP.NET MVC application, make sure you create unit tests (the first thing asp.net MVC asks you when you create a new project) otherwise you are just using a technology because you wanna and nobody likes those people, especially after they leave the project.

Problem:Error 43 An error occurred loading a configuration file: Failed to start monitoring changes to '[my path]' because the network BIOS command limit has been reached. For more information on this error, please refer to Microsoft knowledge base article 810886. Hosting on a UNC share is not supported for the Windows XP Platform. [my path]\web.config Solution:
REMEMBER YOU ONLY NEED TO MAKE THESE CHANGES ON YOUR MACHINE NOT THE MACHINE YOU ARE TYRING TO ACCESS
- Add the following DWORD value at the following registry key:
HKEY_LOCAL_MACHINE\Software\Microsoft\ASP.NET\FCNMode The following list possible values for the FCNMode DWORD value and the behavior that is associated with each value. - 0 or greater than 2 - This is the default behavior. For each
subdirectory, the application will create an object that will monitor
the subdirectory.
1 - The application will disable File Change Notifications (FCNs).
2 - The application will create one object to monitor the main
directory. The application will use this object to monitor each
subdirectory.
I recommend setting the value to 1, to disable the FCN. This is what is causing the error when you try to use the debugger. DON'T FORGET: If you are running a 64bit version of windows you will need to go to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ASP.NETExplanation:When building over a network I believe MSBuild creates a thread of some sort for each file it's compiling. This tells it to create only one for the entire project/solution. For some reason this fixes it. Ugg these last few posts have been some tuff ones. This blog ( http://tonybellomo.com/FullBlog.aspx?BlogID=10176) helped lead me to my answer, though the 64 bit part through me for a spin.
Problem:
Done executing task "AspNetCompiler" -- FAILED. Done executing task "CallTarget" -- FAILED. (default target) (1) -> (Website target) -> ASPNETCOMPILER : error ASPRUNTIME: Request failed. Solution:
What was going on and not being said was the computer I was on didn't trust the assemblies I was using on another computer....We all could have got that from the error right? Anyways, there is a fun little tool called, .NET Framework 2.0 Software Development Kit. Once this kit was installed and downloaded I ran an application called, .NET Framework 2.0 Configuration. In this tool I selected - Runtime Security Policy <-- Once selected in the right pane I selected
- "Adjust Zone Security"
- Once this is selected I choose
- "Make changes to this computer." Click Next
- On the next screen click "Local Intranet" and move the trust arrow up to "Full Trust" I did it for Trusted Sites also.
Explanation:
Remember .Net doesn't let you run assemblies from any which location. Why would they ‽ That could be a nightmare of security issues, so developers when working on assemblies across the network and things go south always think perms, down to an assembly level.
Problem:When I look for the id of an ASP.NET element with some sort of neat DOM querying language I can't find it. Solution:Remember ASP.NETer's ASP.NET renames the id from what you named it to something different when it writes the element out to the page. The good news is ASP.NET always names it to the same unique name (something like but not necessarily ctl00_classname_controlname). Knowing this, you can run your page once and grab the id from the page source. Now use your super cool DOM querying language of choice to find that id by it's new proper ASP.NET name. Explanation: Why does ASP.NET do this? The good super geeks at Microsoft know that most of us, not you the reader of course, are not wise enough to give each ASP.NET element a unique name so they won't conflict with each other when ASP.NET is doing all its little magic tricks. Once again this is a stupid little error that hung me up for more than I'd like to admit. I knew ASP.NET did this I just didn't piece together on why I couldn't find the element by id with my querying language.
You wanna set up a continuous integration server for .net and you want to do it fast, problem is learning all the darn elements and what they do for a nant script (default.build) and for the Cruise Control script (ccnet.config), ugg what a pain. Well I'm here to help you. I just created these two scripts on a very basic level to help you get moving quickly, because who honestly wants to waste time setting these things up. I provided plenty of comments too and links in the scripts to websites to make this as painless and as quick as possible.
Feel free to take and use and build upon, but remember to share and certainly don't snip it and play to your friends on how quickly you set it up and not tell them where you went. That's just not cool. Some might even say you're being a poser. :)Cruise Control config file ccnet.config:
<!-- A great refrence website -->
<!-- http://ilmatte.wordpress.com/2008/06/01/cruisecontrolnet-tutorial-part-1/#ccnettutsourcecontrolblock -->
<cruisecontrol>
<project name="testProject">
<!-- URL of web interface set up for cruise control -->
<webURL>http://localhost:8080/default.aspx</webURL>
<!-- Directory of your project checked out from whatever -->
<!-- repository you use and build script is in -->
<workingDirectory>C:\dev\ccnet</workingDirectory>
<!-- Directory of where all the build logs will be placed -->
<artifactDirectory>C:\develop\CCnet\project1CCnetArtifacts</artifactDirectory>
<!-- Hook for using Subversion -->
<!-- Parameter documentation for sourcecontrol plugin using svn: -->
<!-- http://ccnet.sourceforge.net/CCNET/Subversion%20Source%20Control%20Block.html -->
<sourcecontrol type="svn">
<trunkUrl>http://win-r7ld6grk131:1234/svn/testproject/trunk/testapp</trunkUrl>
<workingDirectory>C:\dev\ccnet</workingDirectory>
<executable>C:\csvn\bin\svn.exe</executable>
<username>admin</username>
<password>admin</password>
<timeout>60000</timeout>
</sourcecontrol>
<!-- Hook for Git: Didn't spend to much time -->
<!-- setting this up it may need some more tweeking -->
<!-- and I'm not sure CC supports it natively yet -->
<!--
<sourcecontrol type="git">
<repository>C:\repositories\examplerepository\TestApplication</repository>
<branch>master</branch>
<autoGetSource>true</autoGetSource>
<executable>git</executable>
<tagOnSuccess>false</tagOnSuccess>
<tagCommitMessage>ccnet build {0}</tagCommitMessage>
<workingDirectory>C:\repositories\examplerepository\TestApplication</workingDirectory>
<timeout>60000</timeout>
</sourcecontrol>
-->
<!-- How often it should check the repository for changes -->
<!-- Parameter documenation for triggers -->
<!-- http://ccnet.sourceforge.net/CCNET/Interval%20Trigger.html -->
<triggers>
<intervalTrigger name="SVN" seconds="10" buildCondition="IfModificationExists" />
</triggers>
<!-- You can use MSBUILD instead of NANT because it can just build the -->
<!-- the solution file, as of right now you can't do that in NANT -->
<!-- for anything above Visual Studio 2003 Solution files -->
<!-- If you have any issues setting this up to build over a network
<!-- Look at these blog posts
<!-- http://bencoffman.com/blog/2010/12/01/Error43AnErrorOccurredLoadingAConfigurationFileFailedToStartMonitoringChangesTo.aspx -->
<!-- http://bencoffman.com/blog/2010/12/01/ASPNETCOMPILERErrorASPRUNTIMERequestFailed.aspx -->
<!--
<tasks> <msbuild> <executable>c:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable> <workingDirectory>\\vdev2\data\Inetpub\wwwroot\KSL\BartonCreek\</workingDirectory> <projectFile>bartoncreek.sln</projectFile> <buildArgs> /t:Rebuild /p:Configuration=Debug</buildArgs> <timeout>600</timeout> </msbuild> </tasks> -->
<!-- labels each build with my name on the front of the project name -->
<!-- Parameter documenation for labeller at -->
<!-- http://ccnet.sourceforge.net/CCNET/Default%20Labeller.html -->
<labeller type="defaultlabeller">
<prefix>Bens-TestProject-</prefix>
<incrementOnFailure>true</incrementOnFailure>
</labeller>
<!-- Runs the super sweet nant script you created -->
<!-- there is an <exec> parameter for nunit tests OR -->
<!-- You can just use <nunit>.....just saying -->
<!-- Parameter documentation for task -->
<!-- http://ccnet.sourceforge.net/CCNET/Task%20Blocks.html -->
<tasks>
<nant>
<executable>C:\nant-0.90\bin\nant.exe</executable>
<baseDirectory>C:\dev\ccnet</baseDirectory>
<nologo>false</nologo>
<buildFile>default.build</buildFile>
<buildTimeoutSeconds>1200</buildTimeoutSeconds>
<targetList>
<target>build</target>
</targetList>
</nant>
</tasks>
<!-- The directory to copy to. A subdirectory called the current build's label will -->
<!-- be created, and the contents of sourceDir will be copied to it -->
<!-- http://ccnet.sourceforge.net/CCNET/Build%20Publisher.html -->
<publishers>
<buildpublisher>
<sourceDir>C:\dev\ccnet\bin</sourceDir>
<publishDir>C:\Builds\</publishDir>
</buildpublisher>
</publishers>
</project>
</cruisecontrol>
nant build script default.build:
<?xml version="1.0"?>
<!-- Good Reference site for the new comers -->
<!-- http://ondotnet.com/pub/a/dotnet/2003/01/27/nant.html -->
<project name="Bens Test Project" default="run" basedir=".">
<!-- REMEMBER:!! as of version .90 nant only supporst building of -->
<!-- Visual Studio 2002 and 2003 Solution files -->
<!-- Builds your code and creates a bin directory to put your -->
<!-- library's (assemblies) in -->
<target name="library">
<mkdir dir="bin" />
<csc target="library" output="bin\testLibrary.LastNames.dll">
<sources>
<!-- I used star here to compile all .cs files. -->
<!-- Also I put a slash in so I could put my build file in -->
<!-- The root solution folder and have it step into each -->
<!-- project file and build all the code it then takes the -->
<!-- library's (asseblies) and puts them in the -->
<!-- root bin folder -->
<include name="testLibrary/*.cs"/>
</sources>
</csc>
</target>
<!-- Builds your code and creates a bin directory to put your -->
<!-- exe in -->
<target name="build" depends="library">
<csc target="exe" output="bin\BensTestApplication.exe">
<sources>
<!-- I used star here to compile all .cs files. -->
<!-- Also I put a slash in so I could put my build file in -->
<!-- The root solution folder and have it step into each -->
<!-- project file and build all the code it then takes the -->
<!-- exe and puts them in the -->
<!-- root bin folder -->
<include name="TestApplication/*.cs"/>
</sources>
<!-- classes I referenced in "BensTesdtApplication" are in -->
<!-- this library -->
<references>
<include name="bin\testLibrary.LastNames.dll" />
</references>
</csc>
</target>
<!-- Deletes the entire bin folder and all of its contents -->
<target name="clean">
<delete dir="bin" failonerror="false"/>
</target>
<!-- Executes the exe your program built, -->
<!-- This will not run if the "build" "target" fails -->
<!--
<target name="run" depends="build">
<exec program="bin\BensTestApplication.exe"/>
</target>
-->
</project>

I recived this error when installing Cruise Control .Net (CCNet)
Error Readout:Handler "CCNetHttpHandler" has a bad module “ManagedPipelineHandler” in its module list Fix:%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i or %windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i Remember in Windows 7 you have to run this in a command prompt with Administrator privileges. The easiest way to do this is click your windows button in the lower left corner, in search type cmd, then right click cmd and select "Run As Administrator."Explanation:Apparently a glitch somewhere caused .net to not be registered with iis. I'm running windows 7 with iis 7.x. This glitch really didn't make itself visible too well, but hey when you are having a problem with .Net and all else fails, reboot or reinstall .Net. It's the Microsoft way. :) And now Crusie Control .net should finally run on your machine. These dudes posted the fix first. Thanks Fellas http://wishmesh.com/2010/08/iis-7-5-error-handler-pagehandlerfactory-integrated-has-a-bad-module-managedpipelinehandler-in-its-module-list/
Error Readout:"This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default... Fix:Change the following values located in the applicationHost.config file located in Windows\system32\inetsrv\config. <section name="handlers" overrideModeDefault="Deny" /> change this value from "Deny" to "Allow" <section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Deny" /> change this value from "Deny" to "Allow" Explination:This error came up when I was setting up cruise control on windows 7 with iis 7. Cruise control sets the platform for creating custom handlers for their applicaiton in the future. Digging a little deeper you can see they set their custom handles to ".aspx" which means they aren't changing anything, but they do give a good explanation in the web.config file comments. " <!-- Yes, we are overriding .aspx - don't delete this! We are using .aspx since we know it is already bound to ASP.NET. In future we might use a different extension so that people can add their own ASP.NET pages if they want to, but we should make sure in that case to change how URLs are created -->" The discussion for this error is here http://forums.asp.net/t/1220987.aspx

In work the other day we started to debate the best way to "mock" a web service. The two ideas we boiled down to were either to create another web service exactly the same as the original, except have it consume the data from a text file or to have a flag in the existing data layer, trigger the code to read data from a text file locally, thus removing an additional dependency created by making a second web service What I came up with was this. We needed to decide what we were testing? Are we testing 1. To make sure the code can deal with the data correctly? Or 2. Are we testing to see if our code can connect to the web service? Since we would like to specify our own data, I believe this makes it pretty clear. We are testing to make sure we can deal with the data correctly. The first argument stated, that by making a new web service, in which we specify the data, you are not only testing that the web service can connect but it can consume it correctly. I believe this is where their thinking was different than mine. In most web best practices you create a “N-Tier” architecture. Meaning that one of the tiers is dedicated to connecting to the database and returning a data-dump. The reason this is done is because most programming architects like to believe they can sub in one data consumption tier with another, example, getting data from Oracle as opposed to DB2 or getting data from a web service as opposed to a MSSQL database, without causing any issues in the logic of the code. Thus, how the data is retrieve is of little importance, but how it’s processed is where the real brains are and have high importance. All of this being the point of separating this data layer tier from the business logic tier. Now understanding this aspect you also have to think in the mind of a tester. Testers want to remove as many external dependencies on the code as possible. Testers don’t care about the connection a web service makes, they only care about the data it returns. Testers want to control that data and put in their own to test for every scenario and they want to do it with as few dependencies as possible. Therefore introducing a new web service that sits on some other server is not favorable. Now in order to test code you have to maintain another server, another web service and worry about any network issues between the tester and that web service. However most would feel best practice would be to inject the data right into the code nearly removing the data layer. This removes numerous external dependencies and makes the code easier to maintain as it gets passed from generation to generation of developer that comes and goes from the company. The next question is, what would be the best way to inject this data? To make the example easy I just added some additional code in the data layer where we consume the web service and made it look at a flag I set in the web.config. If it says true, it hits the web service, if the flag says false it consumes a local text file, the path of which is also specified in the web.config. This is a down and dirty way of doing it. There are more elegant ways such as using “ Constructor Based Dependency Injection,” and using nMock. If you would like more information on the correct way to test a web service this blog post provides some very solid and good examples.
Error Readout:
System.IndexOutOfRangeException:
Fix:
I encountered the above error when I tried to run the query, SELECT MAX(expression ) FROM tables WHERE predicates;
and then loop through the results using a datareader with code like this, while(rdr.Read()) { someLabel.Items.Add(rdr["ColumnName"].ToString()); }
I got the error above, because when you do a "max" sql query it doesn't return any column header. All you need to do is give the sql result set a column header.
SELECT MAX(expression) as "ColumnName" FROM table where predicates; Explanation:
This is another one of my bone head mistakes. It's such a simple little thing I overlook, and gets me so disappointed in myself when I realize I spent time trying to figure this out. It's generally followed by me looking over my shoulder and seeing if any of my peers saw it. I'm mostly blogging this in hopes I won't make a silly mistake like this again .
Why is it always the baby errors that hang me up the most? It can never be something deep in the CLR, or possibly find a mistake in .Net. Nope, noway, not gonna happen .Net is pretty solid...for the most part.
Error Readout:
None, it's not an error silly. The Problem:
When I debug, and look at a string that contains my file path I see 2 backslashs (escape characters) in my string when I only wanted 1. The Solution:It's nothing, don't worry about it, that's just the way Visual Studio "debug" shows your path when you catch it while debugging. When the path is used in the code for the file system there will only be 1 backslash and it will work correctly. This is such a stupid little thing, but for some reason every once in a blue moon, I forget and freak out on why it's doing this, thus wasting a solid five minutes of my life. I put this post up in hopes I will never forget again and that if someone happens to Google this, my post will pop up and help them move on quickly....maybe only wasting 1 to 2 minutes. :)
 It's a good question. There are some types that are not derived from NSObject, these types are called "Primitive Types." Some examples of these types are - int
- bool
- short
- long
- double
- char
Sooooo basically any type that is not derived from the NSObject class is a Primitive type and does not require a "*". Now I bet you are wondering how do I figure out if it's a primitive type or not. - An easy way is to look at the color of the syntax in xCode, is it deep blue or a sky blue? Deep blue = primitive type, but this is not entirely reliable as the standards for coloring syntax can fluctuate or change.

- You can option-click on the object after you have typed it in xCode, click the little book in the upper right hand corner, when the class reference viewer comes up, look and see if it inherits from NSObject. If it doesn't it's Primitive and you don't need a "*".

 Note:There are some alternatives to using the primitive type int, such as the reference type NSInteger, which has
some nice baked in functionality of distinguishing between 32 bit and 64
bit, but not all primitive types have an alternative reference type in Objective C. Just for fun:In .Net they have primitive types too(I believe they call them value types), kinda. The compiler recognizes traditional primitive types and therefore lets you use the syntax int i = 5;But despite the compiler letting you do this, this type still maps back to System.Int32. All things in .Net are mapped back to System.Object. Everything is a reference type, but .Net lets you keep the traditional syntax instead of writing: System.Int32 i = new System.Int32(5);UPDATE: Enumerations types also do not use a * (star) and they have the sky blue coloration that may make you think you need a *.
What a wild month! London, Paris (loved Paris), and Barcelona, followed up with a gig in Philly working for the second biggest software developer in the world on their up front website, SAP.com. Before I dive into the limited aspects I can speak about SAP.com's technology I would like to point out the facet of SAP that has had, and will have, a lasting effect on me, the cafeteria. These people (SAP) treat their people good! Made to order sushi, made to order Thai, a Philly cheese steak that will challenge South Philly's finest and a Starbucks that feels like it was made just for me, all this within a short walk from my desk. Really, next to the BMW the Germans know how to do it.
Lets dive into my first day. I was sitting at my desk, after enjoying my oh-so-delicious lunch of Alaskan Cod; I hear this loud noise getting louder. Turns out it was a helicopter flying in with the American Co-CEO. As he gets out, much like a scene you might expect to see from Iron Man, he has a dream effect on me. He waves at the people there to greet him and follows up with a mock gun shot (I can only hope he made the clicking sound that goes with the mock gun shot) at one of the security guards as he steps into the Escalade, in my mind I say YES, awesome! I know right then and there I'm going to love it for my limited time here.
I digress lets talk about a website that needs to address more nations than a senator trying to get votes in NYC. In short, because this is all I will say and feel comfortable, they follow a Model View Presenter (MVP) development process in making their site. SAP's site addresses content based on what nation/region you are coming from all while maintaining a similar look and feel for every end user. Think localization is easy with .Net...not on this scale boys and girls! Now add a level complexity comprising of several teams in more countries than you can count on one hand, developing for this one site. To create a level of consistency across so many sites a template format was built and an engine on top of the .Net engine to address what should be displayed....this is all I will give up, but I can say it's fun and challenging.
The Problem:
Getting a Powershell script to run a batch script.
The Solution:
powershell.exe -noexit d:\<path to my batch script>\Reporting_Code_Load.bat
Explanation:
All you need to do is add the line above as is to your Powershell script. The "-noexit" tells the command prompt to stay open, simply remove it if you don't want the command prompt to open.
 If Scott Hanselman lives and die's by unit tests, why don't we all just fall in line? It seems the nerd community, has an uncanny ability to adopt silly things quickly. Things like xkcd.com or the idea of ninja's. I have yet to laugh at one xkcd or understand how ninja's are relative in any shape or form, because of this I felt I needed to read up on unit tests, specifically for C#, to find out if it's just hype or this is something development shops with a strong QA team really need to look at.
I read two books that covered the topic of unit testing. The first book was Foundations of Programming (recommended by Scottie H. himself and is free) and the second is Pragmatic Unit Testing In C# with NUnit. Both of them start off with the same old song and dance on how you might have up front costs of introducing unit tests to your code, but the stability these tests provide over the duration of your codes lifetime will cause such dramatic cost savings for the company, it would be foolish not to explore the idea. What a compelling sales pitch, a pitch salesmen, for just about any technology, have used since the beginning of technology in businesses. I'll cut all the used car salesman tactics out and state the most intriguing argument to unit test. It increases code stability and it's easy.
The next question I asked myself: What do I exactly test in the code-base I am working on? In Pragmatic Unit Testing (PUT) they give us an acronym to use in order to answer this question. BICEP.
BICEP, breaks down as such.
Boundary Tests
Inversion Tests
Cross Check Tests
Error Tests
Performance Tests
These are the 5 major aspects one should test, according to PUT and it provides unit testers with a place to start. The next major topic in discussing how to test code is decoupling one piece of code to another. Does your code talk to a middleware? How do you test if middleware is not done creating your service to consume or if middleware is down? In steps NUnit Mocks, NMock2, and DotNetMock. These 3 mock frameworks provide the developer with the ability to feed your tests predefined values, values decided by you. Without going into how to use these mock frameworks, I believe that outside of a few isolated situations they should not be used. The entire purpose of testing your code is to test that you are getting information back that fits the criteria you are looking for. If this information, that is beyond your control, changes on whatever level for whatever reason, you as a developer need to know. Putting in mock objects hides this.
Since I work for a web shop, the topic of web UI unit tests interested me. PUT recommend using Selenium. This makes sense because it still uses the nunit style of testing keeping all your tests to one testing style. Selenium seems a bit cumbersome in comparison to WaitN or iMacro, but I feel keeping all your testing in the same style outweighs the cons of not using Selenium. The more desperate testing sources you introduce, the more confusing it is for an outsider to step in and see the whole picture when learning the code, especially when it's not contained in a single solution.
Finally, I recommend reading both of the books mentioned, but lets be honest most of us care so little about unit testing we'll be lucky to read all of 1 of these books let alone all of both. If this is the case I recommend PUT, while the first few chapters read like the high school teacher striving to gain his students social acceptance, it's an easy read and you can jump into the book at nearly any chapter and get the exact information you are looking for on unit testing. This is something I wish all programming books could achieve.
Error Readout:Exception: System.Web.HttpException Message:
Authentication of viewstate failed. 1) If this is a cluster, edit
configuration so all servers use the same
validationKey and validation algorithm. AutoGenerate cannot be used in
a cluster. 2) Viewstate can only be posted back to the same page. 3)
The viewstate for this page might be corrupted. Source: System.Web at System.Web.UI.LosFormatter.Deserialize(String input) at System.Web.UI.Page.LoadPageStateFromPersistenceMedium()Fix:
I encountered the above error the other day. Since the server wasn't on
a web farm I was a little confused. The fix I ended up using was
updating the web.config key to
requiressl=trueExplanation: The next
thing I asked myself was how can that key affect the viewstate. With
some serious investigation into viewstate and best practices I finally
made the link of how our applications viewstate is tied to session
state which is tied to SSL
when the session cookies are encrypted manually, a step (encrypting our own
session cookies manually) we did because we are still running asp.net 1.1. How to manually encrypt the sessionid in a cookie Response.Cookies["ASP.NET_SessionId"].SecureLets
dive right into how session state and viewstate work to get a better
understanding of the solution. ASP.NET session state lets you associate
a server-side string or object
dictionary containing state data with a particular HTTP client session.
A session is defined as a series of requests issued by the same client
within a certain period of time, and is managed by associating a
session ID with each unique client. The ID is supplied by the client on
each request, either in a cookie or as a special fragment of the
request URL. [ http://msdn.microsoft.com/en-us/magazine/cc163730.aspx] In
.net 1.1 there is a property called "ViewStateUserKey" located in the
viewstate, this key adds user-specific information to the view state.
When the request is
processed, ASP.NET extracts the key from the view state and compares it
against the ViewStateUserKey
of the running page. If the two match, the request is considered
legitimate; otherwise an exception is thrown. In our application we use
the Session.SessionID to set the property. This is where my problem starts. When
a user fills out a form utilizing viewstate to create an account to
login to our system the user establishes a viewstate in their asp.net
page. In order to make the view state slightly more secure we give the
viewstateuserkey
the same value as the session ID. The session ID is a much better fit
because a session ID is unpredictable, times out, and varies on a
per-user basis [ http://msdn.microsoft.com/en-us/library/ms972969.aspx] Once the user has completely filled out the form, we authenticate them. This is where my error occurs [See beginning of post]. The
error is caused because the session id is now encrypted. It's encrypted
because our security team said, all information stored in cookies is to
be secured. Our team consequently set up a flag in the global.asax file
that states if this flag is set to true it should grab the session id
out of each cookie and encrypt it. The reason we did this by hand
is because asp.net 1.1 does not offer secure cookies with one easy key
change in the web.config [NOTE: In asp.net 2.0 all you have to do is have the requiressl=true and you are done]. Now understanding that our session ID is tied to our viewstateuserkey you can understand the viewstateuserkey
is now invalid because the session ID is a different value, simply
because it's encrypted and the server does not know to decrypt it.
[ NOTE: The session ID may still be the same value, it's just
encrypted.] Now asp.net states the viewstateuserkey is invalid and pumps out the error you have seen above. To
fix this I simply change requiressl=true in the web.config. How does
requrie ssl affect an encrypted session id within a cookie that I set
to encrypt? Well, when requiressl
is not on but you are sending the server a secure cookie value, which
we did since we created our own secure cookies in asp.net 1.1 the
server doesn't know to decrypt the cookie because requiressl is not turned
on [ apparently you have to send secure cookies over ssl in asp.net 1.1 and possibly other run times, I didn't know this] which in turn invalidates the viewstateuserkey because the viewstateuserkey uses the session ID which is encrypted in the secure cookie. What
made
this confusing for me is the first part of the form worked without
a hitch. It's when the user authenticates when the error arose. The
reason for this being that the requiressl key is not applicable until
authentication happens. If you'll notice the requiressl key is nested
in the authentication element in the web.config file. Additionally we
don't encrypt the cookie until the user is authenticated. Sooo, the
first few postbacks for our page were just collecting information. It
wasn't until we authenticated the user to our system that requiressl
actually cared if we had secure cookies or not. OverviewViewstateuserkey is set to the session ID. Session ID is encrypted and the updated value is set to the viewstateuserkey requressl
being turned on tells the server to decrypt session id in which case
allows the viewstateuserkey to remain valid with the server.
Jumping right in. The instructions on the dasBlog website of how to install dasBlog on a shared hosting environment are close to zero. The discussion boards offer some insight but in order to get some real feedback you had to post the question, wait and hope they reply soon...if ever.
I will start by showing you the painful way of installing dasBlog on a shared hosting environment and end with showing you the painless way on Godaddy.
Painful starts Below:
- Getting the Code and Getting it to Your Hosting Provider (Godaddy)
Get the code from dasBlog. Download the "web files" unless you want to tinker with the source, a topic I don't cover.
Unzip the code and pull out the "dasblogce" folder. I renamed this folder to "blog." Next I uploaded the folder to my hosting service at Godaddy
Edit the web.config and siteSecurity.config according to the instructions on the website. You will also need to change the permissions on three folders logs, content, siteconfig to have read/write access.
I will discuss the web.config edits a little because it seems there is a bit of ambiguity on the web with how the trust should be set up.
The out of the box setup of the web.config trust elements:
<!-- <trust level="Medium" originUrl=".*" /> -->
<trust level="Full" originUrl="" />
I simply removed <trust level="Full" originUrl="" /> so all I had was the commented out <!-- <trust level="Medium" originUrl=".*" /> --> element. I have heard some talk to just remove <!-- <trust level="Medium" originUrl=".*" /> --> all together and others saying if you un-comment the element the blog should work. For Godaddy removing the one line and commenting out the other is what worked for me. I always like to leave configuration setting in the file and just comment them out. I will forget about them if I don't....I blame college.
- Adding Virtual Directories and Changing Settings
This is the part which slowed me down. You will need to not only create a virtual directory the same name as the folder that holds the content for your blog, in this example that directory is named "blog", but you will also have to create 3 sub virtual directories under the "blog" virtual directory on Godaddy called "logs," "content," and "siteconfig." Notice the virtual directories are the same name as the folders within the "blog" folder.
Next, you will need to change the settings on all four virtual directory folders to have "anonymous access" and "application root." Finally you will need to change IIS7 from integrated mode to classic mode. (Update: i've been told that if you use the web.config file that is meant for IIS7 integrated you will not have to make this change. For right now the standard package with dasblog is the web.config which requires you to use classic mode).
Once you have followed these steps and followed the steps provided by dasBlog you should be good to go on installing dasBlog on a hosting provider the hard way.
Some of the problems I ran into.
- The first error I was recived was a "HTTP Error 500 - Internal server
error." This error really tells you nothing and was quite frustrating. I eventually fixed the error by switching IIS7 to classic mode on godaddy.
- The second error I encountered was "System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission," This was due to the fact I did not have the 3 virtual directories set up under my "blog" virtual directory in IIS7.
Painless way
- Click "Your Applications" from the home screen of your "Hosting Control Center"
- Select "blogs" from the left hand menu
- Select "dasBlog" from the list of blogs
- Select "Install Now"
If by chance Godaddy states your hosting plan is not supported for this product. You have to have .net and IIS. If you have IIS7 make sure you have it on classic mode. Without classic mode, .net, and IIS, Godaddy tells you your hosting plan is not compatible.
|