Friday, April 13, 2007

Aspnet_regiis -c

Have you ever seen the following ASP.NET client-side error?

It is most common in production environments that host multiple IIS sites and applications.

ASPNET_CLIENT
If your ASP.NET 1.1 application implements dynamic validation controls, it is dependent on the existence of an /aspnet_client directory. This directory must be a child folder of the site's home directory. Here is a sample scenario:

  1. We have a site on a production server, abc.com.
  2. abc.com serves web pages residing on the server's file system at c:\abc. This is the home directory.
  3. I have an asp.net application hosted at abc.com/newapp
  4. My application serves web forms residing at c:\myapps\newapp

My "newapp", which uses validation controls, depends on the existence of c:\abc\aspnet_client. If the ABC site is managed by someone else (some other department in your company), you may not be comfortable with this dependency! E.G, what if someone managing the site content in abc.com ignorantly deletes /aspnet_client, fearing it to be malicious?

Furthermore, while /aspnet_client is handled for you in VS.NET, it is not automatically created for new sites added to IIS. So if you are launching a new site and a new ASP.NET 1.1 application, you will have to include a step to build the /aspnet_client directory. This step is:

Aspnet_regiis -c

This creates the /asnet_client folder under EVERY website node in IIS. So you are safe until the next time some fool deletes it or renames it on the shared server.

Alternative to /aspnet_client

You can remove the dependency of your app on the parent root by overriding the location of the ASP.NET client scripts in web.config. First, copy the scripts folder from the parent root (e.g. c:\abc\aspnet_client) to the application root (e.g. c:\myapps\newapp\aspnet_client). For clarity, rename the folder from aspnet_client to aspnet_override. Then, set the override in web.config:

    <system.web>

    <!-- WEB CONTROLS
    This section is settings to enable client-side validation code.
    -->
    <webControls clientScriptsLocation="aspnet_override\\"/>
    ...

Now you manage the client scripts yourself!

3 comments:

price per head said...

Great site!!! this information really helped me

pay per head said...

Thanks a lot for the posted review, it's really interesting to read

pay per head said...

Thanks a lot for the posted review, it's really interesting to read