Hi,
I tried to do an application aspnet core with jquery datable. The data is in file table in sql sever.
The path of server is : \\servername\\PartageData\\wSerie
, with wSerie the database. The path of the file is \\servername\\PartageData\\wSerie\wSerieDir
When I run my application I have error message
404 - Not Found.
The URL requested was not found on the server.
Check for typos in the file name in the ajax parameter and in your file on the server.
I thought that the problem is with my definition of the connectionStrings
because all files is in wSerieDir
; but I tried to change it by Catalog=wSERIE\\wSerieDir
but I've always 404-Not Found!
Have you an idea?
I defined appsettings as below
"ConnectionStrings": {
"DefaultConnection": "Data Source=servername\\PartageData;Initial Catalog=wSERIE;Trusted_Connection=True"
},
I use the class
public class wSerie
{
public Guid stream_id { get; set; }
public Byte[]? file_stream { get; set; }
public string? name { get; set; }
[NotMapped]
public HierarchyId? path_locator { get; set; }
[NotMapped]
public HierarchyId? parent_path_locator { get; set; }
public string? file_type { get; set; }
public Int64 cached_file_size { get; set; }
public DateTimeOffset creation_time { get; set; }
public DateTimeOffset last_write_time { get; set; }
public DateTimeOffset last_access_time { get; set; }
public bool is_directory { get; set; }
public bool is_offline { get; set; }
public bool is_hidden { get; set; }
public bool is_readonly { get; set; }
public bool is_archive { get; set; }
public bool is_system { get; set; }
public bool is_temporary { get; set; }
}
ApplicationDbContext.cs
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{ }
public DbSet<wSerie> wSeries { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<wSerie>().HasNoKey().ToTable("wSerie", t => t.ExcludeFromMigrations());
base.OnModelCreating(modelBuilder);
}
}
I define the API
[Route("api/[controller]")]
[ApiController]
public class wSerieController : ControllerBase
{
private readonly ApplicationDbContext context;
public wSerieController(ApplicationDbContext context)
{
this.context = context;
}
[HttpPost]
public IActionResult GetSerie()
{
try
{
var draw = Request.Form["draw"].FirstOrDefault();
var start = Request.Form["start"].FirstOrDefault();
var length = Request.Form["length"].FirstOrDefault();
var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault();
var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault();
var searchValue = Request.Form["search[value]"].FirstOrDefault();
int pageSize = length != null ? Convert.ToInt32(length) : 0;
int skip = start != null ? Convert.ToInt32(start) : 0;
int recordsTotal = 0;
var customerData = (from tempcustomer in context.wSeries select tempcustomer);
if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDirection)))
{
customerData = customerData.OrderBy(sortColumn + " " + sortColumnDirection);
}
if (!string.IsNullOrEmpty(searchValue))
{
customerData = customerData.Where(m => m.name.Contains(searchValue)
|| m.file_type.Contains(searchValue)
);
}
recordsTotal = customerData.Count();
var data = customerData.Skip(skip).Take(pageSize).ToList();
var jsonData = new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data };
return Ok(jsonData);
}
catch (Exception ex)
{
throw;
}
}
}