404 error with IIS 7.0 - iis

I have a text file that I am trying to browse to using the browser http://files.mydomain.com/test.txt and I get a:
HTTP Error 404.0 - Not found
I double checked and the text file does exist. When I add a test.htm file, I have no issues.
Can someone help? Something tells me it's security issue.

Have you checked the following:
Your DNS 'A' record for 'files' is pointing to the correct IP address
If your server is using a shared IP address across multiple sites have you configured a HTTP host header?
Is there a mime type set for the .txt extension?
Have you made any changes to the Handler Mappings for the site? e.g. mapped the .htm extension to say the ASP ISAPI filter and accidentally removed the StaticFile handler?
Can you serve other static content such as .jpg, .gif, .pdf etc?

Kev has covered most of the possible problems, but for reference there is another possibility.
Confirm that in Request Filtering you either
have .txt as an Allowed extension, or
have Allow unlisted file name extensions ticked in Edit Request Filtering Settings
The same effect can be achieved with the following web.config section:
<system.webServer>
<security>
<requestFiltering>
<fileExtensions>
<add fileExtension=".txt" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>

Also make sure also that the website is started. I was getting 404 and then realized that the Default Website was stopped because another website (Sharepoint) was using port 80. Sometimes the obvious is what gets you.

Add the MIME-Typ by going to ...
features / Mime-type
right click,
add,
put in the file extension ".txt"
and the mime-type "text/plain"
ok
et voila

I know this is an old post, but this might still help somebody out. I ran into this problem with my Asp.Net Core application. In my case it turned out that static files are served from a subdirectory called 'wwwroot' by default. Creating that subdirectory and moving the file in their solved it for me:
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/index?view=aspnetcore-2.2&tabs=windows#web-root

Related

http://localhost:port always redirecting to https://localhost

I'm building a simple website in vs2015. I have IIS express selected as the hosting environment. I have tried multiple new projects and seem to be going around in circles, having installed and uninstalled iis-express 10 multiple times, and added and removed windows feature of iis also. When I launch a web project from vs2015, it used to open (without issue) a http://localhost:port (e.g. http://localhost:51898), but now continually redirects to https://localhost.
Any idea why?
It is not about Visual Studio, it is about Chrome.
This solution worked for me: Google Chrome redirecting localhost to https
the redirect will only happen with explict configuration and IIS or
asp.net will not automatically redirect .
check following config files and loo for any redirect settings
ApplicationHost.Config,All web.config files (C:\Windows\System32\inetsrv\config)
search for httpRedirect
e.g. <httpRedirect enabled="true" destination="https://localhost" />
check for urlrewrite configurations. a typical rule will be like this .so you can search for Redirect
<action type="Redirect" url="http://www.maindomain.com/{R:1}" />
</rule>
If you do not find these settings anywhere in your configuration,your application code is doing this.Check your code
In my situation it was caused by this piece of code:
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
Anyway double check you startup.cs file. Maybe configurations there are part of a problem
in my case, it was a configuration i did on IIS for all my sites to load via https. The rewrite rule matched localhost as well and hence it redirects to https. I rewrote the redirect rule and it was ok.

Unable to host large files on IIS webserver

I'm running IIS 8 on Windows Server 2012R2, and I'm having an issue. I'd like to be able to host large files, but it's causing problems. If I put anything over ~400MB on it, then when I try to access that file from a browser I get a "404 file not found" error.
I should note that smaller files work fine. Any thoughts?
The problem could be that your MIME types need to be modified. From https://serverfault.com/a/78526/12894:
What is probably happening is that your server doesn't know that .war
is a type of file that needs to be downloaded rather than executed. It
then is run through your allowed Web Service Extensions for any
matches. If it doesn't find one, it throws a 404 error even though the
file does in fact exist.
If you set a MIME type for war files of type application/octet-stream,
that should resolve your issue.
See also the Microsoft article Requests for static files return 404 error (IIS 6.0)
Have you tried looking at the Web.config file for the maxrequestlength tag? The problem in this case is not the upload, but rather the request for the file, when the page is loaded. Look for the following line:
<httpruntime maxrequestlength="51200" executiontimeout="7200"/>
Where I set the second number to 2 hours (just a random timeout time) and the first number is the maximum file size that a page that needs the file can request. In this case, you can have 500Mb of upload size. This may fix it, however, there's also another section that you can edit, added in for security purposes:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="524288000"/>
</requestFiltering>
</security>
Here, again you have 1024x1024*500=500Mb. This is edited in the session properties - you can do that through the Management Interface or through writing your own scripts. Have a look at MSDN here:
http://technet.microsoft.com/en-us/library/cc725820(v=ws.10).aspx

DotNetNuke redirects when calling ImageResizer with fake extension

