.status-msg-wrap { display: none; }
Wednesday, February 28, 2018
no image

Question about scoped dependencies in .net core

The docs say that scoped dependencies get new instances for each request that arrives.

I added a scoped dependency to the container. Its constructor only gets called for the first time the dependency is resolved.

I was expecting to see more constructor calls for the next requests that arrived and that required a new instance of my dependency.

What I am missing?

Question about scoped dependencies in .net core Click here
no image

Identity & Claims: Multiple Values for single ClaimType?

I haven't been able to find any good resources for this, though I'm sure I'm not using the correct search terms.

My MVC application uses Identity with Claims. I use the claims to populate information like the user's name and other user specific properties. However, now I have a need to assign a claim to a user that has multiple values, and I'm not entirely sure how that works in Identity.

For example, my app has three companies: A, B, and C. User1 can access Company A and B, and User2 can access Companies A and C. I initially tried storing this information as multiple rows with the same "ClaimType" in the AspNetUserClaims table (screenshot). However, when creating the identity, it's only bringing back one company (screenshot). I thought - ok, maybe I'm doing this wrong. But for shits and giggles, I added MORE rows (screenshot). And now it's coming back with SOME of them, but not all of them (screenshot).

Clearly, I'm not doing something correctly. Can someone please help guide me? The goal is to allow someone to switch between "companies" so that all data they see is from that currently selected company across all application pages, until they choose to switch to another company.

I had read about "multitenancy" but that doesn't seem to be the correct application here.

Identity & Claims: Multiple Values for single ClaimType? Click here
Tuesday, February 27, 2018
no image

Noob question: Why wont my Index.cshtml page load the data being passed to it from the controller?

Upfront I should say I'm using ASP.NEt Core 2.0

OK, so I'm build a small test site as a learning experience. My controller Index method consists of:

List<Object> objects = _objectRepository.GetObjects(); return View(objects); 

I ran it through the debugger, and know that list is populating with the two objects I have created as initial data, but then when it passes it to my Index.cshtml file, which has this at the top

@model List<Namespace.Models.Object> 

when I try to do this:

<ul> @foreach (var object in Model) { <li>@object.Property1</li> <li>@object.Property2</li> } </ul> 

I'm getting a Null Reference Exception: Object reference not set to an instance of an object, and it details that foreach() loop, so I'm thinking it has to be an issue with the Model variable right?

Thanks in advance for any help!

Noob question: Why wont my Index.cshtml page load the data being passed to it from the controller? Click here
no image

IsPressed Trigger for Custom User Control (WPF)

I've created a custom control for a button for my application. Everything's gone perfectly until I needed to establish a "IsPressed" trigger. I understand that the object isn't a button but I can't seem to find a way to get an inheritance from Button to my custom user control so I can used the "IsPressed" trigger. I hope this is making sense... How can I establish a trigger for "IsPressed" or something similar so that then a user presses the button, the background color changes.

My code as of now:

User Control

<UserControl x:Class="Tool_Management_System.Controls.NavBarButton" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Tool_Management_System.Controls" mc:Ignorable="d" d:DesignHeight="25" d:DesignWidth="150"> <Border x:Name="Body" Background="Transparent"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" MaxWidth="25"/> <ColumnDefinition Width="3*"/> </Grid.ColumnDefinitions> <Image x:Name="ButtonIcon" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="HighQuality"/> <TextBlock x:Name="ButtonText" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center"/> </Grid> </Border> </UserControl> 

User Control Styling

<Style x:Key="NavBarButton" TargetType="Controls:NavBarButton"> <Setter Property="Height" Value="25"/> <Setter Property="Background" Value="#202020"/> <Setter Property="BorderBrush" Value="#000000"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Margin" Value="0,0,-1,-1"/> <Setter Property="FontSize" Value="10"/> <Setter Property="FontFamily" Value="Tahoma"/> <Setter Property="Foreground" Value="#DEDEDE"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Trigger.EnterActions> <BeginStoryboard> <Storyboard> <ColorAnimation Duration="0:0:0.25" Storyboard.TargetProperty="Background.Color" To="#80B45A00"/> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard> <Storyboard> <ColorAnimation Duration="0:0:0.25" Storyboard.TargetProperty="Background.Color" To="#202020"/> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </Style.Triggers> </Style> 
IsPressed Trigger for Custom User Control (WPF) Click here
no image

