2018-10-22         Yehudi

How to do DI in asp.net core middleware?

I am trying to inject dependency into my middleware constructor as followspublic class CreateCompanyMiddleware{ private readonly RequestDelegate _next; private readonly UserManager<ApplicationUser> _userManager; public CreateCompanyMiddleware(RequestDelegate next , UserManager<ApplicationUser> userManager ) { _next = next; } public async Task Invoke(HttpContext context) { await _next.Invoke(context); }}My Startup.cs file looks likepublic void ConfigureServices(IServiceCollection services){ services.AddDbCont...

 c#                     2 answers                     94 view
 2018-10-22         Carr

HttpClientFactory - Get a named, typed client by its name

HttpClientFactory offers the following extension method:public static IHttpClientBuilder AddHttpClient<TClient>(this IServiceCollection services, string name)and I've created a typed HttpClient as follows:public class CustomClient { public CustomClient(HttpClient client, CustomAuthorizationInfoObject customAuthorizationInfoObject) { /// use custom authorization info to customize http client } public async Task<CustomModel> DoSomeStuffWithClient() { /// do the stuff }}I can register this custom client in the program's ServiceColle...

 c#                     1 answers                     95 view
 2018-10-22         Zara

Nlog Log IP Address from NetCore Library Project

I have a VS 2017 solution with multiple projects, I have a separated project with the NLog methods to use it from other projects for not include NLog in all projects.NetCore Rest APINetCore InfraestructureNetCore Database And persistenceNetCore LoggerOther NetStandard Projects with helpers and ViewModel ClassesI want to Log Client IP Address and user if it's logged in. I have seen that I have to use a template in the NLog.config, but it is not working and the log IPAddress field is empty.What's the correct way to do it?NLog.Config<extensions> <add assembly="NL...

 c#                     1 answers                     97 view
 2018-10-22         Maureen

ASP.NET Core 2.0 request failed

I have the following API controller: [HttpPost] public async Task Post([FromBody]Statistics value) { if(_user == null) _user = await _userManager.GetUserAsync(HttpContext.User); if(_user.Statistics == null) _user.Statistics = new List<Statistics>(); _user.Statistics.Add(value); Context.SaveChanges(); }I'm trying to send some data:$("#submit-button-clicked").click(function () { $.ajax({ url: 'api/Statistics ', type: 'POST', dataType: "json", ...

 c#                     2 answers                     98 view
 2018-10-22         Jo

Read URL parameter for Helpers

There are Helpers who are responsible for adding Active classes to the menu.public static class HtmlHelpers{ public static string IsSelected(this IHtmlHelper html, string controller = null, string action = null, string status = null, string cssClass = null) { if (String.IsNullOrEmpty(cssClass)) cssClass = "active"; string currentAction = (string)html.ViewContext.RouteData.Values["action"]; string currentController = (string)html.ViewContext.RouteData.Values["controller"]; string currentStatus = (string)html.ViewContext.RouteData....

 c#                     1 answers                     0 view
 2018-10-22         Kerwin

Antiforgery and cache-control header ASP.NET core

I am trying to override cache-control header set by default antiforgery of asp.net core 2.0.net core always sets it to no-cache, no-store. I am trying to use private which actually works as I wanted. no-cache, no-store doesn't seem to always work giving me some kind of antiforgery token was meant for ... user.. kind of error occasionally. Which setting cache-control to private seems to solve.But .net core doesn't let me override the default cache-control set by antiforgery.I have tried following: public async Task<IActionResult> Login(string returnUrl) { Ht...

 c#                     1 answers                     1 view
 2018-10-22         Erica

DataGridComboBoxColumn binding to a different list that the DataGrid ItemsSource

So I am relatively new in WPF and a nice feature someone mentioned to me was the custom columns in datagrids..So here is my question.I have two database tables, an Employee table and an Occupation table.Employee tableOccupation tableAnd as you can see I have a foreign key linking the two tables. So in my app I set my DataGrid ItemsSource = list of Employees. In my DataGrid I defined the columns myself, I disabled the AutoGenerateColumns property. I have 4 columns, 0: TextColumn1: TextColumn2: TextColumn3: ComboBoxColumnSo my question is, how can I set the ItemsSource of the...

 c#                     1 answers                     27 view
 2018-10-22         Bess

TextBox does not exist in the current context in DataGrgid DataRowTemplate

I have a datagrid which on click will show a textbox for user input. I am able to display the details on the textbox. Now I have a Update button inside the datatemplate. Once i click on the update button I want the user input taken and do processing.This is my xaml code:<DataGrid.RowDetailsTemplate> <DataTemplate> <Border BorderThickness="0" Background="BlanchedAlmond" Padding="10"> <StackPanel Orientation="Vertical"> <StackPanel Orientation="Horizontal"> ...

 c#                     1 answers                     29 view
 2018-10-22         Clark

Update datagrid using data binding from database using observable object

I’m trying to use data binding as close to MVVM as possible to update a WPF datagrid with data from a database. I think I’m still struggling with the concept, to which I haven’t found (or understood) the answer in any examples I’ve been through. There is a lot of information in this post, but unless I've missed something, my specific question below is not addressed.Question:How to trigger PropertyChangedEventArgs when another class updates the SQL database?I’ve tried something as follows, however, it doesn’t work (presumably because I’m notifying in a new instance). If I r...

 c#                     1 answers                     30 view
 2018-10-22         Jessica

Duplicate rows being added to datagrid when adding in for loop

When I output the generated value into in the datagrid it puts the same value about 15 times before adding a unique value into the the datagrid. Does anyone know any solutions or workarounds to this problem? Also note that I am running this for loop within another for loop to generate a specific amount of values. var parts = new List<string>(); string hash = CalculateMD5Hash(identifier); for (var i = 0; i < 32; i += 2) { string chars = "0123456789ABCDEFGHJKLMNPQRTUVWXY"; var nextDigit = Convert.ToInt3...

 c#                     1 answers                     31 view
 2018-10-22         Jocelyn

How do I split a string with '$' delimiter?

I have this FINAL PAYMENT $25 string on a MVC c# application.I want to split into FINAL PAYMENT and 25I tried doing this string s = "FINAL PAYMENT $25";string[] str1 = s.Split('$');//result: 25How can I get the rest. Can anyone help? Split method returns a string array, if you need both elements of this array, Try:string s = "FINAL PAYMENT $25";string[] resArray = s.Split('$');var FPayment = resArray[0];var second25= resArray[1]; [XXX]You can use indexOf instead of a Splitstring s = "FINAL PAYMENT $25";int index = s.IndexOf("$");String final_pay = s.Substring(index...

 c#                     2 answers                     87 view
 2018-10-22         Rory

UseWebpackDevMiddleware AggregateException

I try to create a ASP.NET Core MVC application using NPM/Webpack/Vue.js. I am following this tutorial:https://marczak.io/posts/netcore-vuejs/When starting the project I get this exception:An exception of type 'System.AggregateException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'One or more errors occurred.' Inner exceptions found, see $exception in variables window for more details. Innermost exception Newtonsoft.Json.JsonReaderException : Unexpected character encountered while parsing value: <. Path '', line 0, position 0. at Newton...

 c#                     1 answers                     88 view
 2018-10-22         Riva

RenderBody with jQuery Ajax calls

I'm think that I'm doing something wrong here in .Net Core. I have layout with @RenderBody Problem is - I'm doing jQuery Ajax calls, my Actions returning me Partial Views. That works good. Problem is, I don't see any path of Controller and Action in URL, can't refresh page, I am returned to the Home. Another problem with Partials Views I can't solve is - Scripts:I can include all scripts in Layout, but some partials views requiring 2-3 scripts, another partials views different 2-3 scripts. I can't split usage, I don't want to throw all in one layout.Can't add them in the Pa...

 c#                     1 answers                     89 view
 2018-10-22         Calvin

c# Count rows in DataTable where all values of row equal to 1

I have a datatable in which the columns and rows are created at runtime, so as a result the column names may vary and row numbers too. Values for each cell can only be 1 or 0.I may get a datatable with say for example 3 columns. e.g.Age | Sex | Location-------------------1 | 0 | 1-------------------0 | 1 | 0--------------------1 | 1 | 1--------------------0 | 1 | 0--------------------1 | 1 | 1--------------------I want to be able to count only the rows which contain 1 on each column. So above example would return 2. Iterate through the rows and column...

 c#                     1 answers                     90 view
 2018-10-22         Darren

How to pass string in the url as a parameter for asp.net core api

I am trying to build an api that will take a IForm file from the body and save the file. Then return the filename in the directory. I have worked with the same structure before. But then I had an integer value in the parameter now it is a string. I am trying this way. But when the route matches it always returning status 200 without saving the file and filename in the respond. [HttpPost][Route("/api/users/${email}/photos")]public async Task<IActionResult> Upload(string email, [FromBody]IFormFile fileStream){ var user = this.repository.GetUserByEmail(email); if (...

 c#                     1 answers                     91 view
 2018-10-22         Stacey

Inject User Credentials from HttpRequestContext into the service layer

I have a .NET 4.6 WebApi 2.0 OWIN App that serves HTTP Requests.Those requests are authenticated and we are storing certain claims in the RequestContext ClaimsIdentity (UserId, Client Code)We also have our Controllers, Services and Repository structure.Our Services are injected into the Controllers via Ninject, and the Repositories into the Services.When the user performers certain requests we need to check their permissions. The service usually needs to know the: UserId, ClientCode, Groups the user has access to and permissions under each group (Read, Write, etc). This las...

 c#                     2 answers                     92 view

Page 1 of 9074  |  Show More Pages:  Top Prev Next Last