Scott Hanselman

Important Note: Replacing the default ViewState Persistance Behavior

June 03, 2004 Comment on this post [2] Posted in ASP.NET | ViewState | Bugs
Sponsored By

Scott Mitchell also has a good article on ViewState up on MSDN.

I talked to him before I blogged this and he agreed it was worth mentioning.  I blogged about this issue before

In his article Scott shows how one can override SavePageStateToPersistenceMedium and LoadPageStateFromPersistenceMedium to put ViewState somewhere else.  A few snippets are below:

   protected override void
     SavePageStateToPersistenceMedium(object viewState)
   {
      LosFormatter los = new LosFormatter();
      StringWriter writer = new StringWriter();
      los.Serialize(writer, viewState);
      StreamWriter sw = File.CreateText(ViewStateFilePath);
      <snip> 
  
}
   public string ViewStateFilePath
   {
      get
      {
         string folderName =
           Path.Combine(Request.PhysicalApplicationPath,
           "PersistedViewState");
         string fileName = Session.SessionID + "-" +
           Path.GetFileNameWithoutExtension(Request.Path).Replace("/",
           "-") + ".vs";
         return Path.Combine(folderName, fileName);
      }
   }

In this example code (that you shouldn't copy/paste into production :) ) you see that he's redirecting ViewState to serialize to a file with a name like ASPNET23234094498230948320492834-myfile-default.aspx.vs. 

The problem (an edge case certainly, but still a problem) with this approach is that it doesn't support multiple browser windows on the same machine hitting the same page

Remember where ViewState is stored by default - it's stored with the requested page instance (in the HTML).  Using the ASP.NET SessionID in the filename scopes the state to the user and adding the file name reduces scope to the Page Declaration, but not the actual request instance.

Fortunately, Scott Mitchell wisely aludes to a solution in his article when he says:

Note   One workaround would be to use a globally unique identifier (GUID) as the file name for the persisted view state, saving this GUID in a hidden form field on the ASP.NET Web page. This approach, unfortunately, would take quite a bit more effort than using the SessionID / URL scheme, since it involves injecting a hidden form field into the Web Form. For that reason, I'll stick to illustrating the simpler approach for this article.

I spoke with Scott, and he agreed that for this solution to be more ideal one would have to implement a solution using a GUID.  Otherwise, be aware that you may run into flakey concurrence bugs where pages step on each other's ViewState.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Today's Errors: "Unexpected Error 0x8ffe2740 Occurred" Error Message When You Try to Start a Web Site and "Not Running ASP.NET Version 1.1" Error Message When You Try to Open an ASP.NET Web Application Project in Visual Studio .NET 2003

June 03, 2004 Comment on this post [6] Posted in ASP.NET | Web Services
Sponsored By

Good times, good times.  Twenty minutes before a demo to a bank, I get this:

"Not Running ASP.NET Version 1.1" Error Message When You Try to Open an ASP.NET Web Application Project in Visual Studio .NET 2003

Now, of course, I know darn well I'm only running .NET 1.1 on this box.  Hell if I know what's going on, but I've done the whole ASPNET_REGIIS thing before, so I run aspnet_regiis -ua, then aspnet_regiis -i (I could  have just done -r, probably).

Didn't work. I DO have some funky stuff in my Web.config customerrors section that has a defaultredirect.  Ah! http://support.microsoft.com/?id=825792 says:

"If the defaultRedirect attribute is set to an HTML file or to an ASP file, the request for the Get_aspx_ver.aspx file does not return the ASP.NET version information."

Bingo? No...now I get:

"Unexpected Error 0x8ffe2740 Occurred" Error Message When You Try to Start a Web Site

I see the 0x8ffe2740 and a Stop Sign in IIS's MMC. Turns out another process started up while IIS wasn't running and took over Port 80.  Running TCPView made it clear.

So, 13 minutes spent Googling and Troubleshooting.  Demo looks good and I've got 7 minutes to blog about it.

Would this be a good interview test problem for a potential employee?  Like, literally give them a laptop with this problem and say "fix it."  My CTO could have solved this problem as well in similar time, but I wonder (as I read Google Groups) if there aren't people who would waste days on this kind of problem.  Thoughts?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Section 508 Accessibility and ASP.NET

June 03, 2004 Comment on this post [1] Posted in ASP.NET
Sponsored By

I've be interested in Web Accessibility for a while, and collected a pile of links about it in 2002 for a project.  I even turned off my monitor for a day and ran "Jaws," a screen reader for Windows that blind people use. (Seriously, try this one day - if you ever go blind, at least you'll know how you'll keep your programming job.  It was comforting to know that I could keep my job.)

Scott Mitchell has a great article on accessibilty up on MSDN.  Kudos to Scott for this; there just aren't enough people who realize the need for accessibilty and few people take the time in their projects to make a site truly accessible.  You don't know how many customers you are losing if they can't even get to your site.

It's great to know that ASP.NET 2.0 will generate Section 508 compliant markup by default.  Nice to know there is some commitment.

If you need Section 508 compatibility now, you can patch the ASP.NET 1.1 DataGrid TODAY with the June 2003 Hotfix (Q821156).

Also, be sure to check out Mark's Dive Into Accessibility book, it's an invaluable download. 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Who ever said software development was just another job?

June 03, 2004 Comment on this post [0] Posted in XML
Sponsored By

This was just too good not to share…emphasis is mine.

Via Peter Provost, I came upon Kris Syverstad’s post drawing an analogy between great software developers and great athletes. Kris’s post in two sentences: Great developers and great athletes strive to be the best, and have the talent and drive to become so. The best developers are the ones who seek out help when they need it, and take steps to actively seek out learning opportunities on their own.

I think Kris’s analogy is right on. I found it ironic that Kris very clearly lays out the attitude one needs to excel in this business, and the absolute antithesis of this attitude is displayed in one of his comments. The comment I’m referring to was “[Building your skills on your own] takes time outside of your 40 hour work week and it is unpaid. So, what is the incentive?” 

Hrmm…investing in yourself? Personal pride? The desire to be the best? Loving what you do?  

I’ve had the privilege of working with some really, really great developers. I’ll tell you one thing they all have in common: software isn’t something they just do for 40 hours a week to pay the bills. [Brain.Save()]

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

ComputerZen.com - Episodes you may have missed...

June 02, 2004 Comment on this post [2] Posted in ASP.NET | Web Services | DasBlog | XmlSerializer | Speaking | PDC
Sponsored By

It's the wife's birthday so I shall be out of pocket for the weekend and I may not have time to blog.  But, I realized that I have a whole 2+ years of blogging up here that you may have missed.

Thus, I present "Syndicated ComputerZen in Syndication or Episodes You May Have Missed" for your pleasure. 

  • Bringing data "along for the ride" with CheckBoxes and the ASP.NET DataGrid
    Work WITH the Grid, not against it;  Listen to the Events and Nudge/Influence the Grid; just because code is on CodeProject or in Google Groups doesn't mean the writer knows the DataGrid from his own Ass.
  • ASP.NET: Postbacks for Algernon
    Pretty PostBacks when using RewritePath; Complex Custom Confirmation Dialogs on LinkButtons in DataGrids while STILL maintaining PostBacks (whew!)
  • But what price my soul?  The one where I muse about the potential for going to hell for writing really smelly code.  What to do when you've built a great monument, but there's bird poop at the top that you're responsible for.  Does it take away from the accomplishment?
  • Exporting Tabular Data to Excel from ASP.NET  My #1 most popular post.  Geez...look at the Referral List.  It's worth checking out.  Amazing.
  • XmlSerializer Madness Learning about when the XmlSerializer caches its generated assemblies, and when it doesn't.
  • The Day I Moblogged the PDC Keynote The lengendary post where I blogged the PDC Keynote from the only device with coverage - my BlackBerry.  My left thumb, in particular, has yet to recover.

If you find it useful, I may dig in to the archives again. (This post was brought to you by the upcoming dasBlog MonthView.)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.