Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Ajax Call to Controller in different Area result in 500 error. #10910


User avatar
0
moonch created
  • version .NET 6
  • product type MVC Core
  • .NET Core

Making Ajax Post Trying to hit an action method for a controller in diferent area fails with 500 error. Same code was working in ABP Boilerplate and ASP NET Core Project but not in Zero, Also it works in case the ACTION method is in same Calling Controller. So URL without area works ok.

var model = { "SectionId": @FileUploaderConsts.HR_CV, "ParentId": recordId }; $.ajax({ type: "POST", url: '@Url.Action("Async_GetPdfFile", "DocumentsAndFiles", new { area = "DocumentManagement" })', dataType: "json", data: model, success: function (pdf) { alert("OK"); }

` [Area("DocumentManagement")] [Route("DocumentManagement/[controller]/[action]")] [AllowAnonymous] public class DocumentsAndFilesController : ArchiroxControllerBase {

    [HttpPost]
    [DontWrapResult]
    public async Task<DM_PDF_ViewModel> Async_GetPdfFile(DM_AdditionalFileInfo_ViewModel model)
    {
        return await _iDM_File_Handler_AppService.GetPdfBlob(model.ParentId, model.SectionId);
    }

` the url:"/DocumentManagement/DocumentsAndFiles/Async_GetPdfFile" is not being hit, however if the Async_GetPdfFile is local the POST is success. The logged in user is admin which has all the permissions, and i tried decorating the DocumentsAndFiles with [AllowAnonymous] to eliminate the possibilty of permission issues, the url construction looks OK, Please see attached image.

Your help is appreciated.


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Could you check your server side log file ? It is located under App_Data/Logs folder with Logs.txt name.

  • User Avatar
    0
    moonch created

    ok the issue was in a FileAppService not registering the ConfigrationFile, One Issue is Before injecting IConfigration to read from appsetting.json, I also tried injecting IConfigurationRoot this throws error, Can you please advise how to get appsetting.json values IN ASP NET ZERO , there is little to no documentation on the subject.

    ` private readonly IConfiguration _configuration;

        public ArchiroxApplicationModule(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public override void PreInitialize()
        {
            Configuration.Authorization.Providers.Add<ArchiroxAuthorizationProvider>();
        }`
        
        public method()
        {
            var key = _configuration.GetValue&lt;string&gt;("Azure:AccountName"); //Always NULL
        }
        
        
        //THE APPSETTING.json
        
        }
        "Azure":
        {
            "ConnectionStrings":"somestringt",
            "AccessKey": "somestring2",
            "AccountName": "somestring2"
         }
        }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can do it as shown below;

    public AbpZeroTemplateWebCoreModule(IWebHostEnvironment env)
            {
                _env = env;
                _appConfiguration = env.GetAppConfiguration();
            }
    

    and access the configuration like this;

    _appConfiguration["Azure:AccountName"]