Sladescross's Blog

Blogging about Sharepoint related stuff

Ajax Deeper Dive and Partial Page Rendering November 23, 2013

ScriptManager class is the heart of ASP.NET Ajax. Before elaborating more on ScriptManager, note that ScriptManager is class and a control (both) in Ajax.

The ScriptManager class in ASP.NET manages Ajax Script Libraries, partial page rendering functionality and client proxy class generation for web applications and services. By saying client proxy class, this means an instance of the Ajax runtime is created on the browser.

This class is defined in the System.Web.Extensions.dll. You will find this DLL in your system’s Global Assembly Cache at C:\Windows\Assembly (For XP)

The ScriptManager control (that we may drag on a web form) is actually an instance of the ScriptManager class that we put on a web page. The ScriptManager manages all the ASP.NET Ajax controls on a web page. Following tasks are taken care by the ScriptManager class:

Essentially, a true AJAX application uses the XMLHttpRequest object to bypass the browser and establish direct communication with the Web server and any hosted HTTP endpoints. The application is capable of asynchronously retrieving necessary data and independently refreshing blocks of the user interface. Based on this key behavior, a number of AJAX frameworks have been designed that have different doses of syntactic sugar, larger or smaller feature sets, and richer or simpler families of user interface widgets. ASP.NET AJAX is one of these frameworks.

A canonical example to illustrate the power of the AJAX approach is an application that retrieves stock quotes in real time. The non-AJAX Web sites that offer this feature today are using either meta-refresh tags or a plugin-based approach such as Flash, Silverlight™, or ActiveX® controls. Typically, the list of stock values to display is bound to a server-side grid control, and the grid is then refreshed with the rest of the page with the next postback or page request. A page like this can be quickly enhanced with a sprinkle of partial rendering. Let’s see how. The markup in Figure 1 wraps a grid control in an UpdatePanel control that is periodically refreshed by a Timer control.


How would a pure AJAX approach affect the design of a live quote page?

Firstly, the invoked URL is not the page itself. The page invokes an HTTP endpoint backed by a scriptable Web or WCF service. There’s no page lifecycle, no postback events, no view state restoration. As a result, network traffic is significantly reduced.


From an architectural standpoint, you see two neatly separated blocks of code at work—the client-side front end and the server-side back end. The former is powered by JavaScript; the latter is based on managed code.


In partial rendering, there’s no natural separation between the user interface elements (the view) and the core application logic (the model).


Data can be cached on the server, care of the (Web) service front end and implementation. In addition, data can be cached along the way by an HTTP proxy or even by the JavaScript code running in the browser. More importantly, you’re not caching markup; you’ll be caching usable data (objects or JSON strings) that can be checked at any time against runtime conditions.


Unfortunately, there’s no client-side GridView control as there is in the server-based ASP.NET approach. You need a form of client-side data binding, preferably with some templating support. Currently, ASP.NET AJAX is not of much help here. For further explanation on this topic, straight from the Microsoft ASP.NET team, see the sidebar, “Insights: ASP.NET AJAX.”


Let’s start from this last point to explore the ways in which you can build your own small but effective data binding and templating framework. Note that the final output has to be a string of HTML markup. The initial input is a collection of objects with a few public properties. Your job is to build a piece of HTML that fulfills the user’s expectations. Generally, you start by looping over the bound collection and concatenating the template’s text with the value of the object’s properties.