Build registrations still open?

I've heard the legends of Build selling out in mere minutes, but it seems to me that I can still register for Build 2018, amost two weeks after registration opened.

What am I missing?

Build registrations still open? Click here
no image

Updating an old IIS site

I'm not sure if this is the right place to as but I'm having difficulty updating an IIS site. I'm editing the aspx file of the main page trying to add another menu item under a list and saving the file after I've added the code, but the item doesn't appear in the list even after restarting the iis server. When I view the source code of the page the new code I added isn't in there, but when I view the code from the file itself (in multiple editors) the modified code is there. Any ideas?

I've also tried loading it in different browsers.

Updating an old IIS site Click here
no image

A question about task scheduling

Sorry for the stupid question, but I'm making an MVC app that will send out an email an hour before a scheduled time. This email only needs to be sent out once.

There is a TON of information on setting tasks etc, and that's part of my problem. I'm not sure which option to use.

I started using Quartz to do this, but this seems more tailored to something that needs to be repeated.

For a bit of context, people will enter a task into a form with a scheduled time, an hour before that time gets scheduled an email will be sent out to parties who need to know what's happening.

I was hoping someone might be able to point me in the right direction.

Thanks for your time.

A question about task scheduling Click here
no image

Is it possible to mix writing an EF Core query with LINQ and strings?

Sorry for the confusing title. But I was hoping to be able to write most of the query in LINQ, but then write the WHERE clause as a string, like you would a dynamic query. So something like:

var query = from part in _context.CurrentInventory

query.Where = "part.PartNumber LIKE '%a%' OR part.PartNumber LIKE '%b%'

The reason is because the WHERE can get quite large and using EF.Functions.Like really slows down the query.

I could build the whole thing dynamically and just execute the string, but I was hoping to avoid that unless necessary.

Is it possible to mix writing an EF Core query with LINQ and strings? Click here
no image

Assistance with Functions to Multiple Elements

C#, WPF, VS2017 https://pasteboard.co/H9AWOlU.jpg

I am working on an application and am having a hard time figuring out how to do something. I attached an image for some clarity. This image is a canvas with multiple textboxes bound to XML data and buttons. The buttons all interact with the textbox DATA and everything is peachy. However, I intend to have 50 of these, and replicating all the button code over and over is not feasible. So I am trying to figure out a universal way to have just a handful of buttons that interact with the selected line/canvas.

I know I can make a class and programatically add the elements to a stack panel. But I am unable to get it look like the image and I really need it to look like that. So I am just poking around to see if anyone has any ideas?

Code Example: (Plus Button in the middle) So this is just 1 of the buttons that interacts with the specific textbox. On the 2nd canvas / monster line it will do the exact same thing, but use the 2nd textbox.

 //Adds 1 HP to Current HP private void m1_plus_MouseUp(object sender, MouseButtonEventArgs e) { Double currenthp; if (m1_chp.Text == "") { MessageBox.Show("Select a Monster First"); } else { currenthp = Convert.ToInt32(m1_chp.Text); int value = Convert.ToInt32(m1_chp.Text); value++; m1_chp.Text = value.ToString(); } } 
Assistance with Functions to Multiple Elements Click here
no image

Publishing ASP.NET Core 1.1 with CSPROJ

Hello friends.

We're currently going through a transitional period from ASP.NET Core 1.0 to 1.1

As we've already seen, project.json is being depreciated in favor of .csproj in version 1.1.

My issue is that I'm running a linux server with the latest .NET Core 1.1 version. So I would assume it would publish via .csproj but it continues to tell me I'm missing project.json, can anyone let me know how to publish (compile) my web application sitting on my server via .csproj?

Obviously I've tried to use dotnet publish, this is the command that tells me project.json is required but this isn't a 1.0 application, it never was. It was created within VS2017 with ASP.NET Core 1.1 using .NET Core 1.1.

I've already searched this and /r/aspnet and could not find a suitable answer. Stackoverflow doesn't have any suitable answers for me. How are you guys compiling 1.1 web applications on a linux distro?

Publishing ASP.NET Core 1.1 with CSPROJ Click here
Monday, February 26, 2018
no image

JustABackup - backup solution written in C#

Hi everyone,

I'm posting a side-project I have been working on my spare time for a while, a backup solution written in C#.

