Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It <strong>is the browser</strong> on the client side <strong>that determines the content type</strong> that gets <strong>sent to the server</strong>. That is the browser sends the header that ASP.NET uses to fill the HttpPostedFile.ContentType property.</p> <p><strong>You can't change this with IIS staticContent mime mappings</strong>, those settings apply only to files sent by the server to the client (not the other way around).</p> <p>You'd better <strong>use some custom code in your c# method</strong> before the if-else block you posted, to (attempt to) <strong>determine the</strong> real <strong>mime type with a server side check</strong>. Take a look at those two methods, that lead to different results and performance:</p> <ol> <li><a href="https://stackoverflow.com/questions/1302264/how-do-i-get-the-mime-type-of-a-file-being-requested-in-asp-net-c/1357617#1357617">Use reflection to call to a method in a <em>internal</em> .NET framework class</a> (this simply matches the file extension with those known to the framework itself)</li> <li><a href="https://stackoverflow.com/questions/81283/asp-net-how-to-detect-file-upload-mime-type/1238450#1238450">Use an un-managed call to a IE dll</a> (this method should guess the mime type looking for <em>magic bytes</em> inside the file, <a href="http://msdn.microsoft.com/en-us/library/ms775107%28VS.85%29.aspx" rel="nofollow noreferrer">as you can read in the MSDN documentation</a>)</li> </ol> <p><em>Note: generally speaking you should always check/determine the content type on the server and never rely on the one sent by the client (never trust HttpPostedFile.ContentType): it can be accidentally wrong (as happened to you), purposely changed by some hacky user, wrong because of a browser not complying to some standard (IE is known to send wrong mime types for some image formats)...</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload