Access denied in IE when downloading files

I am currently working on a new site in the .NET MVC platform, and I am trying to implement an asynchronous image loading a user through an iframe. Although I almost completely completed my task and am fully operational in any other browser, it does not work in IE 9 with the following error: Microsoft JScript runtime error: Access is denied. This seems like a security issue. Let me describe my problem using the following code snippets with comments: 1. I have an html form with an input file that its visibility is hidden. Inside the form there is one input element with type="file" and a submit button (also hidden).

 <div class="brandLogo"> <p>@identity._RetailerLogo.Caption</p> <div id="LogoContainer" class="imgLogo"> <img id ="CompanyLogo" src="@DefaultRetailerImage" alt="" title="@Model._ADD_LOGO_IMAGE"> </div> <p class="txtR"> <a id="UploadLogo" href="#" style="position: absolute; left: -999em; top: -999em;">Upload </a> </p> <form id="UploadForm" action="@Url.Action("editLogo", "Profile")" method="POST" enctype="multipart/form-data" name="UploadForm" target="UploadTarget" style="position: absolute; left: -999em; top: -999em;"> <input name="UploadLogoFile" id="UploadLogoFile" type="file" onchange="clickUploadButton();" /> <input type="button" id="SubmitLogoForm" value="Save Image" /> </form> <iframe id="UploadTarget" onload="UploadImage_Complete();" name="UploadTarget" style="position: absolute; left: -999em; top: -999em;"></iframe> 

  • The html form is trying to submit the file in an iframe via javascript. Both the form and the iframe are in my local project (asp.net mvc) in the same domain (I run it under the local host).

  • I am using the on change event on an input element to capture this user who has selected something and to start submitting a form using an ajax call. Therefore, when I call through javascript: $("#formID").submit() , I get an access denied error.

Any help would be appreciated

+4
source share
1 answer

I saw this IE error before, finally, I changed my method. The change event of the input element change is programmatically considered as a security threat to IE :( (so stupid IE)

By default, IE does not allow you to generate a change to a file element if you want this function to be able to use ajaxuploader or fileuploader

 var uploader = new qq.FileUploader({ // pass the dom node (ex. $(selector)[0] for jQuery users) element: document.getElementById('file-uploader'), // path to server-side upload script action: '/server/upload' }); 
+2
source

Source: https://habr.com/ru/post/1432543/


All Articles