What’s wrong with this approach? Actually, nothing is wrong with this approach. In fact, there’s no radically different approach that I can think of that doesn’t do the exact same thing at some point. This means that you can certainly create a framework that abstracts this basic routine. In the catalog of AJAX patterns (see, the key steps for defining a client-side templating model go under the name Browser-Side Templating pattern (BST).

The markup builder returns an HTML string based on a reference to one or more HTML templates in the page document object model (DOM) and the downloaded data. Finally, the callback injects the string in the page’s DOM.

Now let’s take a look at some code. In this implementation, the heart of BST is in the JavaScript MarkupBuilder class, which accepts up to three HTML templates—header, footer, and item.


What’s the point? Remember that with partial rendering, you can only have one request pending at a time per session—just like in a normal non-AJAX page. Of course, you can have any number of simultaneous calls if you control them directly through XMLHttpRequest. Furthermore, if you make direct service calls, you have no view state around and no worries about keeping it consistent across multiple partial rendering calls (which is the real reason why the partial rendering implementation prevents you from executing concurrent operations).

The HTML Message Pattern

To top off this column, let me just make a quick comment on another pattern that really deserves more attention in a future column—it’s called the HTML Message pattern. The goal of the HTML Message pattern is to have the server generate blocks of HTML markup to be displayed in the browser. As you can see, it falls somewhere between partial rendering and other models for building true AJAX applications.

AJAX Service Layer

I’ll refer to the server-side part of a typical AJAX presentation layer as the AJAX service layer to distinguish it from the service layer that generally represents the point of contact between the presentation and middle tier in a standard multitier architecture. Figure 1 illustrates the model.


The communication between the AJAX service layer and the client front end occurs through HTTP endpoints that are exposed by Windows® Communication Foundation (WCF) services and are invoked by JavaScript proxy classes embedded in client pages.


Partial rendering preserves the view state and server page lifecycle and allows you to declaratively design the user interface using controls and properties.


How would you dynamically create and update a browser user interface based on raw JavaScript data?

Solutions for Now

HTML is used for presentation whereas XML, JSON, and RSS are formats that move server-generated data to the client where it can be manipulated for presentation. In the context of AJAX, this neat model is hindered by the use of the JavaScript language. Once you have downloaded data to the client, you only have JavaScript to build the UI. The BST pattern in the form of custom data binding and template techniques helps you create the UI you need.


Application Load Balancing Addresses May 21, 2012

Filed under: Application Address Refresh Job,Timer,Topology — sladescross @ 9:23 am

The Application Addresses Refresh Job has one specific job to do – keep track of all available and online instances of all service application end-points. This means that whenever a proxy requests an endpoint for a service application it will ask the Topology Service (the Application Discovery and Load Balancer Service) for an endpoint. The Topology Service keeps a list of the endpoints that has been discovered by the Application Addresses Refresh Job and passes on one of these endpoints to the proxy, using the load balancing algorithm, which uses that endpoint to talk to the service application. So far so good…


Sharepoint Excessive Timer CPU February 23, 2010

Filed under: Sharepoint,Timer — sladescross @ 11:04 pm

Switch of logging and check log files for timer errors.


stsadm Delete Configuration Object January 29, 2010

Filed under: deleteconfigurationobject,stsadm,Timer — sladescross @ 12:41 pm

stsadm -help deleteconfigurationobject


Fusion Logging

Filed under: .NET,Fusion,Logging,Timer — sladescross @ 12:34 pm

For BadImageFormatException:
Try running peverify.exe on the file. That will give a more specific description about why it s considered a bad image. Keep in mind that modules built against v2 can not be loaded by a pre-v2 CLR.

For SecurityException:
You need Execute permission for loading any assembly. Also, if a codebase was used to load this file, you would need both FileIOPermission.Read and FileIOPermission.PathDiscovery or else WebPermission to the location (depending on whether this is a local file or a URL). Try caspol.exe to check your managed security settings.

For FileLoadException:

For an “Access is denied” message (for hresult E_ACCESSDENIED, 0×80070005):
Run tlist -m on the file to see if another process has the file locked and without share-read access. If not, check the ACLs for the file and its dependencies (especially if you’re using impersonation).

For a “The located assembly’s manifest definition with name [yourAssembly] does not match the assembly reference” message (for hresult FUSION_E_REF_DEF_MISMATCH, 0×80131040):
The Fusion log will say which part of the assembly reference failed to match what was found. It will be the assembly name, culture, public key (or token) or version (if the found assembly was strongly-named).

For “Unverifiable image [yourAssembly] can not be run” or “Can not run executable [yourAssembly] because it contains relocations” messages (for hresult COR_E_FIXUPSINEXE, 0×80131019):
That image must be run as the process exe or else be compiled as a dll. This is because MC++ has made optimizations for you in your image, based on the assumption that it will be the process exe. If it’s not the process exe, it won t be loaded at the expected location, so the assumed offsets will be incorrect. When the CLR sees such a file loaded as a non-process exe, it will reject the load.



Sharepoint Clear The Timer Service Cache November 23, 2009

Filed under: Cache,Clear Cache,Config DB,Sharepoint,Timer,Timer Cache,Timer Service Cache — sladescross @ 11:27 pm

In Windows Server 2008, the configuration cache is in the following location:


SharePoint Services Timer Service File System Cache

Reseting the file system cache have resolved many issues I had in my SharePoint farm. Microsoft tech support gave me this resolution to fix some issues I had with Usage Analysis. I perform this operation fisrt if I get stuck with any issues related to timer jobs. Good times!

So, how to clear the file system cache?

File system cache should be cleared on all servers in the server farm on which the Windows SharePoint Services Timer service is running. To do this, follow these steps:

1. Stop the Timer service.
To do this, follow these steps:
a. Click Start, point to Administrative Tools, and then click Services.
b. Right-click Windows SharePoint Services Timer, and then click Stop.

2. Delete or move the contents of the following folder:
a. %ALLUSERSPROFILE% \Application Data\Microsoft\SharePoint\Config\GUID
b. Leave the cache.ini alone
c. Delete all other files (all guid.xml) these are all timer job definitions
d. Open cache.ini in notepad and change whatever number you see there to 0

3. Start the Timer service:
To do this, follow these steps:
a. Click Start, point to Administrative Tools, and then click Services.
b. Right-click Windows SharePoint Services Timer, and then click Start.

Note: The file system cache is re-created after you perform this procedure. Make sure that you perform this procedure on all servers in the server farm on which the Timer service is running.

Go back to the %ALLUSERSPROFILE% \Application Data\Microsoft\SharePoint\Config\GUID folder and make sure you see a bunch of xml files.

Open the cache.ini and see if the 0 is replaced by a higher value.

You have just synched all your servers with the same timer job definitions from the config db.

If you only see a single server having issues, only clear the config cache on that server, you do not need to clear the cache on the entire farm. To do a single server, follow the steps below on just the problem server.

To clear the config cache on the farm, follow these steps:

    1. Stop the OWSTIMER service on ALL of the MOSS servers in the farm.
    2. On the Index server, navigate to:

Server 2003 location: Drive:\Documents and Settings\All Users\Application Data\Microsoft\SharePoint\Config\GUID and delete all the XML files from the directory.
Server 2008 location: Drive:\ProgramData\Microsoft\SharePoint\Config\GUID and delete all the XML files from the directory.

  1. Delete all the XML file in the directory. NOTE: ONLY THE XML FILES, NOT THE .INI FILE.
  2. Open the cache.ini with Notepad and reset the number to 1. Save and close the file.
  3. Start the OWSTIMER service on the Index server and wait for XML files to begin to reappear in the directory.
  4. After you see XML files appearing on the Index server, repeat steps 2, 3 & 4 on each query server, waiting for XML files to appear before moving to subsequent servers.
  5. After all of the query servers have all been cleared and new .xml files have been generated, proceed to the WFE and Application servers in the farm, following steps 2, 3, 4 and 5 for each remaining server.

Folder location and ConfigDB id


Creating Sharepoint Timer Jobs November 8, 2009

Filed under: Sharepoint,Timer,Timer Job — sladescross @ 11:15 am

A few weeks back I posted about how you can create custom timer jobs for use in the latest release of SharePoint to perform scheduled tasks. However, considering there have been almost 40 comments to the post in the last three weeks, I figured the post needed some clarification (duh, ya think?).

The first thing you need to do is create a class that inherits from the Microsoft.SharePoint.Administration.SPJobDefinition class. To implement this class, you need to create a few constructors and override the Execute() method, like so:

Powershell reporting and invoking of custom job definition.

Custom timer job and timer job configuration.

To read the data, use the XmlSerializer class to deserialize the XML into the Address object.

Address _address = new Address();
XmlSerializer serializer = new XmlSerializer(typeof(Address));
FileStream file = new FileStream(@"c:\address.xml", FileMode.Open);
_address = serializer.Deserialize(file) as Address;

To serialize the Address object back to the XML file, do the exact opposite of reading the file.

Address _address = new Address();
XmlSerializer serializer = new XmlSerializer(typeof(Address));
TextWriter writer = new StreamWriter(@"c:\address.xml");
serializer.Serialize(writer, _address);

The SPPersistedObject class provides a base class for all administration objects. It serializes all fields marked with the Persisted attribute to XML and writes the XML blob to the configuration database. The SPPersistedObject class contains code to serialize all its members that are base types, other persisted objects, and collections of persisted objects. Configuration data that is stored in persisted objects is automatically made available to every process on every server in the farm.



Get every new post delivered to your Inbox.

Join 63 other followers