ASP.NET Core MVC : catch 503 error and redirect to view - asp.net-core-mvc

In my ASP.NET Core MVC application, I'm trying to catch and isolate 503 error which is coming from the API project, we are intentionally stopping the app pool for the API in order to get the error and instead of this screen:
I want to redirect to a specific view, for example /Home/Error, is there an option to do that in the configuration of the ASP.NET Core MVC project?

Your application running in (or being accessed through) the ASP.NET Core Module is the service that is reported to be unavailable by this error page.
The 503 is returned by IIS, not by your application. The whole reason the 503 is returned, is because your application doesn't respond to IIS, so even if you wanted to, you can't return it from your application.
See Custom Error Page for Http Error 503 to change the IIS 503 error page.

Related

How to Mimic Server Down(503) With Windows 8 Phone Emulator, IIS Express, Web Api?

Does anyone know how to get a 503 error to occur when doing a call from code in a windows phone application.
I tried by not running my web api project and just loading up and doing a call to that project but it just comes back 403 and not 503.
You can throw the 503 error with this line of code in your WebAPI controller:
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.ServiceUnavailable, "Service unavailable");

Using GWT getting 405 error message on IIS 7.5

I have inherited a project that is using GWT to post login information via a form. According to Firebug, its coming back with a 405 error.
I have tried the directions on: IIS 7.5, Web Service and HTTP 405 error
That didn't fix the problem. I turned on Failed Request tracking and this is the error that I see:
MODULE_SET_RESPONSE_ERROR_STATUS
Warning
ModuleName="StaticFileModule", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="405", HttpReason="Method Not Allowed", HttpSubStatus="0", ErrorCode="Incorrect function.
(0x80070001)", ConfigExceptionInfo=""
Thanks!

ASP.NET MVC erroring on some clients but not all

I have an ASP.NET MVC 3 site that works without error in the debugger and on a few other PCs. However on some clients/pc's I just get an error message when trying to access information:
Error.An error occurred while processing your request.
Any ideas why this doesn't happen all the time and any idea how to track down the problem?

Error executing child request for

In my MVC3 application I'm getting the above mention error when I try to handle a maximum request exceeded error.
I'm handling the exception at the application level. I'm trying to redirect to an error page that's located in the Shared folder of the views.
I'm using the code below to redirect to an error page if the request size is over the limit.
this.Server.ClearError();
this.Server.Transfer("~/Views/Shared/NotAuthorised.cshtml");
This is the error im getting.
Error executing child request for /SiteName/Views/Shared/NotAuthorised.cshtml
According to the Microsoft documentation (Error Executing Child Request" Error Message When You Use Server.Transfer or Server.Execute in ASP.NET Page) you cannot use Server.Transfer after an application level error.
Microsoft Internet Information Services (IIS) dispatches the
Server.Transfer or the Server.Execute request to the appropriate
Internet Server Application Programming Interface (ISAPI) extension
based on the extension of the requesting file. For example, a request
for an .aspx page is dispatched to the Aspnet_isapi.dll ISAPI
extension.
After the request is dispatched to appropriate ISAPI extension, the
ISAPI extension cannot call another ISAPI extension. You receive the
error message that is listed in the "Symptoms" section because the
Aspnet_isapi.dll file, which handles requests to ASP.NET pages, cannot
forward the request to the Asp.dll file, which handles requests to ASP
pages.
You can however use Response.Redirect(path) like this:
Response.Redirect("Home/About");

Running MVC3 application on server results in 403.14 response

I am trying to get an MVC3 application working on a Windows Server 2008 R2 box. The server is running IIS 7.5. The application is setup with anonymous authentication and a v4.0 framework application pool. I have given IUSR and IIS_IUSRS access to the directory until I switch to using a service account.
I have tried the following:
Registered ASP.NET 4 with IIS (%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -ir)
I have installed MVC3 on the server from http://www.asp.net/mvc/mvc3.
I am still receiving an HTTP 403.14 response: "HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory."
If I throw in a dummy index.html file, the page gets served. It seems to me like a module isn't intercepting the request to point the request to the home controller.
Answer: While MartinHN's answer did resolve the issue, it would result in a performance hit when serving static files. Thanks to his answer I started doing some searching and found that there is a IIS7 hotfix available which will allow ASP.NET 4 applications to handle extensionless URLs without running all modules for each request. The hotfix is available here: http://support.microsoft.com/kb/980368. After installing this hotfix my application was serving content as expected, without the Web.config change.
Might be one of the following...
Check your web.config for the line:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
...
</system.webServer>
And make sure that the application pool is set to the Integrated Pipiline.
You can also try to reset the Handler Mappings in IIS. Click the site --> Handler Mappings --> Revert to parent (link should be on the right sidebar).

Resources