Wednesday, March 28, 2012

AJAX Beta 2 web.config

Is there any documentation describing the sections needed in the web.config file to implement asp.net ajax into a site? I have installed it and am using it happily but I want an explanation of each element that is in that web.config template and why it is required, what I dont know worries me!

Thanks!

This is an excellent question.

I am going to give an explaination off my head:

First off:DOCS.

<configSections>
<sectionGroup name="microsoft.web" type="Microsoft.Web.Configuration.MicrosoftWebSectionGroup, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="Microsoft.Web.Configuration.ScriptingSectionGroup, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="webServices" type="Microsoft.Web.Configuration.ScriptingWebServicesSectionGroup, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="Microsoft.Web.Configuration.ScriptingJsonSerializationSection, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
<section name="profileService" type="Microsoft.Web.Configuration.ScriptingProfileServiceSection, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
<section name="authenticationService" type="Microsoft.Web.Configuration.ScriptingAuthenticationServiceSection, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>

^^ This just defines how the config sections are laid out in the following markup in the config file.

The important stuff we should concentrate about is the inner section webServices and the sections below that (the outer ones just defines the layout of the config kinda (dumb sections that does nothing but define themselves ))

--

jsonSerialization,profileService,authenticationService are all on the same level. These actually have usable elements you can configure.

You should read the docs on what the classes are (they are vague though) but web.config found in C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025

has an actual section + comments:

<microsoft.web>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<!--
<jsonSerialization maxJsonLength="500">
<converters>
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
</converters>
</jsonSerialization>
-->
<!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "true|false"/>
--
<!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
and modified in Atlas applications, you need to add each property name to the setProperties and
getProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
</webServices>
</scripting>
</microsoft.web>

jsonSerialization section can have defined custom converters, if you have an object that you want to provice your own notation for, do it here.

I don't know too much about the other stuff, but it seems pretty straight forward...

--

Moving on:

<pages>
<controls>
<add tagPrefix="asp" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagPrefix="asp" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
<tagMapping>
<add tagType="System.Web.UI.WebControls.CompareValidator" mappedTagType="Microsoft.Web.UI.Compatibility.CompareValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.CustomValidator" mappedTagType="Microsoft.Web.UI.Compatibility.CustomValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.RangeValidator" mappedTagType="Microsoft.Web.UI.Compatibility.RangeValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.RegularExpressionValidator" mappedTagType="Microsoft.Web.UI.Compatibility.RegularExpressionValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
<add tagType="System.Web.UI.WebControls.RequiredFieldValidator" mappedTagType="Microsoft.Web.UI.Compatibility.RequiredFieldValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.ValidationSummary" mappedTagType="Microsoft.Web.UI.Compatibility.ValidationSummary, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</tagMapping>
</pages>

^^ <controls> will map the prefix 'asp' to the AJAX controls (mainly updatepanel, scriptmanager, updateprogress etc) GLOBALLY across the whole site, so you don't have to provide it in the directive on each page ( This is VERY useful to use on your own controls, this is a true blessing!)

The <tagmapping> will replace the stock ASP.NET validator controls with the ASP.NET AJAX ones. This is to override the original stock validator controls to make them work properly.

--

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>
</httpHandlers>

First one replaces all requests (post, get (etc?)) to asmx files to the ScriptHandlerFactory. This factory is undocumented, but I can tell that it switches between 2 handler factories (it wraps them on a condition)

First one of them is RestHandlerFactory (undocumented), this will get chosen if it is a rest (if pathinfo starts with "/js").

If not, it will choose the stockWebServiceHandlerFactory class.

ScriptResource,axd axd is AJAX' own handler for processing script resources. This seems to be well documented (compared to other ajax stuffStick out tongue).

--

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="Microsoft.Web.UI.ScriptModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-ISAPI-2.0"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" />
</handlers>
</system.webServer>


^^ This is the section for IIS 7.0 (or any web server that reads this section. maybe cassini?).

This will remove WebServiceHandlerFactory-ISAPI-2.0 and inject the script handlers / modules.

Some is documented, some is not. But this is probably to make the script stuff work, to use regular English. Big Smile

This is only from the top of my head. Some are facts, some are just my assumptions!

Anyway, hope it helps, and if it really is an answer to you,mark it as answer, thanks!


hello.

the final section will only be used by IIS 7 (and i do think that the web.config that comes with ajax beta 2 is not complete).

btw,?EmilChristopherMelar is there any contest with cool prizes or something like that? why are you asking for your answer to be marked at the end ofyour posts?
Because then you can see that a thread is really answered, so people can see that it doesn't need any more attention, duh.
hello.

well, didn't really know that there are people on this forum trying to find threads that need attention...

It's not about that. It's about aknowledging the answer so I don't have to follow it up anymore.

It is common sense and usage of news / forums to give a response on a successful / unsuccessful answer.

And what's the point of answering if it's not read / acknowledged? What would the motivation for helping be if your answer is blatantly ignored?

No comments:

Post a Comment