The JSON convert error. Is there the way to avoid using controller for server-side blazor?

The first question is - is it possible to avoid using controller for server-side blazor application? You did it for FileUpload, but there is not still shown the way to get file and directory data without controller for File Navigator.

I have the next error of Navigator first load: 

I have checked the data sent from controller, there is not any <. What is the reason of error could be?


Attachment: controllerresponse_17e2cbca.zip

5 Replies

IL Indhumathy Loganathan Syncfusion Team January 24, 2022 02:11 PM UTC

Hi Stanislav, 
 
Greetings from Syncfusion support. 
 
We have handled all the file operations of the File Manager in the controller part. To display the files and folders inside the File Manager, a HttpClient call will be sent from the client to the server where we perform a read operation, then display the files and folders. We have retrieved the files from the specified location by using the API controller. Without the service controller, the File Manager couldn’t retrieve the files from the mentioned path.  
 
The reported error occurs due to the authentication done in your Blazor sample. We have used HttpClient for web API calls in the File Manager to perform all file operations. While using Windows authentication, our service controller is not triggered. We have raised a query on GitHub for a fix and are tracking it closely for the solution. 

 
However, by following the below steps, you can achieve authentication for Blazor File Manager. 
 
 
For your reference, we have prepared a sample and attached in the following link. 


In the sample, we have rendered Blazor File Manager, which will be visible to authorized users (logged in) only. Check the below blog to understand about Blazor server authentication. 


Please let us know if you need any further assistance. 

Regards, 
Indhumathy L 



SG Stanislav Gordenko January 27, 2022 09:05 AM UTC

Hi Indhumathy,

On my application an access to page with file navigator is not allowed to users which are not authorized and which role is below administrator.

Is there any other reason to get this error?

In my first message I have added response from controller, and there is not any error here. What should I check more?

If you will need to make the sample, please, use NET6 framework, otherwise I cannot run it.


When received your answer I have attached JWT bearer security to controller and token to request query strings. Result is the same error.



SA Shameer Ali Baig Sulaiman Ali Baig Syncfusion Team January 28, 2022 02:38 PM UTC

Hi Stanislav, 

Greetings from Syncfusion support. 

We have updated our shared sample in the last update to .NET 6.0 version.  
 
 
We were unable to predict the problems which you are facing in your application. 

If possible share us the following details regarding your reported problem from your application. 

  • Share us the video footage you reported problem.
  • Please, share a sample by replicating your reported problem.
  • Share us the authentication details which you have used in your application.

This information would help to provide you the prompt solution. 

Regards, 
Sameer Ali Baig S. 



SG Stanislav Gordenko January 30, 2022 08:41 AM UTC

Finally I have understood that the reason of wrong answer was xml-data returned by File Controller. Preference of XML was set on application level.

I have added 

[Produces("text/plain")] to the File Controller and everything started to work.


For all which is interesting about authorization of files.

I use jwt bearer to control which files could be shown based on user roles.

File Controller statrs with:

    [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]

    [Route("[controller]")]

    [EnableCors("AllowAllOrigins")] 

    [Produces("text/plain")]

    public class FileController : ControllerBase


It makes possible to get User.Identity.Name and filter file list based on user role. 


To embed jwt-bearer to File Navigator request:

                <FileManagerAjaxSettings Url="@("/File/FileOperations".AddQueryParameter("access_token", Token))"

                                         DownloadUrl="@("/File/Download".AddQueryParameter("access_token", Token))"

                                         GetImageUrl="@("/File/GetImage".AddQueryParameter("access_token", Token))"

                                         UploadUrl="@("/File/Upload".AddQueryParameter("access_token", Token))" />




KR Keerthana Rajendran Syncfusion Team January 31, 2022 01:09 PM UTC

Hi Stanislav, 
 
Thanks for the suggestions. We are happy to hear that your issue is resolved. Please get back to us if you need further assistance. 
 
Regards, 
Keerthana R. 


Loader.
Up arrow icon