Posts

Showing posts with the label asp.net-core

Showing the data of the right side of the TimeLine

Image
Showing the data of the right side of the TimeLine How can I show the description Data on the left or the right side of the timeline acording of it Candidate.Saving result? If it's Candidate.Saving == true it should be on the left, if it's Candidate.Saving==false it should be on the right side of the time line. I will shou here my candidate Model And my View. Candidate.Saving == true Candidate.Saving==false public class Candidate : BaseEntity { public int Id { get; set; } public string Name { get; set; } public int Number { get; set; } public string ProfileText { get; set; } public Byte CV { get; set; } public string CVNAME { get; set; } public List<Profile> ProfileList { get; set; } public String Description { get; set; } public Boolean Saving { get; set; } public string Title { get; set; } public DateTime DateOfDescription { get; set; } } Here is my view: @model HCCBPOHR.Data.Candidate @{ ViewData["Title"] = ...

Restore AJAX handling for ASP.NET Core to previous functionality

Image
Restore AJAX handling for ASP.NET Core to previous functionality In previous MVC5 and below, you could make an ajax call that unwrapped the parameters properly: JS: $.post('/controller/endpoint',{intparam: 1, strparam: 'hello'}) CS: public ActionResult endpoint(int intparam, string strparam){} In the new aspnetcore, it has changed: CS: public CustomClassWrapper{ public int intparam {get;set;} public string stringparam {get;set;} } public ActionResult endpoint([FromBody]CustomClassWrapper item){} To sum it up, in the new framework, you need to write a wrapper class and can only pass one [FromBody] parameter to the method. Previously, the params would be unwrapped by variable name correctly. So, i'm trying to re-implement this functionality in an aspnetcore middleware component. I'm having difficulty in how to accomplish calling the controller method properly with the parameters. My current cut-down code: public async Task Invoke(HttpContext context) ...

.Net Core Use logout link instead of button preventig cross domain GET request

.Net Core Use logout link instead of button preventig cross domain GET request I know that using button instead of anchor link in _LoginPartial.cshtml is to prevent cross domain GET requests, but I really need using anchor link to have a uniform nav-bar links. My question is: If I use anchor tag and use javascript code to call form submit method, will it be safe and prevent cross domain GET request? I mean replacing this code: <button type="submit">Logout</button> with this one: <a href="javascript:document.getElementById('logoutForm').submit()"></a> The point of the button is actually to submit the logout request via POST, since GET requests are idempotent and should not have any side effects. CSRF is just gravy on top. If you need a link, you can either style the button as a link (which is really the optimal path, as stylistic appearance is the domain of CSS, not HTML or JavaScript.) or you can use JavaSc...

.Net Core Hosted Service Requires HttpContext

.Net Core Hosted Service Requires HttpContext EDIT Summary I have a background service, which requires a DBContext, my DbContext is dependent on the HttPContext, because it uses the UserClaims to filter the context. The HttpContext which is null when requesting the DbContext from BackgroundService, (this is by design because there is no WebRequest associated with a BackgroundService). How can I capture and moq the HTTPContext, so my user claims will carry over to the background service? I'm writing a hosted service to queue pushing messages from my Hubs in Signalr. My Background. public interface IBackgroundTaskQueue { void QueueBackgroundWorkItem(Func<IServiceProvider, CancellationToken, Task> workItem); Task<Func<IServiceProvider, CancellationToken, Task>> DequeueAsync(CancellationToken cancellationToken); } public class BackgroundTaskQueue : IBackgroundTaskQueue { private ConcurrentQueue<Func<IServiceProvider, CancellationToken, Task>>...

Asp.Net Core API disable startup complete message

Image
Asp.Net Core API disable startup complete message As part of my application I have a .Net Core API project. Unlike most cases where this project would run as its own process, I have the API run in a thread, among others, in a single process. Also for my project, I have implemented a custom logging system to suit my needs. However, I have come across a slight problem. Every time I run my program, once the API starts, this message is printed to the console: Hosting environment: Production Content root path: C:UsersPathToCode Now listening on: http://*:8000 Application started. Press Ctrl+C to shut down. I would like to disable this message as there is no need for it, and it clutters up the otherwise well organized console log. I have a screenshot below so you know exactly what I'm talking about: I have already disabled all other logging for the mvc (removed ILoggerFactory from ConfigureServices and set all logging to "None" in appsettings.json ). ILoggerFactory ConfigureS...