ASP.NET

You are currently browsing articles tagged ASP.NET.

Profile Data in EPiServer

To store settings for the current user, use the built-in Profile support in ASP.NET.

EPiServer is using this for its own need to store information on a per user basis. (The built-in values EPiServer needs are accessible through the class EPiServerProfile that is a subclass of the ASP.NET class ProfileBase).

You can get access to the current users EPiServer’s Profile instance accessing the static property Current on the EPiServerProfile class. There is also a default indexer property inherited from ASP.NET’s ProfileBase class that you can use for you own values.

EPiServer.Personalization.EPiServerProfile.Current["MySetting"] = "Test123";
			

For performance reasons use only string, int, DateTime and avoid objects that must be serialized. There is also support for handling anonymous users (not logged in) if needed.

Read more: http://msdn2.microsoft.com/en-us/library/at64shx3.aspx

Update: Read more about changes to Profile information in SP1 for EPiServer CMS 5 R1.

Tags: , ,

The error message “Generation of designer file failed: Unknown server tag ‘EPiServer:Property’” in Visual Studio can really drive me mad.

Today it happened again. I noticed that I could not recompile my application because the new textbox I added to my ASPX-file did not appear as a member in the corsponding designer.cs-file.

First, I double check that I installed SP1 for Visual Studio 2005 so I have the latest version of Web Application Projects.

The Usual Trick

When this happens it is in most cases an indication of a syntax error in the ASPX-file. In many cases you get so many strange errors and warnings in Visual Studio’s Error List so you do not understand what is wrong. A quick way to get a good error message and be certain that the designer.cs-file is in sync is to first delete it and then regenerating it by right-clicking the ASPX-file in the Solution Explorer and selecting “Convert to Web Application”.

This works in most cases. Either you will get an error you will understand how to fix or it just regenerates the designer.cs-file for you.

Permanent Frustration

Sometimes you will fail to generate the file and nothing you do seem to help. Everything is in order. No syntax errors in the ASPX-file. It just refuses to regenerate the designer file because it cannot find component X.

Obviously I’m not alone getting this problem. I’m not sure why it stops working but I guess part of the problem is related to the ASPX-file must be parsed first and something is wrong with the environment.

Tim McBride on the ASP.NET team hints how to get more information by turning on debugging for Web Application Projects.

REGEDIT4
[HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio8.0WebApplicationProjectsDebug]
"LogFile"="C:logfile.txt"
"Enabled"=dword:00000001"
LogFieldGeneratorFailures"=dword:00000001

And with a call stack we have more information where it goes wrong:

System.Web.HttpParseException: Unknown server tag 'EPiServer:Property'.
   at System.Web.UI.TemplateParser.ProcessError(String message)
   at System.Web.UI.TemplateParser.ProcessBeginTag(Match match, String inputText)
   at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)
   --- End of inner exception stack trace ---
   at System.Web.UI.TemplateParser.ProcessException(Exception ex)
   at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)
   at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)
   --- End of inner exception stack trace ---
   at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)
   at System.Web.UI.TemplateParser.ParseInternal()
   at System.Web.UI.TemplateParser.Parse()
   at System.Web.UI.DesignTimeTemplateParser.ParseTemplate(DesignTimeParseData data)
   at Microsoft.VisualStudio.Web.Application.Parser.Parse()
   at Microsoft.VisualStudio.Web.Application.Generator.UpdateDesignerClass(String document, String codeBehind, String codeBehindFile, String[] publicFields, UDC_Flags flags)

ProcessBeginTag cannot map a tag to a control. The tag EPiServer:Property control is not registered on the page but in the <system.web><pages><controls> section in web.config. This indicates that something fails either in TemplateParse.PrepareParse when trying to get hold of the RuntimeConfig or in Microsoft.VisualStudio.Web.Application.Parser.ParseConfig when it tries to get to web.config through the designer host.

Adding a Register directive manually to the Page will remove the first error and reveal another.

