Sharepoint stop caching xml or media files

If  you are using sharepoint you noticed that every xml,img or media files are cached automatically. This is good for performance but its so problematic for changes or updates. You change something in your xml at background but users can not see changes because of sharepoint caching .

Solution is so easy

this is your file path:

[your xml url]/myfile.xml
[your img url]/img.jpg

if you change it like this

[your xml url]/myfile.xml?ver=[some number]

[your img url]/img.jpg?ver=[some number]

and after change your xml content generate some random number for [some number] sharepoint relaese caching your media or data files.I am using GUID for this 🙂

Getting Root Site in Sharepoint

When you are working in sharepoint with extended web applications which is using different authentication methods . You have to need current URL of different domain for hardcoded envoriment . For example http://www.test.com one of your extranet using forms authentication and http://myserver is your default and using windows authentication. if user create a request from http://www.test.com/somedifferet… you need to root of http://www.test.com rather than http://myserver.And you dont want a login screen because of links.

if you type hard code like this its not working for default domain which image not in _layout folder.

<img src=”http://myserver/something/imagenotcomingfromlayout.jpg”&gt; asks extra windows auth login

Solution.

<img src=”/_layouts/GetRootSite.ashx?url=http://myserver/something/imagenotcomingfromlayout.jpg”>

Handlers returns same as users coming request root site.and change http://myserver/ to http://www.test.com

Create a generic handler like below and add this handler to 12/TEMPLATES/LAYOUTS folder for every registered user can reach.

<%@ WebHandler Language=“C#” Class=“GetRootSite” %>

using System;

using System.Web;

using System.Net;


public
class GetRootSite : IHttpHandler

{

public void ProcessRequest (HttpContext context) {

Uri requestUri = context.Request.Url;

string baseUrl2 = context.Request.Url.GetLeftPart(UriPartial.Authority);

string gelenpath = context.Request.QueryString[“url”];

Uri gelen = new Uri(gelenpath);

string gelenPreFix = gelen.GetLeftPart(UriPartial.Authority);

string artakalan = gelenpath.Substring(gelenPreFix.Length);

string sonuc = baseUrl2 + artakalan;

context.Response.Redirect(sonuc);

}

public bool IsReusable {

get {

return false;

}

}

}

AjaxControlToolkit with Sharepoint

Prerequiests

You have to configure your sharepoint for .net 3.5 framework
See this post

Download and setup AjaxControlToolKit to Sharepoint
Download AjaxControlToolkit

1-) Add your web applications web.config file in safecontrols tag

<SafeControl Assembly=AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e Namespace=AjaxControlToolkit TypeName=* Safe=True />

2-)Add fallowings into your web.config-> Pages->Compilation->Assemblies tag

<add assembly=AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e />

3-) Reset your iis server

Do not forget to add assembly to your web page

<%@ Assembly Name=”AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e” %>

Step by Step configure your sharepoint running with .NET Framework 3.5

Step by Step configure your sharepoint running with .NET Framework 3.5

(Do not forget to backup your web.config file)

1) First setup Framework 3.5 to your server.And you already have got a Web Application on which you want to do these changes.

2)Add fallowings to Web.Congif in configuration -> configSections

    <sectionGroup name="system.web.extensions"

                type="System.Web.Configuration.SystemWebExtensionsSectionGroup,

                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

                PublicKeyToken=31BF3856AD364E35">

      <sectionGroup name="scripting"

                  type="System.Web.Configuration.ScriptingSectionGroup,

                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

                PublicKeyToken=31BF3856AD364E35">

        <section name="scriptResourceHandler"

                 type="System.Web.Configuration.ScriptingScriptResourceHandlerSection,

                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

                PublicKeyToken=31BF3856AD364E35" requirePermission="false"

                 allowDefinition="MachineToApplication"/>

        <sectionGroup name="webServices"

                     type="System.Web.Configuration.ScriptingWebServicesSectionGroup,

                    System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

                    PublicKeyToken=31BF3856AD364E35">

          <section name="jsonSerialization"

                  type="System.Web.Configuration.ScriptingJsonSerializationSection,

                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

                PublicKeyToken=31BF3856AD364E35" requirePermission="false"

                  allowDefinition="Everywhere" />

          <section name="profileService"

                  type="System.Web.Configuration.ScriptingProfileServiceSection,

                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

                PublicKeyToken=31BF3856AD364E35" requirePermission="false"

                  allowDefinition="MachineToApplication" />

          <section name="authenticationService"

                  type="System.Web.Configuration.ScriptingAuthenticationServiceSection,

                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

                PublicKeyToken=31BF3856AD364E35" requirePermission="false"

                  allowDefinition="MachineToApplication" />

          <section name="roleService"

                  type="System.Web.Configuration.ScriptingRoleServiceSection,

                System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

                PublicKeyToken=31BF3856AD364E35" requirePermission="false"

                  allowDefinition="MachineToApplication" />

        </sectionGroup>

      </sectionGroup>

    </sectionGroup>

  </configSections>

