SaaS CMS has officially launched! Learn more now.

Permissions for functions doesn't show error

Vote:
 

Hi, 

I have a small problem. I want to see the error on the test server, and I am a part of admins in Permissions for Functions so I should see the detailed error, but since we added in the config file custom 500.html for all server errors:


      
      
      
      
      
      
    

I also see just that page and not the whole error. 

If I add 

all users get the whole errors. Is there some solution for this?

Thanks in advance :)

Simona

#115263
Jan 12, 2015 17:11
Vote:
 

I think IIS (web.config) settings are overwritten and enforced before actually EPiServer can handle that.

If you really need custom 500 error page for rest of the world and for admins - show detailed view of the error, you could create a bit more complex 500 error page and behind the scene check permissions for the current user - if he/she is able to see detailed messages.

using EPiServer.Security

..

if (PrincipalInfo.Current.IsPermitted(Permission.DetailedErrorMessage))

If user is permitted you can use exception manager to render detailed error page:

ServiceLocator.Current.GetInstance<IExceptionManager>().RenderHttpRuntimeError(exception);
#115272
Jan 12, 2015 21:24
Vote:
 

Ohhhh Great!!!!

Thanks a lot!! 

#115287
Jan 13, 2015 10:36
Vote:
 

And how should I get the error message in the controller action? :)

#115303
Jan 13, 2015 14:49
Vote:
 

I think you have to check Server.GetLastError() or similar.

#115309
Jan 13, 2015 15:53
Vote:
 

Yeah, in the meantime I've found that but it is null.

I found this post: 

http://sunali.com/en/2008/01/16/why-does-server-getlasterror-return-null/

I've added globalErrorHandling="Off" in episerver.config but it still gives me null. I am not sure if I should try with Context.AllErrors because the post is from 2008 :)

#115311
Jan 13, 2015 16:13
Vote:
 

investigate AllErrors collection..

#115348
Jan 13, 2015 17:33
Vote:
 

I tried with it but it is also null. I think that Episerver handles that error and I have to find out how. 

Thanks anyway :)

#115349
Jan 13, 2015 17:37
Vote:
 

Try to go upwards from EPiServer.Global.OnError event handler :)

#115350
Jan 13, 2015 17:40
Vote:
 

At the end, this is how I done it:

  private void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

            var exc = Server.GetLastError();
            if (exc != null)
            {
                if (PrincipalInfo.Current.IsPermitted(SystemPermissions.DetailedErrorMessage))
                {
                    ServiceLocator.Current.GetInstance<IExceptionManager>().RenderHttpRuntimeError(exc);
                }
                else
                {
                    var httpException = exc as HttpException ?? new HttpException(500, StringConstants.InternalServerError, exc);
                    Response.Clear();
                    switch (httpException.GetHttpCode())
                    {
                        case 403:
                            Response.Redirect("~/403.html", true);
                            break;
                        case 404:
                            Response.Redirect("~/404.html", true);
                            break;
                        default:
                            Response.Redirect("~/500.html", true);
                            break;
                    }
                    Server.ClearError();
                }
            }

        }

I removed the code from the web config.

I am not sure if it is the best solution but it works for now. If anybody has some better solution, please share :)

Thanks Valdis :)

#115393
Edited, Jan 14, 2015 13:58
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.