I originally had an IIS hosted Nancy application which had a custom error page Errors\500.html. Inside the Errors folder I had a Web.config file that removed the Nancy handler so that the error pages could be served.
There were two types of errors that I handled:
An error while initializing the Nancy Framework or a Nancy module would be handled by Application_Error() in Global.asax.
Any error while running a Nancy route would be handled by a custom Nancy IStatusCodeHandler implementation.
After switching to using Nancy.Owin Application_Error() is no being longer called.
I have tried a few variations of Configuration() in Startup.cs such as:
app.UseNancy(options => options.PassThroughWhenStatusCodesAre(HttpStatusCode.InternalServerError));
But I cannot get Application_Error() to be called.
I have tried creating a custom middleware to handle the exception, but this only works for exceptions while running a route and not if there is a problem loading a Nancy module:
app.UseNancy(options => options.PassThroughWhenStatusCodesAre(HttpStatusCode.InternalServerError));
app.Use<MyCustomExceptionMiddleware>();
How can I get my custom error pages loading (preferably still using Application_Error())?
Using Nancy 0.22.2, Owin 1.0 and Microsoft.Owin.Host.SystemWeb 3.0.0.
Application_Error() is not called when using OWIN.
Related
I am trying to host a .net core application on A2hosting shared hosting windows option, which uses IIS. However, once I used UserSecretsId in the .csproj file for the secret manager, I was getting the 502.5 error. This is odd since production doesn't use the secret manager. After doing some digging I found adding the following line in my .csproj file gets rid of the 502.5 error again:
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
Now, I need to store my secrets outside the web folder. I am trying to use the following code in my program.cs to set this up:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseConfiguration(new ConfigurationBuilder()
.AddJsonFile("<path here>") // line causing issue
.Build())
.Build();
This code brings back the error 502.5. When I comment out the AddJsonFile line alone, the error is gone. I was trying to understand what is wrong with AddJsonFile.
In conclusion, the issue seems to revolve around IConfiguration (with secret manager and AddJsonFile).
Any idea how I can get the AddJsonFile function working? Any good alternates to access an external json file? I am trying for something that is not messy like reading a while file and serializing it into AddInMemoryCollection function. Is the a way to log the errors shown as 502.5? I have noticed that with this errors, middlewares don't run. This means I can't use the ILogger in them.
This error was no longer shown when AddJsonFile("<path here>") showed a valid path. I could use the overload AddJsonFile("<path here>", true) which would ignore this function if the file is not found. This way the 502.5 was resolved once the path was valid. It is however still a mystery as to how an invalid path shows a 502.5 error. I am also not sure if this has something to do with the configuration package.
This was posted back in August https://social.msdn.microsoft.com/Forums/expression/en-US/c3e9f882-541f-48a2-a856-956ad3383f67/running-an-aspnet-core-pipeline-using-azure-functions
He talks about using a catch-all function and then somehow running the HttpRequestMessage through Asp.Net Core
How can I do this? With functions 2, using core, I can do things like add a Razor Page to my functions app. But if I try to return the View it throws an internal server error.
How can I call a Controller myself, and then get an IActionResult value back?
I've been using Backload along JQuery File Upload plugin for over a year now, and it has been working great with my old site using MVC 4 with Simple Membership and backload 1.9.3.0, but when I upgraded my site to MVC 5 and ASP.NET Identity, and backload 1.9.3.1, I started getting problems with backload, I keep getting:
Failed to load resource: the server responded with a status of 500 (Internal Server Error) from the controller when calling http://xxx/Backload/UploadHandler?objectContext=xx
.
When I traced the problem, I found that the problem originated during the Authorization process, which then throws an exception:
Backload Error: 10030080 : Exception occured in Authorization Manager: Object reference not set to an instance of an object..
And then I get the aforementioned response on the browser and the files don't get displayed by Jquery File Upload plugin since it didn't receive anything but an internal server error back from the controller.
I think the problem is that it is trying to get user roles through using System.Web.Security.Roles. I tried to cancel the authorization process but that never seems to work, I've tried the handler from Example 12 on their documentation but it never seems to reach the handler_AuthorizeRequestStarted method because I think the exception gets thrown before that step.
It's a shame if they don't address this problem soon, I really liked their approach.
I got it to work through specifying in the appSettings section of web.config the two following entries:
<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false" />
After that everything worked just like before. In fairness I think that these issues are related to ASP.Net Identity rather than to Backload server backend.
I have an ASP.NET MVC 4 site running perfectly well in an Azure WebRole. The ASP.NET MVC project was started on its own, after which I added an Azure Cloud Service project to the solution and added the ASP.NET project/site as one of the 'roles' of the service (so it shows up in the 'Roles' folder).
My problem is that I would like to have working a WebRole.cs file within the ASP.NET MVC project, but no matter what I've tried to do, it appears that when deployed, it just never gets called. OnStart and the override of Run (which I know, must never leave the loop) -- these just apparently never get called.
But if you startup a new CloudService project and add, at that time from the start, an ASP.NET MVC project, it automatically has a WebRole.cs file in it, so my guess is that I need to configure something somewhere for the WebRole.cs (actually speaking, the WebRole class, which inherits RoleEntryPoint) to get called. What might that be?
using System;
using System.Web;
//using Microsoft.WindowsAzure.StorageClient;
using System.Diagnostics;
using System.Threading;
namespace Us.WebUI
{
public class WebRole : Microsoft.WindowsAzure.ServiceRuntime.RoleEntryPoint
{
public override bool OnStart()
{
return true; //return base.OnStart(); // CALL THIS???
}
public override void Run()
{
while (true) {
Thread.Sleep(TimeSpan.FromSeconds(30));
try {
EmailFuncs.SendEmailToUs("An email from our WebRole?????", "Email me this, email me that.");
}
catch { }
}
}
}
}
UPDATE: Thanks, the question has been answered. But I will add: On doing this, while it clearly was working (fully deployed and in emulator), that suddenly I was having problems doing a full publish of the site. After a azure publish took 3 hours:
Verifying storage account 'xyz'... > Uploading Package... > - Updating... [stayed here for 3 hours], it failed with this error: The server encountered an internal error. Please retry the request. So one thing I was wondering is, did I need to override OnStop in WebRole.cs?
UPDATE 2: Those previous problems were fixed, and had nothing to do with this issue. Actually, I've learned this: If you ever have any warnings generated in your build, Azure often will not work with them even when they don't cause problems locally or in other hosts. Since then, I've been much more studious to tackling build warnings (but critical to this is turning off with warning codes the many warning types you want to ignore!).
Adding a class to your Web Project which inherits from RoleEntryPoint is sufficient, it should just work. Did you try setting a breakpoint in the emulator?
What you might be experiencing is that EmailFuncs.SendEmailToUs requires info from the app/web.config and that this info is not available. You need to know that your WebRole class runs in a different process (not your web application), meaning it's not using your web.config. If you want the WebRole.cs to read info from the configuration file, you'll need to add these settings in WaIISHost.exe.config
I using UrlRewritingNet dll from http://www.urlrewriting.net/ But I got the 404.0 not found error:
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Here is Handle mapping of StaticFile handler
http://imageshack.us/a/img163/5455/31274006.png
I've configured the same code, web.config with IIS 6 (uncheck Check for file exists) and it works.
I've tried many ways I get from another posts but it didn't work.
Any tip about this case?
//Since I'm *nix admin so maybe I lack some important points to make a proper question, sorry about that, if you need any info please let me know.
TIA.