XAP cached and no way clearing the cache!-Collection of common programming errors
You could use IHttpHandler instead of direct link to .xap file. This means the url to your .xap file should be changed from “webapp/slapp.xap” to “webapp/handler.axd?source=slapp.xap”. Then you will be able to add another parameter to last url, for example build number: “webapp/handler.axd?source=slapp.xap&buildno=1234”. After upgrading your silverlight application you will have to change url parameter “buildno”.
1 public class XapHandler : IHttpHandler 2 { 3 #region IHttpHandler Members 4 public bool IsReusable 5 { 6 get { return true; } 7 } 8 9 public void ProcessRequest(HttpContext context) 10 { 11 string UrlPath = context.Request.Params["source"]; 12 if (string.IsNullOrEmpty(UrlPath)) 13 { 14 context.Response.StatusCode = 404; 15 return; 16 } 17 string PhysicalFileName = context.Request.MapPath(UrlPath); 18 if (!System.IO.File.Exists(PhysicalFileName)) 19 { 20 context.Response.StatusCode = 404; 21 return; 22 } 23 context.Response.StatusCode = 200; 24 context.Response.ContentType = "application/x-silverlight-2"; 25 try 26 { 27 System.IO.FileStream Stream = new System.IO.FileStream(PhysicalFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None); 28 try 29 { 30 byte[] Buffer = new byte[4096]; 31 int BytesRead = 0; 32 do 33 { 34 BytesRead = Stream.Read(Buffer, 0, Buffer.Length); 35 context.Response.OutputStream.Write(Buffer, 0, BytesRead); 36 } while (BytesRead == Buffer.Length); 37 } 38 finally 39 { 40 Stream.Close(); 41 } 42 } 43 catch 44 { 45 context.Response.StatusCode = 500; 46 return; 47 } 48 context.Response.OutputStream.Flush(); 49 } 50 51 #endregion 52 } 53
Don’t forget to register your http handler in web.config file.