{"id":3132,"date":"2014-03-16T22:56:15","date_gmt":"2014-03-16T22:56:15","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/16\/xap-cached-and-no-way-clearing-the-cache-collection-of-common-programming-errors-2\/"},"modified":"2014-03-16T22:56:15","modified_gmt":"2014-03-16T22:56:15","slug":"xap-cached-and-no-way-clearing-the-cache-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/16\/xap-cached-and-no-way-clearing-the-cache-collection-of-common-programming-errors-2\/","title":{"rendered":"XAP cached and no way clearing the cache!-Collection of common programming errors"},"content":{"rendered":"<p>You could use IHttpHandler instead of direct link to .xap file. This means\u00a0the url to your .xap file\u00a0should be\u00a0changed\u00a0from &#8220;webapp\/slapp.xap&#8221; to &#8220;webapp\/handler.axd?source=slapp.xap&#8221;. Then you\u00a0will be able to\u00a0add another parameter to last url, for example build number: &#8220;webapp\/handler.axd?source=slapp.xap&amp;buildno=1234&#8221;. After upgrading your silverlight application you will have to change url parameter &#8220;buildno&#8221;.<\/p>\n<pre><b>1 <\/b>  public class XapHandler : IHttpHandler <b>2 <\/b>  { <b>3 <\/b> #region IHttpHandler Members <b>4 <\/b> public bool IsReusable <b>5 <\/b> { <b>6 <\/b> get { return true; } <b>7 <\/b> } <b>8 <\/b> <b>9 <\/b> public void ProcessRequest(HttpContext context) <b>10 <\/b> { <b>11 <\/b> string UrlPath = context.Request.Params[\"source\"]; <b>12 <\/b> if (string.IsNullOrEmpty(UrlPath)) <b>13 <\/b> { <b>14 <\/b> context.Response.StatusCode = 404; <b>15 <\/b> return; <b>16 <\/b> } <b>17 <\/b> string PhysicalFileName = context.Request.MapPath(UrlPath); <b>18 <\/b> if (!System.IO.File.Exists(PhysicalFileName)) <b>19 <\/b> { <b>20 <\/b> context.Response.StatusCode = 404; <b>21 <\/b> return; <b>22 <\/b> } <b>23 <\/b> context.Response.StatusCode = 200; <b>24 <\/b> context.Response.ContentType = \"application\/x-silverlight-2\"; <b>25 <\/b> try <b>26 <\/b> { <b>27 <\/b> System.IO.FileStream Stream = new System.IO.FileStream(PhysicalFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None); <b>28 <\/b> try <b>29 <\/b> { <b>30 <\/b> byte[] Buffer = new byte[4096]; <b>31 <\/b> int BytesRead = 0; <b>32 <\/b> do <b>33 <\/b> { <b>34 <\/b> BytesRead = Stream.Read(Buffer, 0, Buffer.Length); <b>35 <\/b> context.Response.OutputStream.Write(Buffer, 0, BytesRead); <b>36 <\/b> } while (BytesRead == Buffer.Length); <b>37 <\/b> } <b>38 <\/b> finally <b>39 <\/b> { <b>40 <\/b> Stream.Close(); <b>41 <\/b> } <b>42 <\/b> } <b>43 <\/b> catch <b>44 <\/b> { <b>45 <\/b> context.Response.StatusCode = 500; <b>46 <\/b> return; <b>47 <\/b> } <b>48 <\/b> context.Response.OutputStream.Flush(); <b>49 <\/b> } <b>50 <\/b> <b>51 <\/b> #endregion <b>52 <\/b> } <b>53 <\/b>\n<\/pre>\n<p>\u00a0Don&#8217;t forget to register your http handler in web.config file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You could use IHttpHandler instead of direct link to .xap file. This means\u00a0the url to your .xap file\u00a0should be\u00a0changed\u00a0from &#8220;webapp\/slapp.xap&#8221; to &#8220;webapp\/handler.axd?source=slapp.xap&#8221;. Then you\u00a0will be able to\u00a0add another parameter to last url, for example build number: &#8220;webapp\/handler.axd?source=slapp.xap&amp;buildno=1234&#8221;. After upgrading your silverlight application you will have to change url parameter &#8220;buildno&#8221;. 1 public class XapHandler : [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3132","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3132"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3132\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}