I wanted to point out one difference between ConfigurationManager and WebConfigurationManager. I know there are other differences but here’s an issue I ran into recently.

I’ve been working on some Bot Framework stuff (really cool and fun, by the way). The Bot uses a QnAMakerService and QnAMakerDialog which worked great when I ran the Bot locally (debugging in Visual Studio) but it didn’t work when I deployed it to Azure. I knew that a lot of features of my bot were working but when it needed to use the QnA features it was just bombing out. A coworker helping out said he fixed my problem by putting settings in for the QnaSubscriptionKey and QnaKnowledgebaseId via the Azure Portal (navigate to your App Service, then Settings > Application Settings)

image

 

Yeah, I knew those were needed of course, but I had already added them. The settings were in my web.config file:

image

I was glad the Bot was working and I had a major clue to my issue. I wasn’t going to let it end there. Why weren’t the web.config settings being used? I took a close look at my code:

[Serializable]
public class QnADialog : QnAMakerDialog
{
public QnADialog() : base(new QnAMakerService(
new QnAMakerAttribute(
ConfigurationManager.AppSettings[“QnaSubscriptionKey“],
ConfigurationManager.AppSettings[“QnaKnowledgebaseId“],
Sorry, I couldn’t find an answer for that“,
0.5)))
{
}
}

The code seemed pretty straightforward. As a matter of fact, I recalled copying it from a sample on the web! Then I noticed that the code was using “ConfigurationManager” which was not the normal thing for me. I usually create web applications and I therefor use “WebConfigurationManager” to read from web.config files. And since my bot runs as an App Service in Azure, it IS a web application. I proceeded to make the major refactor of adding the text “Web” to the word “ConfigurationManager”. I then removed the Application Settings from the Azure Portal, leaving the values I had previously entered into the web.config file. And it worked perfectly.

As developers we have a variety of options to access configuration data and that data can be stored in several places. In addition to the two previously mentioned, there is also the CloudConfigurationManager class. My understanding is that this would have worked similarly to WebConfigurationManager. And, in fact, good old plain ConfigurationManager would have worked fine for this Azure App Service if I used the Portal to set my app settings instead of the web.config file. So, choose carefully and get to know the differences between the ConfigurationManager classes

Well, this was one of those bugs that took a while to figure out and of course the solution was pretty simple.

It turns out that this:

