At the time of writing this article would like to write the title directly as a hint of error, as follows:
"securityerror:blocked a frame with origin" http://localhost:55080 " From accessing a cross-origin frame. "
But a bit long, will show not all, just want to change it, think about it
"ASP. NET upload a large picture or file error Resolution",
And then when I finish writing this topic, I think this article seems to have no need to write at all, it is estimated that reading the topic will think about the configuration of the Web. config. But want to write the content is really not so "simple", after all, it is spent a few hours to study AH ~ ~ ~ So think again, become the present topic, is to share with you.
That's about it.
First on the error prompt:
First prompt
Prompt after
That is true Download a ajaxfileupload.js plugin on the internet, for no refresh upload pictures to make, and then follow the example of the demo to run a bit, upload ah what are OK, but just upload the example image has a relatively large, 4m,5m look, and then upload will report the above error.
Simply look at my description, it is obvious that the reason for the larger picture, may soon think of the configuration of the Web. config problem, but when I was the authority of the time, there is no such a light, because there are hints wrong, there is a visit to Baidu, the results found what is "cross-domain tuning function" problem, so far, The question I explored is in the wrong direction.
Although there is no obvious point in the question is the size of the upload image is related, but this problem is not set the size of the upload file, and the default upload file size of ASP. 2M
Let me tell you the solution first by adding the following paragraph to the <system.web> of Web. config
< httpruntime maxRequestLength = "4096" usefullyqualifiedredirecturl = "true" executiontimeout = "6000" minfreethreads = "8" minlocalrequestfreethreads = "4" apprequestqueuelimit = "" " enableversionheader = "true" />
Description
Gorgeous Split-line
Gorgeous Split-line
If you want to understand my inquiry into the whole problem of the process, then continue to look down, quite interesting (in fact, because of the initial exploration of the problem, let me learn more relevant knowledge, the process is more disgusting, but the results are relatively happy. )
Say that the error hint, is "securityerror:blocked a frame with origin"http://localhost:55080 " from accessing a Cross-origin frame." This sentence, and then mentioned what "cross-domain tuning function", then confused, what is this ah? And then see an article is about this, the main point is that there is an IFRAME in the page, and then the JS code in the IFRAME and the page JS code calls each other, in some cases it becomes a cross-domain call, will error.
Find here I have a bit impatient, because seemingly need to see the source code of Ajaxfileupload.js plug-ins, to tell the truth, see JS Source code is my many do not love one of the things. But I do not like to meet the problem quickie person, so must look.
at first, I was more puzzled about how JS implemented the file upload? of course, I know it is Ajax, but when the page is directed, the background is how to get the file path to upload it? (The front desk is dead will not let you get, will be like c:\fakepath\ Xxx.jpg forgive my ignorance, in fact, has been in the use of ASP. NET-own control, never put these issues back (just recently seems to have some light, listen to some friends said that the development will not use the ASP. NET-own control, so recently began to change), but when the need to use When <input type=file/> , he knew that he was really ignorant. Nice cup.
Say how JS is through the AJAX implementation of the upload file, simply by submitting a form, the inclusion of a <input type=file/> form submission is OK, and then in the background through
httpfilecollection files = System.Web.HttpContext.Current.Request.Files
You can get this file object, and then you can do a series of operations. However, it is usually the first to save the file to a directory we specify, if you want to preview the image, then you can only pull the copy to the specified directory of the image to display. I don't know what I'm saying, all clear?
Here is how the ajaxfileupload.js plug-in implementation of the file upload it, it is dynamic to create an IFrame and a form, and then Clone (clone) the page <input type=file/> To this form, then submit the dynamic creation of the form, so that the background can know what you want to upload the file is what, the content returned to the dynamic IFRAME, more importantly, this is a no-refresh upload Ah! It feels like a cool idea.
Back to the problem, in the process I found there was no "cross-domain tuning function" problem, followed by the browser break point. When the discovery of a large file upload, the document structure of the dynamic IFrame is not generated at all, then it is caught.
Because the whole JS code to look at the careful, feel there is no urine point. is because the size of the upload file will lead to the IFRAME document structure can be generated, so this time I was a bit counter-effort, is not the problem of project configuration ah? Then we found the solution.
Take a big circle to finally solve the problem, but about the Ajaxfileupload.js plugin is not finished, if interested, please pay attention to:
JQuery about Ajaxfileupload.js Plug-in progressive parsing (ajaxfileupload.js second bomb)
JQuery self-made bullet box upload avatar plugin-to be perfected (ajaxfileupload.js third bomb)
ASP. NET uses the Ajaxfileupload.js plug-in to upload a large file failure resolution (Ajaxfileupload.js first bomb)