Mar 28, 2023, 7:53 AM
Problem with custom http header
Hello
this is continuation of the https://forums.ext.net/showthread.ph...om-HTTP-header
Code is taken mostly from here too
The problem is that http header is sent in all cases, except when using Directevent ( see the submit button below)
means - the setupCrlf function is called, but the custom http header is not even visible in network nebugger, so not on server then too
The only reason for using direct event is the file uploader
So is there a way how to pass the custom header with direct event ( or alternativelly use file uploader with static direct method?)
Thanks
this is continuation of the https://forums.ext.net/showthread.ph...om-HTTP-header
Code is taken mostly from here too
The problem is that http header is sent in all cases, except when using Directevent ( see the submit button below)
means - the setupCrlf function is called, but the custom http header is not even visible in network nebugger, so not on server then too
The only reason for using direct event is the file uploader
So is there a way how to pass the custom header with direct event ( or alternativelly use file uploader with static direct method?)
Thanks
<%@ Page Language="C#" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Simple Array Grid With Paging and Remote Reloading - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" />
<script>
function loadDataGrid() {
var grid = <%= GridPanel1.ClientID %>;
grid.store.reload();
}
function loadDataDirectMethod() {
Ext.net.DirectMethods.DirectMethodCall();
}
function setupCrlf(control, eventType, action, extraParams, options) {
Ext.apply(options.headers, { csrfToken: 'xxxx' });
}
</script>
<script runat="server">
[DirectMethod]
public static void DirectMethodCall()
{
X.Toast("Call Okay");
}
[DirectMethod]
public static object[] DirectMethodLoadGrid(string action, Dictionary<string, object> extraParams)
{
List<object> ret = new List<object>();
for (var i = 0; i < 100; i++) {
ret.Add( new {
id= i,
company= "Company" + i
});
}
X.Toast("Call Okay");
return ret.ToArray();
}
protected override void OnLoad(EventArgs e)
{
if (IsPostBack && HttpContext.Current.Request.Headers["csrfToken"] != "xxxx")
{
X.Toast("Call denied / forged.");
}
base.OnLoad(e);
}
private void OnDirectClick(object sender, DirectEventArgs e)
{
X.Toast("Call Okay");
}
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" Namespace="">
<Listeners>
<BeforeAjaxRequest Fn="setupCrlf" />
</Listeners>
</ext:ResourceManager>
<ext:GridPanel
ID="GridPanel1"
runat="server"
Title="Array Grid"
Width="800">
<Store>
<ext:Store ID="Store1" runat="server" PageSize="10" AutoLoad="False" RemoteSort="false" RemotePaging="false">
<Model>
<ext:Model runat="server" IDProperty="id">
<Fields>
<ext:ModelField Name="id" />
<ext:ModelField Name="company" />
</Fields>
</ext:Model>
</Model>
<Proxy>
<ext:PageProxy DirectFn="Ext.net.DirectMethods.DirectMethodLoadGrid" />
</Proxy>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Company" DataIndex="company" Flex="1" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:CheckboxSelectionModel runat="server" Mode="Multi" />
</SelectionModel>
<View>
<ext:GridView runat="server" StripeRows="true" />
</View>
<BottomBar>
<ext:PagingToolbar runat="server">
</ext:PagingToolbar>
</BottomBar>
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="Load Data For Grid" Icon="Printer" Handler="loadDataGrid()" />
<ext:Button runat="server" Text="Load Data Direct Method" Icon="Printer" Handler="loadDataDirectMethod()" />
</Items>
</ext:Toolbar>
</TopBar>
</ext:GridPanel>
<ext:FileUploadField runat="server" ID="upload"></ext:FileUploadField>
<ext:Button runat="server" Text="Submit" OnDirectClick="OnDirectClick"></ext:Button>
</form>
</body>
</html>