The backup solution is based on plugins (implementing interfaces) that can either read, write or modify a stream of data. An example might be to read files from a folder on your computer, zip them together and store them in OneDrive. All of this is configured with a web based UI, where you create a backup job with your own choice of source data and storage target. As everything is based on plugins the idea is to let this be able to become a complete backup solution, and not limit the user what the application can or can not do.

You can look at the code at GitHub here: https://github.com/JustABackup/JustABackup/ I would love some feedback and/or ideas where to continue. As stated on GitHub, I already have a few ideas to work with at the moment :) And as this is in a very early stage, I know there should be bugs and hidden "features" that I dont know about. With that, I know there are parts with "ugly" code and things that can be improved, but I justify that as its in an early stage and there are TODO's!

The idea of this project started from my own needs where I needed to backup some folders and a database. My first solution was just a .bat script that zipped them together to a NAS. I then wanted to store them in OneDrive, so I stepped up to a console application in C# to fix this. But I thought, what if I want to add other sources to my backup? Seemed kinda dumb to hard code everything. As the next step was some kind of configuration, I couldn't help myself with new ideas and plans for features. When the ship was sailed for a simple solution, the target became to build this with everything I could think of. But hey, it's been fun atleast :)

Note: As of posting this it seems OneDrive have changed something regarding authentication or there is a problem at Microsoft. Will look into that.

JustABackup - backup solution written in C# Click here
no image

How can I add authorization to my Web API?

Hi everyone, I am using MVC5 to create a webapp and I have two different types of controllers (ApiController & Controller) and two different end points:

  • API end point that returns JSON and uses ApiController
  • WebApp front end that uses Controller

I've used filters.Add(new AuthorizeAttribute()) in my FilterConfig.cs so that user has to login before accessing any data on the website but, a user can just go to my API endpoint url and do whatever they want with the data (add,delete,update etc).

I plan on consuming the WebAPI on an android app so i was thinking to implement a login screen that validates the username and pwd (same as my WebApp) using the WebAPI that I made using and if the user authenticates successfully, they are then allowed to update, delete etc. Is this even possible? If yes, how can I achieve this?

Any help would be appreciated, thanks!

How can I add authorization to my Web API? Click here
Sunday, February 25, 2018
no image

Failing to understand overriding methods.

So I just got started in C# and am having an issue understanding the point of overriding a method. I know how to do it, it’s just that, what is the point? Why wouldn’t you just not inherit and just make a separate class outside of the base class with the same method name? All I’m seeing is that it allows you to name a method in a derived class with a method name already being used in the base class. I get overloading, that’s really cool and I have found it extremely useful, but why overriding? When would someone ever need to override a method? Why would they ever need to? When would someone ever use this in production? What is the benefit here? I love polymorphism, but why? Give me an example of when this would be useful.

Failing to understand overriding methods. Click here
no image

How do I put the results of a LINQ SQL Query into a C# Variable?

I want to store alpha text that is returned on a LINQ Query into a local variable. How would I do so?

My Code (not working):

 var qCustomerID = from c in dcCustomers.Customers where c.CompanyName == strCustomer select c.CustomerID; strCustomerID = qCustomerID.FirstOrDefault(); 
How do I put the results of a LINQ SQL Query into a C# Variable? Click here
no image

Projects for portfolio (ASP.NET Jr Dev)

I'm self-taught, former structural engineer with a goal to become a junior dev. I have worked on numerous traditional web apps and APIs utilizing Asp.Net Core and other technologies. (I also have Flask and Suave.io projects)

I'm polishing up some of my projects but I'm not sure if I've done enough. I know all the basic stuff (GIT, OO, Unit tests) and essential ASP.NET libraries/components (EF Core, Identity, Razor). As for the not-so-beginner stuff, I've used Dapper, ElasticSearch, Redis (cache), Docker containers, and utilized DDD/CQRS-esque architectures. The last major thing I plan to learn is CI/CD (at least at a basic level) and then brush up on CS(algorithms, etc.).

My question is, how important is it to learn microservices, Rabbitmq (or some other message broker), Identity Server, and event sourcing? I understand what these are but have not demonstrated them. All of these things seem pretty important and interesting to me but at some point, I'll have to stop learning new technologies and focus on the fundamentals so I can finish up my portfolio and begin the job hunt.

Projects for portfolio (ASP.NET Jr Dev) Click here
no image

