.status-msg-wrap { display: none; }
Tuesday, April 30, 2019
no image

Running IIS on Windows 10, about to open to public any settings I should check

I haven't worked with IIS in 5+ years or so (been on azure or aws). I'm forced to run on a windows 10 machine, I got IIS installed and it's running and I've published everything. Everything looks good localhost. It's just a c# webapi. It'll get it opened up to the outside world IP address soon. Is there any settings I should set that isn't default. Like DDOS or anything.

Running IIS on Windows 10, about to open to public any settings I should check Click here
no image

VS2019 saving MS Unit Tests outside of the solution! Whats going on?

We are using VS2019 16.1 Prev 2.

When we create Unit Tests, in Windows Forms, they now save them in a folder outside of the Solution, whereas it used to be in with the project. As a result we can't send them up to github with the project as it complains about it.

Has anyone else has trouble with this? Also they are suddenly really buggy to run, and even though I know they are passing, often show "incomplete".

Please don't say to use "insert your favorite Test platform" instead. We use what we do for simplicity for the students.

VS2019 saving MS Unit Tests outside of the solution! Whats going on? Click here
no image

Getting variable from cs file to the cshtml file in Razor Page

Can anyone help me with this? I want to retrieve the "file" variable from the code below, and use it in its cshtml file, or if possible, I want to save that variable to a field in the database (I already had a field "File Path" in its model)

