Return Custom message from Controller fails when running in IIS

Return Custom message from Controller fails when running in IIS, It fails when it is working in IIS, but in development environment it works perfect, 
is there something missing in the publication of the app?. I have been trying to understand what happens for a long time.


<div>

    <h2>CARGOS</h2>

    <h6> DESCRIPCIÓN </h6>

 

    <ejs-grid id="Grid" locale="es" gridLines="Both" actionFailure="actionFailure" dataBound="dataBound" rowSelected="rowSelected" allowPaging="true" toolbar="toolbarItems" actionComplete="actionComplete" toolbarClick="toolbarClick">

        <e-data-manager url="/Cargos/UrlDataSource" adaptor="UrlAdaptor" insertUrl="/Cargos/Insert" updateUrl="/Cargos/Update" removeUrl="/Cargos/Delete"></e-data-manager>

        <e-grid-searchsettings fields="@(new string[] { "Codigo","Nombre"})"></e-grid-searchsettings>

        <e-grid-editSettings allowAdding="true" allowEditing="true" allowDeleting="true" showDeleteConfirmDialog="true" mode="Dialog" template='#dialogtemplate'></e-grid-editSettings>

        <e-grid-pagesettings pageCount="5"></e-grid-pagesettings>

        <e-grid-columns>

            <e-grid-column field="Id" isPrimaryKey="true" visible="false"></e-grid-column>

            <e-grid-column field="Codigo" headerText="Código" width="20"></e-grid-column>

            <e-grid-column field="Nombre" headerText="Nombre" width="80"></e-grid-column>

            <e-grid-column field="Basico" headerText="Básico" width="40" textAlign="Right" editType="numericedit" format="N2"></e-grid-column>

        </e-grid-columns>

    </ejs-grid>

 

</div>

 

…..



public IActionResult Insert([FromBody]CRUDModel<CargoSet> param)

        {

            var obj = _context.CargoSet.Where(o => o.Codigo == param.Value.Codigo && o.Suscriptor == Globals.gSuscriptor).SingleOrDefault();

 

            if (obj != null) //Check already exisiting

            {

               throw new Exception(string.Format("El código {0} ya se ha asignado", param.Value.Codigo));//Add custom exception message    

            }

 

 

            // Usuario Adiciona

            param.Value.Suscriptor = Globals.gSuscriptor;

            param.Value.CreatedBy = Globals.gUsuario;

            param.Value.Created = DateTime.Now;

 

            _context.Add(param.Value);

            _context.SaveChanges();

 

            return Json(param.Value);

        }

 

function actionFailure(args) {

 

        var errorMessage = args.error[0].error.responseText.split("Exception:")[1].split('at')[0];  //extract the message from args

 

        var span = document.createElement('span');

        span.style.color = '#FF0000';

 

        span.innerHTML = errorMessage;

 

        ej.popups.DialogUtility.alert({

            title: 'Atención',

            content: span,

            position: { X: 50, Y: 150 },

            okButton: { text: 'OK' },

            showCloseIcon: true,

            closeOnEscape: true

        });

 

    }

LOG

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]

 

      An unhandled exception has occurred while executing the request.

 

System.Exception: El código 02 ya se ha asignado

 

   at VigiaNet2Core.Controllers.CargosController.Insert(CRUDModel`1 param) in C:\Projects\VigiaNet2Core\VigiaNet2Core\Controllers\CargosController.cs:line 127

 

   at lambda_method(Closure , Object , Object[] )

 

   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

 

--- End of stack trace from previous location where exception was thrown ---

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()

 

--- End of stack trace from previous location where exception was thrown ---

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()

 

--- End of stack trace from previous location where exception was thrown ---

 

   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)

 

   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)

 

   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)

 

   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)

 

   at DevExpress.AspNetCore.Internal.BinaryStorageMiddleware.Invoke(HttpContext httpContext)

 

   at DevExpress.AspNetCore.Internal.ResourceManagerMiddleware.Invoke(HttpContext httpContext)

 

   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

 

Please help me.


5 Replies

RS Rajapandiyan Settu Syncfusion Team March 27, 2020 02:40 PM UTC

Hi Luis, 

Greetings from syncfusion support. 

Query 1: Return Custom message from Controller fails when running in IIS, It fails when it is working in IIS, but in development environment it works perfect,
is there something missing in the publication of the app?. I have been trying to understand what happens for a long time.
 

We have validated the provided details and based on that we have ran the sample in IIS. While running the sample in IIS we are able to trigger the actionFailure event. Please refer the below video. 
 

If you still face the same problem please ensure that you have get any error in the console. If yes share the screenshot of the issue with us. 

Regards, 
Rajapandiyan S. 



LU luis March 28, 2020 03:38 AM UTC






Thank you for your effectiveness, I attached what was requested. there is shown in error. I am awaiting your solution.





LU luis March 28, 2020 03:43 AM UTC


ajax.js:84 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

(anonymous) @ ajax.js:84

e.send @ ajax.js:62

loadCulture @ Cargos:92

loadCultureFiles @ Cargos:96


In case it doesn't look good ..

(anonymous) @ Cargos:80

ajax.js:94 POST http://localhost:90/Cargos/Insert 500 (Internal Server Error)

(anonymous) @ ajax.js:94

e.send @ ajax.js:62

e.doAjaxRequest @ manager.js:472

e.insert @ manager.js:393

e.getData @ data.js:333

e.refreshDataManager @ render.js:219

(anonymous) @ render.js:140

e.notify @ observer.js:102

e.trigger @ base.js:181

e.refresh @ render.js:99

e.notify @ observer.js:99

t.notify @ component.js:204

e.endEdit @ normal-edit.js:218

t.endEdit @ dialog-edit.js:40

e.endEditing @ edit.js:290

e.endEdit @ edit.js:219

t.endEdit @ grid.js:2233

e.btnClick @ dialog-edit-renderer.js:69

Cargos:497 Uncaught (in promise) TypeError: Cannot read property 'split' of undefined

    at t.actionFailure (Cargos:497)

    at e.notify (observer.js:99)

    at t.e.trigger (base.js:181)

    at e.dataManagerFailure (render.js:474)

    at render.js:243


In case it doesn't look good ..


LU luis March 28, 2020 11:34 PM UTC


I have temporarily solved it by modifying the configuration file as a developer so that it sends the error information in a more descriptive way and not the standard one.
That way if you find error information to filter and present.

...
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>

......



If there is a better way I would really appreciate it.


RS Rajapandiyan Settu Syncfusion Team March 30, 2020 01:01 PM UTC

Hi luis, 
 
Thanks for your update. 
 
Query #1: Cargos:497 Uncaught (in promise) TypeError: Cannot read property 'split' of undefined 
 
From your shared screenshot we could see that you can able to trigger the actionFailure event but unable to get the error message you have passed from the server when running the sample in IIS. In EJ2 Grid’s actionFailure event, sometimes the error message has sent as an object. So we suggest you to debug the error value in the arguments of actionFailure event to get the error message. Please refer the below code. 
 
 
function actionFailure(args) { 
        console.log("debug the error in the args"); 
        console.log(args.error);  
    } 
 
 
Query #2: I have temporarily solved it by modifying the configuration file as a developer so that it sends the error information in a more descriptive way and not the standard one.
That way if you find error information to filter and present. If there is a better way I would really appreciate it.
 
 
We are glad that you are resolved the reported problem.  
 
Please ensure the above suggestion.  And please share the screenshot about the actionFailure event if you have faced any issue. 
 
Regards, 
Rajapandiyan S. 


Loader.
Up arrow icon