X-CSRF-TOKEN as datamanager headers

Hello i need to add header X-CSRF-TOKEN while using datamanager.

Headers = new object[]{ new { X-CSRF-TOKEN = token } }  - error

Headers = new object[]{ new { headerName = token } }  - output  headerName : value but not X-CSRF-TOKEN :value

Headers = new object[]{ new { myData = token } }   - output  myData : value OK, but i need  X-CSRF-TOKEN as headername

I get an error wen using X-CSRF-TOKEN and when using  var headerName then header ist set as headerName  not value of the var

@{

    string headerName = "X-CSRF-TOKEN";

    string headerValue = value;

    var dataManager = new DataManager()

    {

        Url = "/Services/Module/List",

        Adaptor = "UrlAdaptor",

        CrossDomain = true,

        Headers = new object[]{ new { X-CSRF-TOKEN = token } }

    };

}

<ejs-schedule id="schedule">

    <e-schedule-eventsettings dataSource="dataManager">

    </e-schedule-eventsettings>


</ejs-schedule>


Thanks for reply


4 Replies 1 reply marked as answer

VD Vinitha Devi Murugan Syncfusion Team July 13, 2021 11:05 AM UTC

Hi Jo Jo, 
 
Greetings from Syncfusion Support. 
 
In c#, we can’t name a variable with a dash or a hyphen. Please refer the.NET Naming Conventions for more information. 
 
So, we suggest you to use header name as `X_CSRF_TOKEN` and for the same we have prepared a sample which can be referred from the following link. 
 
 
@{ 
    ViewData["Title"] = "Home Page"; 
 
    string headerValue = "123"; 
} 
 
<div class="control-label"> 
    <div class="control-section"> 
        <ejs-schedule id="schedule" height="550px"> 
            <e-schedule-eventsettings> 
                <e-data-manager url="/Home/LoadData" crudUrl="/Home/UpdateData" adaptor="UrlAdaptor" crossDomain="true"  headers='new object[]{ new { X_CSRF_TOKEN = headerValue } }'></e-data-manager> 
            </e-schedule-eventsettings> 
        </ejs-schedule> 
    </div> 
</div> 
 
Also, please refer to the below forum links for more information. 
 
Regards, 
Vinitha 



JJ jo jo July 15, 2021 12:34 PM UTC

Thanks for your answer.

That's bad, im using a framework where the header name is fixed so i cant change the name.



JJ jo jo July 15, 2021 01:27 PM UTC

Found a working solution:


@{

    var dataManager = new DataManager()

    {

        Url = "...",

        Adaptor = "UrlAdaptor",

        CrossDomain = true,

        Headers = new Object[] { new Dictionary<string, object> { { "X-CSRF-TOKEN", tokenvalue } } }

    };

}


Marked as answer

NR Nevitha Ravi Syncfusion Team July 16, 2021 04:52 AM UTC

Hi Jo Jo, 

Thanks for sharing the solution. 

We are happy that you issue has been resolved, please get back to us if you need any assistance. 

Regards, 
Nevitha 


Loader.
Up arrow icon