System.Web.HttpParseException: The expression prefix 'Resources' was not recognized.  Please correct the prefix or register the prefix in the <expressionBuilders> section of configuration.
   at System.Web.Compilation.ExpressionBuilder.GetExpressionBuilder(String expressionPrefix, VirtualPath virtualPath, IDesignerHost host)
   at System.Web.UI.ControlBuilder.AddBoundProperty(String filter, String name, String expressionPrefix, String expression, ExpressionBuilder expressionBuilder, Object parsedExpressionData, Boolean generated, String fieldName, String formatString, Boolean twoWayBound)
   at System.Web.UI.ControlBuilder.PreprocessAttribute(String filter, String attribname, String attribvalue, Boolean mainDirectiveMode)
   at System.Web.UI.ControlBuilder.PreprocessAttributes(ParsedAttributeCollection attribs)
   at System.Web.UI.ControlBuilder.Init(TemplateParser parser, ControlBuilder parentBuilder, Type type, String tagName, String id, IDictionary attribs)
   at System.Web.UI.ControlBuilder.CreateChildBuilder(String filter, String tagName, IDictionary attribs, TemplateParser parser, ControlBuilder parentBuilder, String id, Int32 line, VirtualPath virtualPath, Type& childType, Boolean defaultProperty)
   at System.Web.UI.TemplateParser.ProcessBeginTag(Match match, String inputText)
   at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)

The code in GetExpressionBuilder gives the same indication and strengthens my suspicion that the parser fails to get hold of any configuration at all since the <expressionBuilders> tag is in the global web.config.

I’m too tired to continue the hunt for the real reason tonight but I did test one final thing:

  1. I shut down the IIS service and close Visual Studio.
  2. And then do I delete all files under “Temporary ASP.NET Files”.
  3. I restart Visual Studio and re-open the Project.
  4. I change Project Settings to use Visual Studio Development Server instead of IIS.
  5. Finally do I click “Convert to Web Application” and this time it generates without errors…

Why? Maybe you know… Please, leave a comment if you have any clues!

Tags: , ,

UPDATE: Solution to WebResource.axd exception

I have tried to figure out why a customer get a strange error message on their ASP.NET web site that stops the whole site from working until you restart the whole IIS.

The exception “The WebResource.axd handler must be registered in the configuration to process this request” occurred quite randomly at first sight. After some investigations I found that the site usually stopped working if you called some of the pages immediately after a restart of the web application. This happens for example when you change in web.config but an unload of your AppDomain can be triggered by other mechanisms, too.

I found no clues to the cause when I searched on the error message, only a lot of question and other desperate people.

Looking closer at the call stack and browsning around with Roeders Reflector I found that the cause of our problem with WebResource.axd is in the method EnsureHandlerExistenceChecked in the class System.Web.Handlers.AssemblyResourceLoader:

EnsureHandlerExistenceChecked()

As you can see in the code above, if the test fails once it will never re-test since handlerExistenceChecked is true and the site will stop working forever.

This check is called for several reasons. One of them is because components like the RequiredFieldValidator uses the ClientScriptManager to insert links on the page to JavaScript that is embedded inside a resource in an assembly somewhere. To make the resource available from the browser the generated link contains a reference WebResource.axd that is registered as a HttpHandler in machine.config redirecting calls with that filename to the AssemblyResourceLoader class.

The only way to recover from the error I have found is to stop the site, run iisreset /restart and wait for a while before you start the site again.

I have not manage to find the exact reason for why the test fails initially. I have some theories but they are hard to validate since used classes and methods are private or internal. One guess is that FindMapping returns null because the HttpHandler collection has not yet been loaded. Another guess is that HttpHandlerAction has not been correctly initialized so TypeInternal is null. It could even be possible that there is a problem with the type system (because ASP.NET applications unloads the AppDomain, generat assemblies dynamically and loads them, etc) so you actually have two instances of the same underlying system type making the Equal operator give an incorrect result.

It really does not matter why it does not work since we can not patch Microsoft’s framework ourself or wait for a hot fix. If anyone else has some clues or have done some research on this problem, please let me know!

My workaround to recover from the error is to use reflection to clear one of the private static flags so it re-runs the test. (Use of reflection like the requires that your application does not run with a low trust level so it might not work everywhere.) Since it is expensive to use reflection I only run the check in the Error event handler in my Application object.

Source code for workaround

Any feedback is appreciated.

Download example code here.

Tags: , ,

Newer entries »