Implementing EF 2.0 Audit log

I'm currently looking for the best way to implement an audit log for my .net core backend using EF core. I've looked online and see various approaches, and was wondering what experiences were in the sub. All the approaches I've seen involve overwriting the SaveChanges() method of the context and some use shadow properties. Interested to see what you guys opinions are on the subject and if anyone has any recommendations for which approach to go for or if there is another that I've not found yet. Thanks!

Implementing EF 2.0 Audit log Click here
no image

Need Contribution and Help In Xeeny Framework (services framework, .net standard devices, sockets)

I am writing this framework that allows .net developers to host services in devices as WCF is still not standard. It allows communication with different transports, duplex, and different serializers. The goal is simplifying communication between devices without servers (say mobile to printer, or mobile to mobile voice chat over UDP) I need support and for now Unit Test coverage will be great (XUnit, C# 7.2). I also need ideas to improve performance (reduce array allocations) or complexity (protocol and message framing became complex when I wanted to allow different transports and concurrent sockets send/receive which happened because I want the client to be able to send messages when there is lengthy streaming).

https://github.com/MhAllan/Xeeny

Need Contribution and Help In Xeeny Framework (services framework, .net standard devices, sockets) Click here
Saturday, February 24, 2018
no image

Help on my notification framework

Hey guys,

I'm working on a notification framework for our ASP.NET MVC 5 application. Whenever a notification is created in the table I need to:

  • Show an alert on their dashboard (Using SignalR for this)
  • Send an email of the notification to the user (Using Sendgrid for this)
  • Send a Text Message of the notification to the user (Using Twillio for this)

Of course, we only send an email/text message if they have agreed to those types of notifications.

In the past what I have done is just created a console application that ran every 5 minutes that would send out email notifications and then update the notification record column sent = true.

However, I'm thinking there may be a better way, but I'd like some feedback. I'm thinking of using Azure functions and Azure Storage Queue's.

  1. We create a notification: Insert into dbo.Notification table (to show on the dashboard).
  2. At the same time we send a POST request to a webhook of an Azure function that inserts it into the queue for email/text messaging.
  3. We have another Azure function that then processes the items in the queue and sends the email and/or text.

Question:
1. Thoughts on this? Should I make it easier and not even use the queue?
2. I won't be updating the original notification record that we processed the email/text messaging. If it fails, it just fails with no re-processing possible.
3. I really just need a sanity check here guys.

Help on my notification framework Click here
Friday, February 23, 2018
no image

MVC View display ruined after Git clone

I created a git repo from one computer and then cloned it on another. After that, when I run the ASP.NET MVC Web application from Visual Studio, the styling in the browser is completely off and some elements are even invisible. The menu is gone, glyphicons are gone, styling is weird. I tried fixing the line endings using an extension, because I thought that was the issue, but it didn't solve anything (extension didn't find any bad line endings).

I also copied the files to a zip file and created the repo again, but it wouldn't let me add a .gitattributes file and commit. My repo on github is still there and the files are still good. I'm not sure what else to do. I spent many hours working on the design.

MVC View display ruined after Git clone Click here
no image

.NET Core new form?

Hello, I am used to C#, .Net and stuff on windows, but I just discovered .Net core and I am wondering if it has a way to create a cross platform "form" (like the windows form), the same way it can create console apps for any supported OS.

I've searched for templates, with no luck, and I am starting to wonder if it is possible at all.

Thanks

Alex

.NET Core new form? Click here
no image

SpoonCMS: A minimalist .Net Core CMS for devs, who want to keep coding in .Net

This is a side project I have been toying with for months that came from not wanting to implement a CMS that took over my whole .Net application. This is very much a Beta, but after using it without issues on my 3rd freelance project, and getting some feedback from a small group, I thought I would share it with a larger crowd and get some thoughts. After all, my use cases are pretty similar each time.

SpoonCMS

This came from formalizing work I had done in one way or another for dozens of freelance projects. I was annoyed that I would have to redeploy for small content updates if I didn't want a huge, invasive CMS system, which they all seemed to be for .Net lately. So I would build very simple content in, content out systems for HTML and I didn't want to keep copy/pasting and tweaking each time.

After hearing people had the same frustration, I figured this would be worth sharing and I made a (somewhat) usable admin. It's nothing fancy at this point, probably never will be, but the directness is part of the appeal for people who have tried it.