Any help would be greatly appreciated!!

 public CreateModel(Getaways.Data.ApplicationDbContext context,IHostingEnvironment environment ) { _context = context; _environment = environment; } [BindProperty] public IFormFile Upload { get; set; } public IActionResult OnGet() { PopulateCategoryDropDownList(_context); return Page(); } [BindProperty] public Post_info Post_info { get; set; } public async Task<IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return Page(); } var file = Path.Combine(_environment.ContentRootPath, "uploads", Upload.FileName); using (var fileStream = new FileStream(file, FileMode.Create)) { await Upload.CopyToAsync(fileStream); } var emptyPost = new Post_info(); if (await TryUpdateModelAsync<Post_info>( emptyPost, "post_info", // Prefix for form value. s => s.Post_ID, s => s.Category_ID, s => s.DatePosted, s => s.Rating, s => s.Description,s =>s.Country,s => s.City, s => s.Region, s => s.IdentityID)) { _context.Post_info.Add(emptyPost); await _context.SaveChangesAsync(); return RedirectToPage("./Index"); } PopulateCategoryDropDownList(_context, emptyPost.Category_ID); return Page(); } } 

}

Getting variable from cs file to the cshtml file in Razor Page Click here
no image

VS plugin for more shortcuts?

Basically i want to get away from R# but i really like some of the shortcuts, eg most importantly Introduce Variable.

Do you know some plugins with more shortcuts?

VS plugin for more shortcuts? Click here
no image

Docxtemplater for Dot Net Core

Really impressed with Docxtemplater how you can write loops and conditions on the Word Doc itself and pass JSON to replace it. But it doesn't have the support to work with Dot Net Core on the server side. Is anyone using something similar with C# on the server side. Open Source solution would be good.

https://docxtemplater.com/

Docxtemplater for Dot Net Core Click here
no image

EF Core: Reference Documents from multiple Tables

I have a web application where documents can be attached to different forms. The classes would look for example like this

public class Application { public ICollection<Document> Documents { get; set; } public ICollection<Document> Photos { get; set; } } public class Review { public ICollection<Document> Documents { get; set; } } 

I would like to have a simple mapping. Every document can only get referenced once.

What would be the best way to configure EF Core with fluent configuration? When I don't configure anything I get one column per reference on my Document Table, which seems not necessary for my use case.

Would be great if someone can give me useful hint on how to achieve this.

EF Core: Reference Documents from multiple Tables Click here
no image

MongoDB Entities v3.6 released with Many-To-Many relationship support

The goal of this library is to simplify access to mongodb by wrapping up the official C# mongodb driver and providing some additional features on top of it. You get all the power of the official driver and then some. The API is clean and intuitive resulting in less lines of code that is more readable/ human friendly than driver code.

You never have to deal with ObjectIds or BsonDocuments. Everything will be type safe. You can get the best of both worlds by modelling your entities in either Document/NoSQL stye or Relational/SQL style or a mix of both.

There is built-in automatic support for One-To-One, One-To-Many and Many-To-Many relationships.

Data can be queried using either LINQ or lambda expressions.

Supports both ASP.Net Core and .Net Core applications.

Code Sample

```csharp //Initialize database connection new DB("bookshop");

//Create and persist an entity var book = new Book { Title = "The Power Of Now" }; book.Save(); //Embed as document var dickens = new Author { Name = "Charles Dickens" }; book.RelatedAuthor = dickens.ToDocument(); dickens.Save(); //One-To-One relationship var hemmingway = new Author { Name = "Ernest Hemmingway" }; hemmingway.Save(); book.MainAuthor = hemmingway.ToReference(); //One-To-Many relationship var tolle = new Author { Name = "Eckhart Tolle" }; tolle.Save(); book.Authors.Add(tolle); //Many-To-Many relationship var genre = new Genre { Name = "Self Help" }; genre.Save(); genre.AllBooks.Add(book); //Queries var eckhart = DB.Collection<Author>() .Where(a => a.Name.Contains("Eckhart")) .SingleOrDefault(); var powerofnow = genre.AllBooks.Collection() .Where(b => b.Title.Contains("Power")) .SingleOrDefault(); var selfhelp = book.AllGenres.Collection().First(); //Delete genre.Delete(); book.Delete(); tolle.Delete(); 

```

Wiki/Getting Started

in order to get started using the library please see the wiki pages.

MongoDB Entities v3.6 released with Many-To-Many relationship support Click here
Monday, April 29, 2019
no image

[Linux][Visual Studio Code] Debug.Fail("") throws exception but Debug.Assert(false) does not

Basically what the title says, I'm a beginner c# developer and I'm running into some confusing behavior with Debug.Assert. Am I not supposed to see any messages from Debug.Assert?

.-/+oossssoo+/-. arash@arash-ThinkPad-X1-Carbon `:+ssssssssssssssssss+:` ------------------------------ -+ssssssssssssssssssyyssss+- OS: Ubuntu 18.04.1 LTS x86_64 .ossssssssssssssssssdMMMNysssso. Host: 3444CUU ThinkPad X1 Carbon /ssssssssssshdmmNNmmyNMMMMhssssss/ Kernel: 4.15.0-47-generic +ssssssssshmydMMMMMMMNddddyssssssss+ Uptime: 1 hour, 16 mins /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/ Packages: 3345 .ssssssssdMMMNhsssssssssshNMMMdssssssss. Shell: bash 4.4.19 +sssshhhyNMMNyssssssssssssyNMMMysssssss+ Resolution: 1600x900, 1920x1080 ossyNMMMNyMMhsssssssssssssshmmmhssssssso DE: GNOME 3.28.3 ossyNMMMNyMMhsssssssssssssshmmmhssssssso WM: GNOME Shell +sssshhhyNMMNyssssssssssssyNMMMysssssss+ WM Theme: Adwaita .ssssssssdMMMNhsssssssssshNMMMdssssssss. Theme: Ambiance [GTK2/3] /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/ Icons: Ubuntu-mono-dark [GTK2/3] +sssssssssdmydMMMMMMMMddddyssssssss+ Terminal: terminator /ssssssssssshdmNNNNmyNMMMMhssssss/ CPU: Intel i7-3667U (4) @ 3.200GHz .ossssssssssssssssssdMMMNysssso. GPU: Intel 3rd Gen Core processor Graphics Controller -+sssssssssssssssssyyyssss+- Memory: 3492MiB / 7795MiB `:+ssssssssssssssssss+:` .-/+oossssoo+/-.

[Linux][Visual Studio Code] Debug.Fail("") throws exception but Debug.Assert(false) does not Click here
no image

How to make Entity and/or Identity Framework hide the PasswordHash column?

Hi all! So i have in my projects this query

var thread = context.threads.Include(t => t.posts).ThenInclude(p => p.ApplicationUser).Include(t => t.ApplicationUser).Include(t => t.movie).Where(t => t.Id == id);

The only problem is this query returns the whole ApplicationUser object so that includes his hashed Password like this:

https://i.ibb.co/jJp5mdT/253235253.jpg

(Dont even know why i hide the data, its just a dummy user).

how could i hide it to not return it? I tried to use Select in the query but that allows you only to select columns from the "main" table of the query (in this example its threads).

How to make Entity and/or Identity Framework hide the PasswordHash column? Click here
no image

VS 2019 won't regen EF models in database first mode

https://developercommunity.visualstudio.com/content/problem/438312/vs-2019-preview2-after-saving-edmx-code-is-not-gen.html

I know we don't want to post every little bug we find, but this seems significant. In short, if you generate your EF layer using database first, and then go back to "Update Model from Database" because you made some schema changes, or added a table...it won't work in VS2019. They will have it included in version 16.1, but I don't know what the release date is for that yet.

It's a pretty significant but in my opinion. I prefer code first, but sometimes you inherit projects that come database first.

VS 2019 won't regen EF models in database first mode Click here
Sunday, April 28, 2019
no image

Better way to accept Func parameter than IActionResult SafeExec(T param, Func operation)

I have this method in the base class

protected IActionResult SafeExec<T>(T param, Func<T, IActionResult> operation) {

try {

return operation.Invoke(param);

}

catch (Exception ex) {

if (ex.IsCritical()) {

throw;

}

Logger.Error(ex);

return StatusCode((int)HttpStatusCode.InternalServerError, ex.ToStringVerbose());

}

}

Calling it is a little awkward

SafeExec(buildHierarchy, (_buildHierarchy) => {

...

return Ok(helper.GetJochierarchy(items.ToList(), _buildHierarchy));

});

Is there a way I can write that so calling it can be done with just a lambda type function syntax. Like this:<code>

SafeExec(buildHierarchy => {

...

return Ok(helper.GetJochierarchy(items.ToList(), buildHierarchy));

});

Better way to accept Func parameter than IActionResult SafeExec<T>(T param, Func<T, IActionResult> operation) Click here
no image

sempack - .Net Core tool bringing semantic versioning to .NET Core nupkgs

sempack is a dotnet core CLI tool that brings semantic versioning back to dotnet core nuget packages.

Problem:

After migrating some of our projects from .NET framework over to .NET Core, we discovered our semantic versioning was broken.

Solution

sempack will modify the csproj file to include semantic versioning while packing the nupkg.

Let me know if you have any thoughts or questions!

sempack - .Net Core tool bringing semantic versioning to .NET Core nupkgs Click here
no image

Is it still worth it to go to Build this year?

Hey all. I'm thinking of heading to Build, but I'm a little late. The post work sessions are already booked up and obviously it's extremely expensive.

Anyone been? Was it worth the price of admission, even with the reduced value at this later date?

Is it still worth it to go to Build this year? Click here
no image

Benefits of dependency injection and late binding?

I'm reading a book right now call Dependency Injection in .NET. I know the basics of dependency injection and I've always just seen it as a means to be able to unit test methods. This book explains how this is just one of the many benefits and I'm trying to fully comprehend how late binding is beneficial.

The author gives a Hello World example where he passes a dependency into a Salutation class like this...

IMessageWriter writer = new ConsoleMessageWriter();

var salutation = new Salutation(writer);

salutation.exclaim("Hello DI");

Console.ReadLine();

Okay, I'm with him. The Salutation class no longer depends on ConsoleMessageWriter and could be swapped with other classes without changing Salutation. Then the author does this to show you could using the Configuration Manager to pull the dependency using reflection like this...

var typeName = ConfigurationManager.AppSettings["messageWriter"];

var type = Type.GetType(typeName, true);

IMessageWriter writer = (IMessageWriter)Activator.CreateInstance(type);

var salutation = new Salutation(writer);

salutation.exclaim("Hello DI");

Console.ReadLine();

The second example uses late binding because you don't know which instance at compile time will be used to pass to Salutation. Theoretically you don't have to deploy again because you could just change the app.config to choose your new dependency. However, this only works if you already have the other class you want passed already belongs to the deployed project, correct?

They talk about not having to redeploy, but if you want a new dependency passed, you would still need to modify the project by adding a new class and then rebuilding/redeploying the solution. I'm just not seeing the benefit here since how often are you just going to hop in the app config and change your dependency... usually if it changes you'll want to add a new class anyway, correct? What am I missing?

Benefits of dependency injection and late binding? Click here
Saturday, April 27, 2019
no image

Custom Navigation and form caching in ASP.Net Core.

I am fairly new (okay very new) to ASP.Net core, and am trying to figure out how to handle a request from our user group. This is my groups first foray into a web-based app (all of our previous apps were windows form-based).

We currently have a create wizard page. There are a total of 5 different objects being created via this page so a ViewModel was chosen (easy enough to this point). One of the objects is a Customer object. The request is that we put a search icon next to the name fields. The end user could click the search icon and go to the Customer Search page (again easy enough), they would put in their search criteria and select a customer to use. At this point the request is to take them back to the wizard page (with the selected customer object). They want all previous information entered to be saved and repopulated, and then the Customer information all populated for the end user to see.

Is the TempData the best way to be saving all of the existing information or is there something better? Should I also be using the TempData to pass the selected Object back to the wizard page?

There is another object where I would be doing the same thing on the form if that has any impact on the answer.

Thanks.

Custom Navigation and form caching in ASP.Net Core. Click here
no image

.NET Core Silently Surpassed Node.js in Google Trends - ASP.NET Core Will Soon Too!

I know Google Trends are not much relevant, but it can be a good parameter of global interest. Node.js and .NET Core are two hot topics among developers these days. Node.js was released in 2009, and Microsoft introduced .NET Core in 2016, almost seven years later.

Node.js is backed by huge open-source communities of JavaScript and TypeScript. Microsoft adopted this culture just a couple of years ago and has gradually become one of the open-source leaders. MS has developed some amazing things recently, and .NET Core is one of them.

Developers love .NET Core very much. Being the true successor of .NET, only at the age of three, it already offers a rich ecosystem. .NET Core has surpassed Node.js in the search term, and its web framework ASP.NET Core will soon do the same. It is very satisfying to see an amazing technology like .NET Core is getting some traction, cheers!

Google Trends Link - https://trends.google.com/trends/explore?date=all&q=node.js,.net%20core,asp.net%20core

Node.js vs .NET Core vs ASP.NET Core - Google Trends

.NET Core Silently Surpassed Node.js in Google Trends - ASP.NET Core Will Soon Too! Click here
no image

Microservice architecture and .NET Core

Hi, I am trying to learn the microservice architecture in .NET Core but I am unable to find any material, course, book that will take with from the basics. I tried pluralsight too but couldn't find anything. Do you guys have something that can help me start? Thx!!

Microservice architecture and .NET Core Click here
no image

Where to find c# data structures examples coded out?

I like to brush up on comp sci stuff occasionally. Does anyone know a single resource that shows common examples coded out for data structures like linked list, stacks, queues, hash maps, etc?

There are some cool hacker rank videos on YouTube by the author of cracking the coding interview where she shows linked list coded out and she’s goes over some of the basics of the others but doesn’t necessarily code them out.

I was hoping to find a comprehensive list of all of these data structures coded out (preferably in C#). Hash maps and trees are of the most interest to me since stacks and queues are pretty simple.

Thanks!

Where to find c# data structures examples coded out? Click here
no image

Is anyone using Emacs, Vim, or some other robust editor for an IDE?

A couple years back I started using Emacs for some new work I was doing. It wasn't .Net at the time and so it seemed like a good took for that job. I ended up really liking Emacs and started to integrate into more of my day to day things.

Eventually I got it setup for .Net work and it actually handles rather well. It is better for Core since that is more command line friendly, but works for most of my needs. I now only open vs when I have some serious debugging and stepping through to do.

Does anyone else use tools that are more off the beaten trail? I would be interested to hear what those are.

Is anyone using Emacs, Vim, or some other robust editor for an IDE? Click here
Friday, April 26, 2019
no image

Making collapsible element inside loop using Bootstrap

Hello, Im making collapsible elements for each table row inside of a foreach loop. The collapsible element shows an image when clicked.

My code snippet for the collapsible element is as follows:

@foreach (var item in Model) { <tr> <td> <nav class="navbar navbar-collapse navbar-dark"> <a data-toggle="collapse" href="#@item.Title"> @Html.DisplayFor(modelItem => item.Title) </a> <div class="collapse navbar-collapse" id="@item.Title"> <img src="@item.FlyerUrl"/> </div> </nav> </td> 

This works wonderfully for the first row only. The other rows are not responsive. The HTML is correct for the rest of the rows as well, but they dont collapse like the first one.

Making collapsible element inside loop using Bootstrap Click here
no image

.NET web API GET from azure db

I have a Web API that I'm currently running locally to an Azure Database the is generated through the API. I can successfully POST to the database but I cannot GET. I'm attempting the GET through postman

https://i.redd.it/wymuarw3dqu21.png

I took the code first approach via EF core. I created the server and got the connection strings via azure. The POST works just fine but the GET gives me the above response. Is this a setting in postman or is there something level of security/authentication i'm missing with azure?

SSL cert is turn off in the settings
when I debug, the GET doesn't hit the controller

.NET web API GET from azure db Click here
no image

Moving from PHP to .NET

I grasp the concepts from a very high level but I am looking to move to .NET.

Are there any recommended frameworks that would enable me to work with .NET from an MVC approach. Preferably similar to Laravel in it's MVC approach.

Any recommendations is appreciated.

Moving from PHP to .NET Click here
no image

Anyone have experience with the ASP.NET Core React + Redux template? Looking for some help with it.

Hey guys, so as the title says, I'm working with the React/Redux ASP.NET Core 2.1 project template. I'm trying to tie it into an in-house OAuth service, so when the app initially loads, it checks to see if the oauth token exists in the session. If it doesn't exist yet, it'll redirect to continue onto the oauth flow to get the token. Once the token is received, it'll store it in the session, and (this is where my problem is) redirect the user to the React part of the app. That all happens on the server side.

So here's my problem: I'm not able to redirect the user back to the client. The app loads, it sees that the token doesn't exist in the server session, it redirects to the oauth flow, the user signs in, the user is redirected back to the app (the controller), and the token is saved in the session. At this point I need to redirect them back to the actual client-side, but if I do something like return Redirect("/");, I get an error stating that no "Index.cshtml" could be found. And that makes sense because of how this project is set up by default. There is no Index.cshtml like I would expect to render the React app.

That being the case, how can I redirect them back to the client? I've done similar flow in another app that was built more from scratch and in that app I was able to just return return RedirectToAction("Home", "Index"); after I saved my token in the session. The Home/Index.cshtml in that case was what rendered the React app, so it was easy enough. But since this new project doesn't have an Index.cshtml, so I'm not really sure how to proceed.

Thanks in advanced for the help.

Edit: One workaround I have, which is not ideal, is to redirect to a different route that isn't the base URI. So instead of doing return Redirect("/"), I can do return Redirect("someRoute"). As long as the someRoute is configured in my react router, it'll actually redirect properly to that page. Then in that page's component, in the componentWillMount, I immediately redirect them to the base URI ("/)". It's really not an ideal solution though.

Anyone have experience with the ASP.NET Core React + Redux template? Looking for some help with it. Click here
no image

Issue with aspx pages

Recently i got to work on a legacy application which is written in webforms. Client pages of the application assume their master page via code,however when no master page is assigned in the page directive of aspx pages , autocomplete of visual studio goes nuts and doesn't recognize asp tags. Anybody happen to know the fix?

Issue with aspx pages Click here
no image

JetBrains Rider on OS X or Visual Studio on Windows?

I do most of my .NET development in Emacs and I intend to continue doing so. However, I am missing some tools, specifically:

debugger ReSharper test coverage profiling IR/CLR inspection 

I can get some of this running Rider natively OS X, and JetBrains continuously adds more. I could get all of it by inställning a Windows VM and running Visual Studio in that. The second option would be more expensive, but it may be worth it. What are your experiences? Other advice?

JetBrains Rider on OS X or Visual Studio on Windows? Click here
The webdev Team