I have a web application in which I applied URL rewriting .I have also applied custom 404 error page with web.config settings and also with global.asax. Both of them working locally,but not on live server.Is there a GoDaddy issue where site has deployed?
Web.config code
<customErrors mode="On" defaultRedirect="" >
<error statusCode="404" redirect="~/ErrorPages/404.aspx" />
</customErrors>
Global.asax code
Exception ex = Server.GetLastError();
if (ex is HttpException)
{
if (((HttpException)(ex)).GetHttpCode() == 404)
{
Server.ClearError();
Server.Transfer("~/ErrorPages/404.aspx");
}
}
I have also tried for following
<system.webServer>
<httpErrorserrorMode=“Custom“ >
<removestatusCode=“404“ subStatusCode=“-1“/>
<errorstatusCode=“404“ path=“~/ErrorPages/404.aspx“ responseMode=“ExecuteURL“ />
</httpErrors>
</system.webServer>
I have also tried setting custom 404 page in godaddy but no result.What will be the solution of this problem?Thanks in advance.
Tried for setting custom 404 page in godaddy's control panel and waited for some time.Then its working for me.
Related
I need help with settings. It's never use provided page for error 404.
This is my customErrors web.config block:
<customErrors mode="On" defaultRedirect="/systemerror.aspx">
<error statusCode="404" redirect="/404.aspx" />
</customErrors>
I have these page created and they works well if I call them by url, but when I write in url non-existent page like:http://www.mysite.com/asdfasdasd I am getting:
Server Error
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.
It's not use my custom error page 404.aspx, how can I fix this ?
If you are using IIS 7, try:
Response.TrySkipIisCustomErrors = true;
Refer:
HttpResponse.TrySkipIisCustomErrors Property :Gets or sets a value that specifies whether IIS 7.0 custom errors are disabled.
You are missing ~
<customErrors mode="On" defaultRedirect="~/systemerror.aspx">
<error statusCode="404" redirect="~/404.aspx" />
</customErrors>
This should work. Let me know.
i am trying to put customError tag in web.config file..
still it doesn't redirect to default url
http://www.lacopainn.com/page/2/?p=dbasndwefxknyafc&wpmp_switcher=mobile
here is my site. when we enter this url it shows error of
Not Found
The requested document was not found on this server.
how can i handle this error and redirect to detault page??
please help
you need to put following tag under System.web tag in your webconfig file
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="default.aspx" />
</customErrors>
</system.web>
Hope it will fix your problem.
This question already exists:
Closed 10 years ago.
Possible Duplicate:
iis 7.5 hijacking 404
I'm running a .net 4.0 site over a IIS 7.5.
I have added the custom errors section to my webconfig:
<system.web>
<customErrors defaultRedirect="/error" mode="On">
<error statusCode="404" redirect="/error?code=404"/>
<error statusCode="500" redirect="/error?code=500"/>
</customErrors>
</system.web>
The custom errors are working. Any internal server errors are redirected to /error?code=500 and any throw new HttpException(404, "Not found"), when a missing parameter is found, are redirected to /error?code=404. But any non existing url path still throws the standard IIS 404 page, not my custom 404.
Any tip?
That happened to me once in IIS 7, the solution was to configure the IIS-Application error pages:
Open IIS
Select your applciaiton
Open Error Pages under the IIS section
In the right panel named Actions, click Edit Feature Settings
To test choose:
Custom Error Pages
Accept the changes
Restart IIS
That did the trick in my case
Edit 1
Remember that the customErrors section works only for requests handled by ASP.Net the static requests like html pages will still redirect to the 404 error page configured in IIS
However, you could override this behavior in your own config file:
For more info
<configuration>
<system.webServer>
<httpErrors existingResponse="Replace" errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="GenericError.aspx" responseMode="Redirect" />
</httpErrors>
</system.webServer>
</configuration>
You also might need to mark the above section as updatable:
Open the file:
C:\Windows\System32\inetsrv\config\applicationHost.config
And change:
<section name="httpErrors" overrideModeDefault="Deny" />
To:
<section name="httpErrors" overrideModeDefault="Allow" />
You can handle it in Global.asax or in IHttpModule.
Exception currentException = Server.GetLastError();
HttpException httpException = currentException as HttpException;
if (httpException != null && httpException.GetHttpCode() == 404)
{
// redirect
}
Check http://learn.iis.net/page.aspx/508/wildcard-script-mapping-and-iis-integrated-pipeline/ for info how to setup wildcard mapping, so all requests are handled by asp.net.
In my ASP.NET 3.5 Website which is published in shared hosting provider , I've configured my web.config file like this :
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="AccessDenied.htm"/>
<error statusCode="404" redirect="FileNotFound.htm"/>
</customErrors>
If the user request pages that doesn't exist ( like "www.example.com/NotExistPage.aspx" ) , user will be redirected to FileNotFound.htm page as we expect .
But if the user request some address like : "www.example.com/NotExistDirectory" without .aspx extension , the user will encounter IIS 7.5 Error page :
HTTP Error 404.0 - Not Found The
resource you are looking for has been
removed, had its name changed, or is
temporarily unavailable.
Detialed error information :
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Requested URL http://www.example.com:80/NotExistDirectory
Physical Path D:\Websites\example\example.com\wwwroot\NotExistDirectory
Logon Method Anonymous
Logon User Anonymous
This is a yellow page which is not user friendly and we didn't expect .
I'm wondering setting customeError in webconfig doesn't support this type of address or not ? How can i prevent users seeing this yellow page .
Edit :
Thanks to David's answer , But I found the actual reason and correct solution. Please see my answer.
#Mostafa: I faced the exact same problem. I found out it can be solved by adding the following to the web.config file:
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/MyErrorPage.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
Thanks to #David solution, But the reason and complete solution are as below:
By setting customErrors mode to "On" it's only working when we get an exception in ASP.NET application, While when we trying to reach nonExistingdirectory Or notExsitingStaticResouce, IIS renders a 404 error and it does not reach to asp.net runtime and served by IIS directly.
So we need to add configuration for IIS as below in Web.config:
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="~/404.html" responseMode="File" />
</httpErrors>
<system.webServer>
It's important to set responseMode to "File", Otherwise status code automatically would change from 404 to 200. So from the client's perspective, they don't get the actual 404 status code.
This is because the ASP.Net module is configured to handle certain file extensions. IIS determines that .aspx must be handled by the ASP.Net module and then the customerrors section in the web.config ( and indeed web.config itself) kicks in.
Since you have requested a page not even configured for ASP.Net, IIS handles it on its own without passing the request on.
For any other files other than .aspx, you can configure this in IIS:
http://www.xefteri.com/articles/show.cfm?id=11
First, directory url must posess trailing slash, otherwise its just an extensionless file.
www.mysite.com/NotExistDirectory/
Second, ASP.net IIS module is handler for ASP MIME types only, so directory is leftover for web server.
Third, customerror is part of system.web is part of ASP.net configuration
and httperror is part of system.webserver is part of IIS configuration.
Assuming http module defaults in IIS configuration httperror will work with custom error for non-existing directory.
Here's my web.config customErrors section (you'll notice I've switched the mode to 'On' so I can see the redirect on my localhost):
<customErrors defaultRedirect="~/Application/ServerError.aspx" mode="On" redirectMode="ResponseRewrite">
<error statusCode="403" redirect="~/Secure/AccessDenied.aspx" />
</customErrors>
and here's the code that throws:
Catch adEx As AccessDeniedException
Throw New HttpException(DirectCast(HttpStatusCode.Forbidden, Integer), adEx.Message)
End Try
and here's what I end up with:
Which is not my pretty AccessDenied.aspx page but it is a forbidden error page so at least I know my throw is working.
I've removed the entry for 403 in IIS (7.0) as a desperate last attempt and unsuprisingly that made no difference.
I've run out of ideas now so any suggestions will be gratefully appreciated!
In fact, your aspx page may not be executing at all.
Go to IIS.
Go to your default website properties.
Click on the Home Directory Tab
Click the configuration button.
Now, check if a .aspx page is registered there.
You need to specify existingResponse="PassThrough" in the system.webServer section of the httpErrors element.
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>