Set withCredentials = true on SfDataManager in Grid

I am using an OdataV4Adaptor in my grid and would like to set the withCredentials to true.  How can I do this?

<SfGrid TValue="MyTable" AllowPaging="true" AllowSorting="true" AllowFiltering="true" Toolbar="@(new List<string>() { "Add""Edit""Delete""Cancel""Update" })">
  <SfDataManager Url="odata/MyTable" CrossDomain="true" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>
</SfGrid>

Thanks,
Paul

5 Replies

VN Vignesh Natarajan Syncfusion Team August 21, 2020 06:27 AM UTC

Hi Paul,  
 
Thanks for contacting Syncfusion support.  
 
Query: “I am using an OdataV4Adaptor in my grid and would like to set the withCredentials to true.  How can I do this? 
 
We suspect that you want to authorize the server by passing the value along with DataManager Url. We suggest you to achieve your requirement by passing the value as header using Headers property of Datamanager. Refer our UG documentation for your reference 
 
 
If above solution does not resolve your query or if we misunderstood your query, kindly get back to us with more details.   
 
Regards, 
Vignesh Natarajan 



PA paul August 21, 2020 01:34 PM UTC

This doesn't seem to help.  The trouble I'm running into is when trying to test from localhost.  It seems to work fine on the published server.  How can I access the OdataV4Adaptor's BeforeSend using the DataManager in the grid?

https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor~Syncfusion.Blazor.Data.ODataV4Adaptor~BeforeSend.html

Thanks,
Paul


RS Renjith Singh Rajendran Syncfusion Team August 26, 2020 08:32 AM UTC

Hi Paul, 
 
Thanks for your update. 
 
Based on this scenario, we suggest you to use custom message handler. With this custom message handler and Microsoft.JSInterop, we have send the request to Javascript function and write the request in browser console. Now, you can view the request in browser console. Please find the below codes for your reference. 
 
[Startup.cs] 
 
using System.IO; 
using Microsoft.JSInterop; 
 
namespace BlazorApp1 
{ 
    public class Startup 
    { 
        public Startup(IConfiguration configuration) 
        { 
            Configuration = configuration; 
        } 
        public IConfiguration Configuration { get; } 
 
        // This method gets called by the runtime. Use this method to add services to the container. 
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 
        public void ConfigureServices(IServiceCollection services) 
        { 
            services.AddRazorPages(); 
            services.AddServerSideBlazor(); 
            services.AddSingleton<WeatherForecastService>(); 
            services.AddScoped<HttpClient>(s => 
            { 
                var ijs = s.GetService<IJSRuntime>(); 
                var context = s.GetRequiredService<IHttpContextAccessor>(); 
                var navManager = s.GetRequiredService<NavigationManager>(); 
                Uri hostUri = null; 
                try 
                { 
                    hostUri = new Uri(navManager.BaseUri); 
                } 
                catch (Exception) 
                { 
                    . . . 
               } 
                var cookieContainer = new CookieContainer(); 
                HttpClient client = HttpClientFactory.Create(new MessageHandler1(ijs));   //crate client instance by using this way 
                client.BaseAddress = hostUri; 
                client.DefaultRequestHeaders.Add("Accept", "application/json"); 
                client.DefaultRequestHeaders.Add("Accept-Encoding", "br, gzip, deflate"); 
 
                if (context != null) 
                { 
                    . . . 
               } 
                return client; 
            }); 
            services.AddSyncfusionBlazor(false); 
       } 
         //add this Custom message handler 
         //add a new class MessageHandler  
         public class MessageHandler1 : DelegatingHandler 
        { 
            private int _count = 0; 
            private IJSRuntime ijs; 
 
            public MessageHandler1() 
            { 
            } 
 
            public MessageHandler1(IJSRuntime ijs) 
            { 
                this.ijs = ijs; 
            } 
 
            protected override Task<HttpResponseMessage> SendAsync( 
                HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) 
            { 
                ijs.InvokeAsync<HttpRequestMessage>("handleError", request);   //here we have send the request to js function and print the request in brower console 
                System.Threading.Interlocked.Increment(ref _count); 
                request.Headers.Add("X-Custom-Header", _count.ToString()); 
                return base.SendAsync(request, cancellationToken); 
            } 
        } 
 
        . . . 
   } 
} 
 
 
Add a JavaScript file in wwwroot folder and add the below codes in that file. Also ensure to refer this JS file in your application. Find the below code  snippets. 
 
[debug.js] 
 
function handleError(request) { 
    console.log(request); 
} 
 
 
By using the above steps, you can print the request in browser console window. Find the screenshot for your reference. 

 

Also enable SetBrowserRequestCredentials as Include. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



PA paul August 27, 2020 03:01 PM UTC

Unfortunately, I'm not sure that helps me.  I'm using a server side app and I just need to access the methods of the adaptor that is associated with the SfDataManager.  Is there a way to override the Adaptor's methods?  Can the Adaptors settings and methods be configured through the DataManager somehow?  Maybe on page or grid initialization?

Thanks,
Paul


RS Renjith Singh Rajendran Syncfusion Team September 1, 2020 11:13 AM UTC

Hi Paul, 

Currently we do not have support to override or set BeforeSend method of DataManager. We have considered this as a usability feature improvement and logged an usability feature improvement task for the same “Provide support to override or set BeforeSend method of DataManager”. We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts.   
   
You can now track the current status of this feature request here.   
   
At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision and technological feasibility. It will be implemented in any of our upcoming releases.   

You can communicate with us regarding the open features any time using our above Feature Report page. 
 
Regards, 
Renjith Singh Rajendran 


Loader.
Up arrow icon