Tuesday 4 December 2018

To prevent caching in Internet Explorer

The following 3 ways to prevent caching in the Internet Explorer.
  • HTTP-EQUIV META Tags 
  • In Controller 
  • AJAX 

HTTP-EQUIV META Tags : HTML pages allow for a special HTTP-EQUIV form of the META tag that specifies particular HTTP headers from within the HTML document. Here is a short example HTML page that uses both Pragma: no-cache and Expires: -1:<HTML><HEAD><META HTTP-EQUIV="Pragma" CONTENT="no-cache"><META HTTP-EQUIV="Expires" CONTENT="-1"></HEAD><BODY></BODY></HTML>
  • Pragma: no-cache prevents caching only when used over a secure connection. A Pragma: no-cache META tag is treated identically to Expires: -1 if used in a non-secure page. The page will be cached but marked as immediately expired.
  • Cache-Control META HTTP-EQUIV tags are ignored and have no effect in Internet Explorer versions 4 or 5. To use Cache-Control this header must be specified using HTTP headers as described in the Cache-Control section above.
  • Note that the use of standard HTTP headers are much preferred over META tags. META tags typically must appear at the top of the HTML HEAD section. And there is at least one known problem with the Pragma HTTP-EQUIV META tag.

​​
In Controller - ASP.NET : 
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public abstract class BaseController : Controller
{

}

AJAX :
$.ajax({    url: '/controller/action',    type: 'GET',    cache: false,    success: function(result) {
    }});

how to return back to last visited URL using Javasscript



function CancelSave() {
           var per = document.referrer;
           window.location.href = per;
       }
or
<a href="javascript:history.go(-1);">Go To Previous Page</a>

Ajax Post : AddAntiForgeryToken

When you add <%Html.AntiForgeryToken(); %> _RequestVerificationToken value will automatically be added to the data that you sent back in the POST request. There is nothing else that needs to be done. First check in the POST data, if you see that value or not.


HTML : 
 <a class="delete-link btn btn-danger btn-sm" style="color:white" data-delete-id="@Model.Studen_Sno">Delete</a>
                  
Jquery : 
$(function () {
        AddAntiForgeryToken = function (data) {
            data.__RequestVerificationToken = $('input[name=__RequestVerificationToken]').val();
            return data;
        };
    });