This is a migrated thread and some comments may be shown as answers.

grid with asp.net core razor page - 404 on Index?handler=Read

1 Answer 990 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Moez
Top achievements
Rank 1
Moez asked on 02 Apr 2019, 07:20 PM

Hello !

I'm testing the latest version of the Grid (2019.1.220, VS 2017, asp.net core 2.2, razor pages).

I'm using the Ajax Binding, and everything is working fine when using IISExpress. When I switch to using a local instance of IIS (version 10 on a windows 10-1803), I get a 404 error in the chrome console with the following message:

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/Index?handler=Read

I've tried the [Web Resources Troubleshooting] page, specifically the section discussing 404, and added the telerik webresource handler to my web.config as follows:

<add name="Telerik.Web.UI.WebResource" path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource"/>

the full web.config is as follow:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
        <add name="Telerik.Web.UI.WebResource" path="Telerik.Web.UI.WebResource.axd" verb="*"    type="Telerik.Web.UI.WebResource"/>
      </handlers>
      <aspNetCore processPath="bin\IISSupport\VSIISExeLauncher.exe" arguments="-argFile IISExeLauncherArgs.txt" stdoutLogEnabled="false">
        <environmentVariables />
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

Any ideas on why I'm still getting the same error ?

Thanks !

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 05 Apr 2019, 08:29 AM
Hello Moez,

Could you please make sure that you are requesting the correct url? If the sample is hosted as an application of the Default Web Site the url should be as follows:


I would recommend you to use relative paths when constructing the urls in the configuration of the grid.

e.g.

.Read(r => r.Url(Url.Action() +"?handler=Read")


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Vakho
Top achievements
Rank 1
commented on 31 Oct 2022, 05:47 AM

Hi, I have the same issue but happens on IIS Express and IIS as well. I am using the correct handler URL. 

My "DataSource" portion of grid (.cshtml)

.DataSource(ds => ds.Ajax()
	   .Read(r => r.Url("/Tournaments/Organizer/Details?handler=ReadTournamentTeams"))
	   .Model(m =>
	   {
		   m.Id(id => id.TeamID);
	   })
	.PageSize(10)
)

 

My method in .cshtml.cs:

public JsonResult OnPostReadTournamentTeams([DataSourceRequest] DataSourceRequest request)
{
	var tournamentTeams = db.Tournament_X_Teams.Where(x => x.Active == true).ToList();
	return new JsonResult(tournamentTeams.ToDataSourceResult(request));
}

 

still browser is giving me 404 error saying that /Tournaments/Organizer/Details?handler=ReadTournamentTeams could not be found. 

What else can be the issue?

Georgi
Telerik team
commented on 03 Nov 2022, 08:37 AM

Hi,

I believe the issue is caused because the serialized URL being incorrect. Could you please try to use `Url.PageLink`?

e.g.

.Read(read => read.Url(Url.PageLink("PageName", "MethodName"))

Vakho
Top achievements
Rank 1
commented on 04 Nov 2022, 03:02 AM

Hi Georgi, the way my page routing is set up is this:

tournaments/organizer/details/2

that "2" in the end is a parameter "TournamentID". In the beginning of the cshtml page I have "@page "{TournamentID}"".

So when I do it the way you specified, it leads to tournaments/organizer/details/2?handler=ReadTournamentTeams. 

Not sure if that is still supposed to work or not, but I'm getting the 400 error. (doing it my way, I was getting a 404 error)

Mihaela
Telerik team
commented on 08 Nov 2022, 01:31 PM

Hi Vakho,

To get a better understanding of the issue, I have created a Razor Pages application, where the Grid is added to the "Index" page and the Read request URL is set up as follows:

Read request: https://localhost:62395/2?handler=ReadTournamentTeams

//Index.cshtml
@page "{TournamentID}"

...
.DataSource(ds => ds
  .Ajax()
  .Read(read => read.Url(Url.PageLink("Index","ReadTournamentTeams")).Data("forgeryToken"))
  ...
)

//Index.cshtml.cs
public JsonResult OnPostReadTournamentTeams([DataSourceRequest] DataSourceRequest request)
{
  ...
  return new JsonResult(dataCollection.ToDataSourceResult(request));
}

Would you please modify the attached sample based on your setup to replicate the behavior you are experiencing? It will help us to identify the issue and provide a better suggestion.

 

Vakho
Top achievements
Rank 1
commented on 11 Nov 2022, 02:40 AM

Hi Mihaela,

Thanks for the attention! So I tried your version of the .Read() portion of the grid and it worked.

.Read(read => read.Url(Url.PageLink("Index","ReadTournamentTeams")).Data("forgeryToken"))

Turns out that without the .Data("forgeryToken") part it gives me a 400 error -- adding it made it go away. While using absolute URL gave me 404 error no matter what (not sure why absolute URL isn't working). I'll stick to this syntax for now, but I have a question: I want to send data to my OnPostReadTournament teams method but I also need forgeryToken. So how would I keep forgeryToken stuff, and also send my custom data to the method at the same time?

Stoyan
Telerik team
commented on 14 Nov 2022, 08:08 PM

Hi Vakho,

You can add property to the object returned by the JS handler of the Data in addition to the antiForgery token to send more data to the server:

.Read(read => read.Url(Url.PageLink("Index","ReadTournamentTeams")).Data("additionalData"))
    function additionalData() {
        var token = kendo.antiForgeryTokens();
        return { data: "my_data", __RequestVerificationToken: token.__RequestVerificationToken };
    }
We remain open, if further questions arise.

Tags
Grid
Asked by
Moez
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or