I've installed the ImageResizer libraries in my DotNetNuke environment as described at http://imageresizing.net/docs/workswith/dotnetnuke
But I'm getting redirected to the root of my portal as soon as I call the resizer extension
My resize settings in the web.config look exactly the same as the example in the installation guide
<resizer>
<pipeline fakeExtensions=".ashx" />
<plugins>
<add name="MvcRoutingShim" />
<add name="DiskCache" />
</plugins>
</resizer>
Looks good to me, but as soon as i try to call an image through the extension, I get redirected to the root of the site.
Call to:
http://localhost/Portal/0/Image.jpg.ashx
Redirects to:
http://localhost/
I can't figure out how to fix this. Is it a DotNetNuke or a IIS setting?
Things I already tried:
Checked the Configuration of the site and made sure the .ashx extension has the "Verify that file exists" checkbox unchecked.
Tried using an other extension
Tried adding a wildcard in IIS
checked resizer.debug.ashx,
2 Issues detected:
(Warning): To potentially see additional errors here, perform an image resize request.
Server(Warning): Microsoft-IIS/6.0 does not support Integrated mode or does not have it enabled.
You must append the .ashx extension to any image requests you wish to process.
It seems the handler is never called and the redirect takes place based on the fact that there's no physical file called Image.jpg.ashx.
Any ideas how to fix this?
It was a defective rewriterule in SiteUrls.config causing this problem:
<RewriterRule>
<LookFor>[^?]*/(\d+)/(.*)</LookFor>
<SendTo>~/Default.aspx?tabid=$1</SendTo>
</RewriterRule>

ServiceStack always Default Redirect to /metadata even when Default.cshtml present

I have a ServiceStack project with ServiceStack Razor added. Any time I try and navigate to the root of the site, I'm getting redirected to /metadata.
This does not happen on my dev machine, only in my hosted environment (AppHarbor).
I do have a Default.cshtml in the root of my project.
Navigating to other URLs work fine: /default1.cshtml, /myservicewithviews
I've tried messing with the DefaultRedirectPath in my AppHost, but that didn't help.
Trying to force it DefaultRedirectPath = "default.cshtml" result in a redirect loop. Which makes sense.
What is causing this?
AppHarbor only publishes files marked "Content" when building projects (AppHb FAQ). This file was the only one not marked content and why I was only experiencing this in my hosted environment and could access all other content.
Not detecting a default document causes ServiceStack to set a RedirectHttpHandler to /metadata - shown around here
Another noteworthy point is that AppHarbor's load-balancer causes their internal port numbers to show up in ServiceStack URLs when performing things like Response Redirects.
To fix this problem, you add the following to your Web.Config:
<appSettings>
<!-- AppHarbor Setting to stop AppHb load balancer internal port numbers from showing up in URLs-->
<add key="aspnet:UseHostHeaderForRequestUrl" value="true" />
</appSettings>
You could also configure this setting in your AppHarbor config panel.

IIS 7.5 Custom 404 Error Page Not Working for Web Root Index/Default

Using IIS 7.5 I have created a custom 404 (and 403.14) error page that displays content from a database if a static file is not found.
In other words, if I browse to http://mysite.com/test/ and a physical index or default file is not found at that location then IIS executes my 404 custom error page which parses the url and either displays a page stored in a database, or a notice saying the page cannot be found.
Everything is working perfectly except that IIS will not display the 404 page for the web root index/default page.
There are no files in the web root directory - here are my observed results:
mysite.com: Completely blank page
mysite.com/: Completely blank page
mysite.com/index.aspx: Correctly displays my custom error page.
mysite.com/default.aspx: Correctly displays my custom error page.
mysite.com/index.htm: Correctly displays my custom error page.
mysite.com/anything_else/: Correctly displays my custom error page.
My Web.config file contains:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/_page/" responseMode="ExecuteURL" />
<error statusCode="403" subStatusCode="14" path="/_page/" responseMode="ExecuteURL" />
</httpErrors>
I would like to store the contents of the home page in a database like the rest of the site's dynamic pages but after much searching still cannot find out how to get IIS to display my custom error page when the home index/default page is not found.
Any help/thoughts would be greatly appreciated.
fodder
I ended up solving this by using the web root index itself as the custom error page instead of another page like "/_page/".
This worked for everything except for SSL redirecting, which I decided was not a big enough issue to hold up the project.
In the system, every page is explicitly set to either http or https. If a user navigates to an https page using an http address then they are redirected to the https version and vice-versa. However, using the root index as the custom error page means that this redirection won't work for the home page because IIS will not redirect a page to itself for some reason.
If anyone has any idea how to get around that problem I'd greatly appreciate your thoughts. But the original question is essentially solved.
Hope reading this helps someone.
fodder
UPDATE - 08/17/2012:
Well, it took a support call to Microsoft (arduous, but eventually fruitful) but I finally found the answer to the underlying problem
When I first set up the web server, I did not install the "Directory Browsing" module for security reasons. I didn't want web clients to be able to see the file structure.
Well, it turns out that one needs to install the Directory Browsing module (EVEN IF IT IS DISABLED) to make IIS respond with anything besides a 200OK (and generate a blank html page).
Once installed (and left disabled, for security reasons), IIS now responds with a 403.14 Forbidden error, which I already had correctly redirecting in my web.config.

Resources