So what happens is that if I forget a registration of a class in autofac container, I will be taken to one of the above pages, however, I don't see the actual error message to print.
In my error templates error view I define @model HandleErrorInfo at the top and in the body I try to access the error using @Model.Exception.Message. But @Model.Exception.Message throws an exception with null object reference.
What do I need to do to have access to the exception?
When you use <customErrors> ASP.NET is unaware of how to pass the exception information into a view, it'll just load/redirect you to the error page. You can try below solution to send error model to view from controller :
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Thank you for the link and information. It was quite helpful. My error handling has some minor similarities with theirs. However, I did take some pointers from their code.
For example I wasn't doing Server.ClearError() and also the line that does:
var httpException = exception as HttpException;
In the Application_Error was setting the httpException to null even though there was a legitimate exception in var "exception". So if httpException is null but exception is not, I will
redirect to error page with the exception's message. It seems to work.
Member
6 Points
34 Posts
Errors Caused in Autofac Container
Jun 14, 2018 01:33 AM|b3hdad|LINK
Hi,
I am using MVC 5 and have configured my project to use Autofac. Things are working fine...mostly.
Now I have configured my web.config to handle errors like this:
So what happens is that if I forget a registration of a class in autofac container, I will be taken to one of the above pages, however, I don't see the actual error message to print.
In my error templates error view I define @model HandleErrorInfo at the top and in the body I try to access the error using @Model.Exception.Message. But @Model.Exception.Message throws an exception with null object reference.
What do I need to do to have access to the exception?
Thank you.
Behdad.
All-Star
18785 Points
3830 Posts
Microsoft
Re: Errors Caused in Autofac Container
Jun 15, 2018 02:48 AM|Nan Yu|LINK
Hi b3hdad,
When you use <customErrors> ASP.NET is unaware of how to pass the exception information into a view, it'll just load/redirect you to the error page. You can try below solution to send error model to view from controller :
https://stackoverflow.com/a/36003119/5751404
Best Regards,
Nan Yu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
6 Points
34 Posts
Re: Errors Caused in Autofac Container
Jun 15, 2018 06:50 AM|b3hdad|LINK
Hi Nan Yu,
Thank you for the link and information. It was quite helpful. My error handling has some minor similarities with theirs. However, I did take some pointers from their code.
For example I wasn't doing Server.ClearError() and also the line that does:
var httpException = exception as HttpException;
In the Application_Error was setting the httpException to null even though there was a legitimate exception in var "exception". So if httpException is null but exception is not, I will
redirect to error page with the exception's message. It seems to work.
Thanks again.
Kind Regards,
Behdad.