Wednesday, 31 October 2007

EPiServer System.Security.SecurityException

On application start up you get : Server Error in '/' Application.. All subsequent requests are fine until the app is restarted. The actual error details : System.Security.SecurityException: Requested registry access is not allowed After browsing the forums, it seems to be a problem when you don't install episerver in the usual manner or it was installed without admin priviledges. A quick way to solve the problem is to create a quick console app with the following code:

static void Main(string[] args)
{
   System.Diagnostics.EventLog _eventLog = new System.Diagnostics.EventLog("Application", ".", "EPiServer Scheduler");
            
   _eventLog.WriteEntry( "Installed OK");
   _eventLog.Dispose();
}
Just run once with admin user and that should be it. To check it ran OK, look in event viewer > application and you should see a message there.


Thursday, 18 October 2007

Checking an assembly is strong named

A strong named assembly's identity consists of a simple text name, version number, and culture information (optional) - plus a public key and a digital signature.

  • Strong names guarantee name uniqueness by relying on unique key pairs
  • Strong names protect the version lineage of an assembly. A strong name can ensure that no one can produce a subsequent version of your assembly.
  • Strong names provide a strong integrity check. Passing the .NET Framework security checks guarantees that the contents of the assembly have not been changed since it was built.

If you want to add an assembly to the GAC but aren't sure if it is strong named (maybe because it is a third party library) - You can ensure that an assembly is globally unique quite easily:

1. Use the strong name tool which is part of the .Net framework tools in the .Net SDK.

sn -v assembly
2. Even easier - Using explorer, click and drag assembly into \windows\assembly directory. If you don't get a descriptive error message then the assembly was strong named and is now gac'd :)


Friday, 12 October 2007

Visual Studio Error List (HTML Errors)

Nothing annoys me more on a Friday afternoon than the Visual Studio Error List rearring its ugly head and popping up with errors (often irrelevant ones) about the HTML markup.

So after playing about with settings and poking around the interweb I found you can either just close all the HTML (or aspx) files you are working on (as it only critises open document's markup) or you can tell Visual Studio to ignore the errors by unchecking:

Tools > Options > Text Editor > HTML > Validation > Show errors

Please, no comments about using the correct validation target, actually fixing the errors or conforming to how Visual Studio wants me to do everything - it's my party and I'll do what I want :P


Wednesday, 10 October 2007

EPiServer Friendly URLS

When integrating our existing Esendex site with EPiServer and deploying onto different web servers we had some issues with friendly URLs. For friendly URLs to work when putting the web site on your different servers you need to ensure the following:
  • Friendly URL option is enabled in your site config
    <add key="EPfEnableFriendlyUrl" value="true"/>
  • The IIS custom 404 error page needs to point to the site URL /Util/Notfound.aspx. EPiServer then checks if the URL requested exists as a friendly URL, and displays the page if it does.
  • The friendly URL httpmodule in the web.config file also needs to be declared.
    <add name="FriendlyUrl" type="EPiServer.Util.FriendlyUrlModule, EPiServer"/>
One problem with this is that if the page is not found, the built-in error page is shown. EPiCode, a EPiServer research project has a module BVNetwork.404Handler that can help with this and also provide redirection functionality too - something we found very useful. Features at a glance:
  • Custom FileNotFound page to replace the built-in error page
  • A powerful CustomRedirects module thats extends the built-in ShortCurUrl function
  • An admin plugin that shows all the CustomRedirects defined
  • FallBack url handling that allows all 404 requests to be redirected to a back-end server only if the url exists on that server

EPiServer Logging & Tail

Any decent developer will know the importance of logging on development machines and in a live environment, so it is worth spending the time setting it up correctly. To get logging initally is easy in EPiServer. just create file in the EPiServer web site directory called EPiServerLog.config and add the following to it to log everything to a file:
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="d:\\logs\\Error-log.txt" />
    <appendToFile value="true" />
    <rollingStyle value="Date" />
    <layout type="log4net.Layout.PatternLayout">
      <param name="ConversionPattern" value="%d\t%X{siteid}\t%m%n" />
    </layout>
  </appender>
  <root>
    <level value="ALL" />
    <appender-ref ref="FileAppender" />
  </root>
</log4net>
EPiServer provide a useful article 'Logging in EPiServer' and you can also get more indepth info on log4net and logging to other mediums (such as email) on the log4net site.

Watching log files

If you have nothing better to do than watching log files then Tail for Win32 is perfect for the job. Tail for Win32 is used to monitor changes to files; displaying the changed lines in realtime. This makes Tail ideal for watching log files - and it's free too!