[EnableCors(origins: “http://MyWebsite.com”, headers: “*”, methods: “*”)]

is not the same as this:

[EnableCors(origins:”http://mywebsite.com”, headers: “*”, methods: “*”)]

I have some JavaScript that calls an ASP.NET web API method on another domain. Let’s pretend that the API is on myservice.com and the website is on mywebsite.com. As you can guess, I was having some issues and getting an error similar to this:

Failed to load http://myservice.com/api/SomeController/SomeMethod: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://mywebsite.com is therefore not allowed access.

I tried a lot of things to figure out what was going on. I knew that I had the CORS attribute on my controller and I had config.EnableCors(); set up in my Web API configuration. This is one of the first times I’m using CORS on Azure so I thought it had something to do with Azure, but that was not correct. After trying many, many hacks with no success and staring at my EnableCors Attribute, I had the “crazy” idea to change “http://MyWebsite.com” to ”http://mywebsite.com” and of course, everything worked fine. From now on, I’ll use all lowercase!

I hope you won’t get stuck wasting as much time as I did trying to figure this one out!

What? You haven’t registered for the best developer conference in the Northeastern U.S. yet? Well don’t worry, there is still time. First, let me tell you why you need to attend.

Full disclosure: I am a founding board member of the TechBash Foundation. Myself and a few other people run this event for the community. We make no money from the event. All fees and revenue generated by TechBash are put directly into the event to cover costs.

OK, on to it…

What is TechBash?

TechBash is a 3 day developer conference. If you are interested in topics like .NET, Web, Cloud, JavaScript, DevOps, Architecture, Patterns, Mobile, Frameworks and more, you should be at TechBash.

Why should you be at TechBash 2017?

I’ll summarize and you can read on below for more details:

1. Content – TechBash has got great content. Want to learn about the latest frameworks and patterns from industry experts? We’ve got them. Want to hear directly from Microsoft employees and MVPs? We’ve got plenty of them. TechBash is bringing in the best speakers from top tech companies to deliver content to you. read more…

2. Location TechBash is organized by a small group of developers who were tired of traveling across the country for good content. So now they are bringing the content to you. TechBash is in the Poconos in Pennsylvania. That’s less than a 2 hour drive from NYC or Philly. Plus, the short drive time means you won’t need to ask your boss for two extra travel days. read more…

3. Price. Book now and you can register for TechBash plus 3 nights in the hotel for less than $1000. That’s a great price for a conference of this caliber. Plus, no airfare needed so TechBash fits into your budget!  After 9/8 hotel rates may vary. read more…

4. Venue  The Kalahari Resort. This is the largest indoor water park in the country. So while you are coming to learn and network with tech leaders from around the country and meet up with old friends and new, you can have a little fun and hit the water slides. read more…

5. Fun for the Family – Yes, it’s a huge water park. But there are a ton of other activities at the Kalahari Resort and nearby. Plus, Friday afternoon we have Sara Chipps hosting a Jewelbots build event for kids 8 and up. They can learn to code too. read more…

 

Plus, if you want to bring the whole team, contact us regarding group discounts: info@techbash.com

 

Great Content – Learn from the best

We’ve got great speakers from top tech firms around the country coming in to speak to you. And you may notice these are some of the same speakers that you’ll see at much more expensive conferences. Here are a just few of our featured speakers:

image

 

And if you are interested in content direct from Microsoft, we’ve got that too:

image

OK, here is a full list of our speakers. You can see our current schedule on our website.

Alon Fliess, Ambrose Little, Anne Bougie, Anoop Kumar, Ashley Grant, Bill Wolff, Cameron Presley, Chris Houdeshell, Damian Brady, Danny Brown, Dave Voyles, Donovan Brown, Eran Stiller, Erika Carlson, Gajan Pathmanathan, Jason van Brackel, Jeffrey Fritz, Jeremy Clark, Jim Wooley, Joseph Guadagno, Joshua Garverick, Ken Dale, Kevin Griffin, Lee Brandt, Nate Barbettini, Nick Landry, Ondrej Balas, Oren Novotny, Paul Hacker, Richard Taylor, Sam Basu, Sara Chipps, Scott Allen, Scott Kay, Stephanie Herr, Stephen Bohlen, Steve Michelotti

Location – If you are in the Northeast, we are close by

Just check out the map below. We are about 2 hours from NYC, NJ, and Philly. We are close by to Delaware, Central and Western PA, NY State, Maryland, DC and much more. The best part is that you don’t need to sit on long flights or ask the boss for extra travel days just to attend TechBash! Oh, and that means travel costs are lower too.

image

Price – The Price is Right!

TechBash fits your budget! An all access ticket to TechBash is only $349. That includes 3 days of content plus breakfast, lunch and coffee/snacks too. Compare that price to some other conferences and see what you think. Of course, you’ll need to stay over for a few nights. We’ve got great prices reserved at the Kalahari Resort (use group id 1145) and if you book quickly you can still get the conference registration and 3 nights in the hotel for under $1000. That is an incredible deal for the content we provide. If you need help convincing your boss, check this out.

Venue – The Kalahari Resort is AWESOME!

To start, The Kalahari is a first class conference center with plenty of Wi-Fi to go around! The place was brand new last year and this year they expanded to add another 500 hotel rooms. Plus, it is now the largest indoor waterpark in the country! So after you are done learning from the best, hit the slides and have some fun!

imageimageimageimageimageimageimageimage

Family Fun – There is plenty to do!

Bring the whole family to TechBash! The kids will love the waterpark but that isn’t all there is for families. This year TechBash is very proud to announce that Sara Chipps will be offering a hands-on event for kids ages 8 and up to learn to code and work with Jewelbots. Kids will learn entry level coding and Arduino. Plus there is face painting, crafts, and more! There is a $10 ticket required to cover costs for this. Check out all of the great stuff to do while at TechBash on our site. We’ve got a ton of ideas.

I hope I’ve shown you why TechBash is the best conference for you. Contact me via my blog if you have any questions.

Thanks,

Andy

If you find yourself stuck because you need to use EF 6 features in an ASP.NET Core web app with Identity, don’t worry, it is easy!

Like many of you, I am trying to get all caught up with ASP.NET Core. It has some great features and I’ve been looking forward to using it. I finally have a new project to start so Core was my first choice.To expand on that a bit, I am using ASP.NET Core with the full .NET Framework. At this point, I don’t need to use .NET Core in cross platform scenarios.

It wasn’t long after I got started that I ran into what I thought was a big problem.Spoiler Alert: It wasn’t a big problem at all!

A new project created for ASP.NET Core (configured to use Individual Accounts for security) will be all loaded up with Entity Framework Core as well as Controllers and Views and Code to make all the authentication stuff work. This post isn’t about that. It was all working nicely. That is, until I needed Entity Framework Spatial Types with SQL Server. My website needs to calculate distance between two points, something that is surprisingly easy with the right tools. However, EF Core doesn’t yet support that! I’d needed EF 6 instead. Now, this is where I made my big mistake. I assumed that I couldn’t have EF 6 and EF Core in the same project so I removed all of the EF Core stuff. I began to set up EF 6 instead and ran into issues wiring things up with ASP.NET Core. To set up all of the Dependency Injection stuff and wire up services, you need code like this:

services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();

But it turns out that AddEntityFrameworkStores doesn’t exist in EF 6. This got me going on all kinds of research, trial and error. All for nothing.

You see, I was going about this all wrong.

Thanks to some help from Julie Lerman (Entity Framework Guru and fellow Microsoft MVP) and Diego Vega (from the EF team at Microsoft), I found out that I could in fact run EF 6 and EF Core in the same project! All I needed to do (after getting all of the EF Core nuget packages all loaded up again) was create 2 DbContexts! One with EF Core for the Identity stuff. And one with EF6 for my application logic (so I can use the spatial features including DbGeography). At first, I had a some namespace confusion because there are classes with the same names in EF 6 and Core. But that was easily resolved.

It’s great when the solution is so simple.

This past Friday, I had the pleasure to present a full day of content at day 1 of Philly Code Camp. My talk has an odd title: “End to End Development With Schwammy’s Favorite Patterns and Practices” This was the fourth time I did this talk and it has sold out very quickly each time so far. So I guess the silly title makes sense to people. Or maybe it’s that they read the description:

To create excellent software, you need to know a lot more than just the language basics. If you are an experienced developer looking to take things to the next level, this talk is for you. In this talk I’ll present many patterns and practices that I use as a Technical Architect. I’ll review and demonstrate many of my favorite patterns such as SOLID, Repository Pattern, Unit Of Work, Dependency Injection, etc. I’ll show how these patterns can be used for both server and client side development in ASP.NET MVC. I’ll demonstrate great ways to use TFS for automating your builds and deployments. During this full day session I will create a web application using VS2015, C#, ASP.NET MVC, Entity Framework, SQL Server, Bootstrap, Knockout.js and ELMAH. Unlike in traditional short talks, with the full day session you’ll see how all the pieces fit together. As always, I’ll throw in lots of tips and tricks along the way. FYI: this is a repeat (with some updates) from my popular full day session from the last Philly Code Camp. The session will not be hands-on for attendees however I’ll provide the complete solution with which you can review and experiment.

It’s a jam packed day – about 7.5 hours of me talking. I’m truly honored that people sign up to spend the day with me. Thanks to all of the attendees who participate and ask questions and make it a great day. Of course, a big thanks to the Philly.Net team Bill Wolff, Rob Keiser, Ken Lovely and a bunch of other great people who run that event so well year after year. I know how hard it is since I used to be one of them Smile.

So here is all the content. I’ve posted it before but this is the most up to date version:

Good luck, it was never really meant to stand on its own so it may not make sense. If you have any questions, let me know.