3-) Add fallowings to web.config sharepoint->SafeControls

      <SafeControl Assembly="System.Web.Silverlight,Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.SilverlightControls" TypeName="*" Safe="True" />

      <SafeControl Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TypeName="*" Safe="True" />

4-) Add fallowings to web.config System.Web->httphandlers

      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>

5-) Add fallowings to web.config System.Web->httpmodules

      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

6-) Add fallowings to web.config System.Web->compilation->assemblies

        <add assembly="System.Core,Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

        <add assembly="System.Data.DataSetExtensions,  Version=3.5.0.0, Culture=neutral,   PublicKeyToken=B77A5C561934E089"/>

        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

7-)Add fallowings to web.config System.Web->Pages

      <controls>

        <add tagPrefix="asp" namespace="System.Web.UI"

              assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

        PublicKeyToken=31BF3856AD364E35"/>

        <add tagPrefix="asp" namespace="System.Web.UI.WebControls"

              assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

        PublicKeyToken=31BF3856AD364E35"/>

        <add tagPrefix="cc1" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>

        <add namespace="ProfileDAL" assembly="ProfileDAL ,Version=0.0.0.0,Culture=neutral, PublicKeyToken=aa99289942830a2b" tagPrefix="cc1" />

      </controls>

8-)Add fallowings to web.config

  <system.web.extensions>

    <scripting>

      <webServices>

      </webServices>

    </scripting>

  </system.web.extensions>

  <system.webServer>

    <validation validateIntegratedModeConfiguration="false"/>

    <modules>

      <add name="ScriptModule" preCondition="integratedMode"

          type="System.Web.Handlers.ScriptModule,

            System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,

            PublicKeyToken=31bf3856ad364e35"/>

    </modules>

    <handlers>

      <remove name="WebServiceHandlerFactory-Integrated" />

      <add name="ScriptHandlerFactory" verb="*"

          path="*.asmx" preCondition="integratedMode"

          type="System.Web.Script.Services.ScriptHandlerFactory,

            System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,

            PublicKeyToken=31bf3856ad364e35"/>

      <add name="ScriptHandlerFactoryAppServices" verb="*"

          path="*_AppService.axd" preCondition="integratedMode"

          type="System.Web.Script.Services.ScriptHandlerFactory,

            System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,

            PublicKeyToken=31bf3856ad364e35"/>

      <add name="ScriptResource" preCondition="integratedMode"

          verb="GET,HEAD" path="ScriptResource.axd"

          type="System.Web.Handlers.ScriptResourceHandler,

            System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,

            PublicKeyToken=31bf3856ad364e35" />

    </handlers>

  </system.webServer>

  <system.codedom>

    <compilers>

      <compiler language="c#;cs;csharp" extension=".cs"

compilerOptions="/warnaserror-" warningLevel="4"

type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0,

Culture=neutral, PublicKeyToken=b77a5c561934e089">

        <providerOption name="CompilerVersion" value="v3.5"/>

      </compiler>

      <compiler language="vb;vbs;visualbasic;vbscript"

extension=".vb" compilerOptions="/optioninfer+"

type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0,

Culture=neutral, PublicKeyToken=b77a5c561934e089">

        <providerOption name="CompilerVersion" value="v3.5"/>

      </compiler>

    </compilers>

  </system.codedom>

9-) Reset iis