Coding Platform ASP.NET 4.0 WebForms on IIS7.5
If I request a page blahblah.aspx which does not exist, I get navigated to my custom error page for Page not found Exception. I have implemented URL routing and so I have omitted all my .aspx extensions for routes.
Now, If I type www.mysite.com/blahblah (thats a url without extension) instead of going to my custom error page, it gets redirected to my IIS 404 error page.
What should I do to make my custom error page appear on my site instead of IIS error page?
The Easy Way
If your IIS 7 web server doesn't already have it, install the IIS 7.0 Administration Pack from Microsoft.
Navigate to the root web server name in IIS, and open the Configuration Editor (part of the Administration Pack). Change the dropdown to system.webServer/httpErrors, right-click on defaultPath, and choose 'defaultPath' Attribute -> Unlock Attribute.
Then try to change the custom error handler page again. Navigate to your site, open Error Pages under the IIS group, click Edit Feature Settings on the right, select Custom error pages and finally, put in your path for the default page.
No lock error this time.
I originally tried to unlock this attribute at the web site level but was prevented, so be aware you may have to go all the way to the root of the IIS tree, the web server itself.
The Manual Way
I know you can accomplish all this by direct editing in notepad of the appropriate config file on the web server. And that may be required for your particular web hosting environment or company production web server change protocols. But why make it complicated if it doesn't need to be? Plus, this way you can do it in the GUI, and compare the before and after to see what changes you truly have to make. But if you MUST do it manually, then:
Open the file %windir%\System32\inetsrv\config\applicationHost.config in Notepad. Run Notepad as administrator if you're having problems.
Pro tip: Do not use notepad++ to edit applicationHost.config. You'll end up secretly and silently saving a 32-bit copy of the file that's in a different folder than the one IIS looks in (due to Windows, not np++) without actually affecting the file you wish to change.
You'll see something like this:
<httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
Remove the ,defaultPath section and save.
You will be able to make the changes you need.
Assuming you haven't done this already...
Go to IIS, select your website, and choose the option "Error Pages". In there, find the 404 status code, right click and go to "Edit Feature Settings". you can then select "Custom Error pages" and change the "Path Type" to URL "Execute URL" to do some rewriting, or a default redirect page for anything else. Put in your URL as a relative value, and now it should redirect to this url on 404 errors.
Edit: Did a bit of digging, in cases, this config may be locked, if you run the following command, it should remove the lock:
%windir%\System32\inetsrv\appcmd unlock config -section:system.webserver/httperrors
Once that is done, you can edit the url properly.
Related
I'm trying to setup a classic ASP page to log errors by redirecting the errors to error page that has logging enabled. When the site was migrated from IIS6 to IIS7 the logging stopped working as the details of the errors are not included in the redirect.
I have been able to fix this issues somewhat by going to the site in IIS Manager, going to that sites Error Pages, Clicking Edit Feature Settings, and Changing that option to Detailed errors for local requests, setting my default path to the error page, and changing the path type to execute URL. In order to do this I had to edit the apphost.config and remove some of the locks that are in place there.
Now when I go to other sites on my IIS the same default page path is set on those too. can someone please point me to some documentation or tell me how to make this change only for this particular site?
TO do the error page per Website Deployed in the IIS you need to click on individual website and then on right hand side click on Error Pages and select the Page.
My problem ended up that I was editing my applicationHost.config which would seem like a reasonable solution, but alas it was not. Changing that XML seems to have no effect on what the IIS manager would allow me to do. I finally went into the Configuration Editor for the root of IIS and edited the same settings there, which actually had some effect. All that I had to do at that point was remove the attribute lock on default path and the then I was able to edit my site. I have no idea why changing the application host did not have any effect. I would make the change and when I finally looked in the settings in the IIS manager, nothing I had done was changed at all... FYI this is IIS 7.5 on Win7
Hope this helps someone else.
My site/application points to a folder called "site" with all permissions set up.
In that folder resides "home.asp".
Default document is "home.asp".
When I go to the domain, I get a "page not found".
If I capture that 404 error in IIS and tell it to redirect to "home.asp", everything works.
The problem with that is I don't want to redirect all 404's to home.asp.
I want the site to default to home.asp and find it.
Any ideas why this is happening?
Do I need to do something to the .Net side of things to tell it to
use the .ASP side of things by default?
Do I need to create a .aspx default page that redirects to my
"home.asp"? If so, what do I name that page?
As Diodeus indicated you should not try to redirect to a default page with a custom 404 error page that redirects, but rather by making sure your "home.asp" is added to the list of default documents within IIS.
This is thus an IIS configuration issue.
For instance for setting up default documents in IIS 6.0 this would be:
In IIS Manager, double-click the local computer, right-click the individual Web site folder, and then click Properties.
Click the Documents tab.
Select the Enable default content page check box.
Click Add to add a new default document to the list. (For you this would be your "home.asp")
Optional: Click the document you want to remove from the list and click Remove.
Click a document from the list and click Move Up or Move down to change the order in which default documents are served to client requests.
Click OK.
(From http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/dc6eb1b4-9028-4308-9935-52b64edfad36.mspx?mfr=true)
We have a problem in that IIS is no longer serving finding the default document (default.aspx) on a server which has previously been working OK. We have not consciously changed the configuration of the machine.
The symptoms are that if you go to the root of an application on the machine, it displays an asp.net 404 not found page with the following text:
The resource cannot be found.
Description: HTTP 404. [etc...]
Requested URL:
/folder/eurl.axd/dd4414e526108f45a561b782d54f3ba2/
I don't know what eurl.axd is, but it seems to refer to extensionless URL support for ASP.NET 4.0, but the sites in question are all ASP.NET 2.0 sites.
Default.aspx is definitely set as the default the document (and is at the top of the list) for the site.
If I manually type in /folder/default.aspx the site then works fine, so it's not a problem serving the page, but merely a problem with IIS not defaulting to that page on it's own.
Any ideas how to fix this would be appreciated as this affects a live server :(
OK I've resolved this now. It seems it is indeed because of the extensionless URL support feature of ASP.NET 4.0. Despite the fact my sites are running .NET 2.0 sites it still seems to affect them as well (possibly because the URL filtering happens higher up?). I disabled extensionless URL support (see link) and now it's finding default.aspx pages OK.
For for more info, check this article:
http://blogs.msdn.com/b/tmarq/archive/2010/06/18/how-to-disable-the-asp-net-v4-0-extensionless-url-feature-on-iis-6-0.aspx
To install and enable ASP.NET:
1> Click Start, and then click Control Panel.
2> Click Add or Remove Programs.
3> Click Add/Remove Windows components.
4> Double-click Application Server, and then click Details.
5> Click to select the ASP.NET check box, and then click OK.
6> Click Next.
7> Click Finish.
So here's the issue. We run Sitecore, which does URL rewriting, and allows for something like example.com/Folder/Page.aspx to be a proper URL.
Now, "Folder" doesn't actually exist on the file system, and neither does "Page.aspx". But those URL's work, because ASP.NET does what it's supposed to.
Okay, so now say I try to go to a web page that doesn't exist like example.com/idontexist.html. This doesn't exist in on the file system, and doesn't use ASP.NET to resolve the file, so then we get a IIS7 404 Error.
Now, I want to change the 404 Error Page to a Custom Error Page, by using a URL. Say, the URL is example.com/ErrorPage.aspx. This page is actually, not a physical page, but an item in Sitecore.
In the Custom Error configuration in IIS Manager, I am trying to change the 404 Error to point to a "URL Redirect" and I'm using "/ErrorPage.aspx" as the URL redirect. When I try to then go to a URL that doesn't exist, IIS7 blows up with an error saying that it can't find /ErrorPage.aspx.
In IIS6, this isn't an issue, and everything works fine. But on IIS7, I redirect to a URL that isn't physically on the server.
Help!
to make a very long story short, here's the thing:
1) configure IIS so that 404 errors go to "default.aspx"
2) create a page that actually handles what you want to handle.
Reference links, SDN originals:
http://sdn5.sitecore.net/upload/sitecore6/handling_http_404_a4.pdf
http://sdn.sitecore.net/upload/sitecore6/dynamic_links_a4.pdf
I set up 404 handler page in web.config, but it works ONLY when extension of URL is .aspx (or other which is handled by ASP.NET).
I know I can setup static HTML page in website options, but I want to have a page.
Is there any options to assign ASPX handler page for all request extensions in IIS?
The direct question was whether or not there are options to assign the ASPX handler to all request extensions: Yes, there is. I'll discuss how to do that shortly.
First, I think the "hidden" question -- the answer you really want -- is whether or not there's a way to redirect all 404 errors for pages other than ASPX, ASMX, etc. Yes, there is, and this is the better choice if it'll solve the issue you're having.
To redirect all 404s in IIS 6, right click your web application root (whether it be its own site or a virtual directory in the main site), and choose "Properties." From there, choose the "Custom Errors" tab. Find 404 in the list and change it to the redirect you want.
Now, if that won't suffice -- and I really hope it does -- yes, you can run every page through the ASPX handler. However, doing so comes at a fairly high cost in terms of efficiency -- raw HTML/image serving is considerably faster than anything dynamic.
To do this, right click your web application root and choose "Properties." Choose the "Home Directory" tab. Click "Configuration;" a new window will pop up. Copy the path from one of the ASP.NET page serves, and then use it for a wildcard application map.
Bear in mind, again, this is the wrong answer most of the time. It will negatively impact your performance, and is the equivalent of using a chainsaw to carve a turkey. I highly recommend the first option over this one, if it will work out for you.
For information:
This is one of the several nice things that IIS7 brings - all pages are routed through the handler such that you can do custom 404s and - usefully - directory and file level security for any file (based on the same web.config stuff as for asp.net files prior to IIS7).
So notionally "use II7" is an answer (will be "the" answer in time) - but of course its not a terribly practical one if you're not hosting/being hosted on W2k8 (or higher).
The web.config can only set up errors pages for pages controlled by it's web site. If you have any other pages outside the purview of the ASP.Net application, then you set up handling for them in IIS. There's an option in there for configuring the 404 page where you can point it to your custom page.
Only other thing i can think of is passing ALL extensions to asp.net.
This way all types of files get processed by asp.net and your custom error page will work.
In the IIS application configuration, you can set a wildcard mapping (".*") to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
You can setup wild card mapping in IIS (Application configuration/Mappings/Wildcard mappings/ - just set aspnet_isapi.dll as executable and uncheck the Verify that file exists box) that will route all incoming requests to your app - so you can control the behavior directly from it.
You don't have to setup static page in your IIS application settings. Imho, you should be able to setup valid url (e.g. /error_handler.aspx) from your app that will be used as landing page in case of specific server error.
In IIS you can set a Custom Error for 404 errors and direct it to a URL in the site properties.
It shows a static html by default
C:\WINDOWS\help\iisHelp\common\404b.htm
You can change it to a relative url on your site.