Some highlights:

  • After installing the package, 2 lines of code for base setup
  • It is built to be very simple and basic. You put content in, you get content out with a few small features around it.
  • Can use claims or auth attributes to secure the admin.
  • Uses LiteDB for content storage. Light, fast, and easy to make backups. Other providers being considered.

Here is a screenshot of the admin for an example project I created.

A simple example of how I would use SpoonCMS to load content onto my Home Page. The controller would look like:

Container container = SpoonDataWorker.GetContainer("HomePage"); ViewData["HeaderContent"] = container.GetItem("HeaderContent").Value; ViewData["BodyCotentBlock"] = container.GetItem("BodyContentBlock").Value; ViewData["RightRail"] = container.GetItem("RightRailContent").Value; ViewData["LeftNav"] = container.GetItem("LeftNavLinks").Value; ViewData["Footer"] = container.GetItem("FooterContent").Value; 

And my view could look like this:

<body> <div id="header-block">@Html.Raw(ViewData["HeaderContent"])</div> <div id="body-copy">@Html.Raw(ViewData["BodyCotentBlock"])</div> <div id="right-rail">@Html.Raw(ViewData["RightRail"])</div> <div id="left-nav">@Html.Raw(ViewData["LeftNav"])</div> <div id="footer">@Html.Raw(ViewData["Footer"])</div> </body> 

Again, this is nothing fancy, but figured some other people could make user of it. If you have any thoughts, feedback, or features requests, I welcome them.

SpoonCMS: A minimalist .Net Core CMS for devs, who want to keep coding in .Net Click here
no image

Switching from PHP to asp.net

Hello. I'm a PHP developer with a couple years experience working in Symfony and Laravel frameworks, familiar with clean code, coding standards and paradigms (SOLID, ACID and this kind of stuff). I was thinking lately and figured out it would not be bad to switch to (or at least start learning about) asp.net and how it differs from PHP. My goal would be to familiarize myself with asp.net, grasp the foundations and slowly start writing web apps using it to finally be able to switch jobs from PHP dev to ASP.NET dev. Can you recommend any good article, courses and similar sources of knowlegde to aid me in achieving my goal? Any help appreciated.

Switching from PHP to asp.net Click here
no image

What laptop would you recommend for asp.net development?

I am currently sitting on a newer Macbook pro 13" working on windows either from bootcamp or through parallels.

It's just not working out for me, and I am experiencing a lot of performance issues, and errors with parallels windows image.

The only Reason I haven't switched back to a real windows pc, is the awesome experience on the mac, and the incredibly responsive mac touch pad.

Which laptop would you recommend for asp.net development. A bit on the go but mostly connected to an external monitor.

I have always been a Lenovo fan boy, but I am open for trying out new things. I have been looking at the new Lenovo X1 Carbon and the Lenovo T580 / T480.

What laptop would you recommend for asp.net development? Click here
no image

Microsoft Dynamics CRM

Hi, I'm a middle C# developer and I have recently received a job offer as a Microsoft Dynamics CRM Developer but I don't know anything about it. My question is: have any of you worked with it? How does it compare with normal MVC development?

Microsoft Dynamics CRM Click here
no image

Is it worth it to watch a .net core 1.0 course?

So I'm working my way through the DevU-curriculum, but replacing/complementing parts of it with other courses.

I've done the C# Fundamentals, and for basic web-development I used the "Google Front-end course" on Udacity.

Next up in the curriculum is "introduction to .net core ", but the DevU course is for v 1.0. Is it worth watching a 1.0 course today, or has too much changed since then?

Is it worth it to watch a .net core 1.0 course? Click here
Thursday, February 22, 2018
no image

Angular 5 and asp.net core 2, what are you setups like?

I'm using angular cli, using visual studio 2017. I found the angular templates to start a project terrible. Wouldn't resolve npm dependencies from the initial boiler plate project, so could not launch the site from vs So I went with angular cli, but it involves me doing ng serve -- open from cmd prompt.

I'm good with angular 1. But in general not great with front end. So resolving npm issuess has been annoying.

Just wondering how you guys run angular 5 from vs. A good github repo I could clone with the boiler plate would b nice but my approach so far is teaching me a lot I'm front end would.

What do you guys think of angular cli BTW?

Angular 5 and asp.net core 2, what are you setups like? Click here
The webdev Team