AD Authentication ASP.NET Core 2.0

AD Authentication ASP.NET Core 2.0 | ASP.NET Core and Azure AD have been kind of my passion for the last year. Naturally with ASP.NET Core 2.0 coming out I wanted to see what had changed in the area of authentication. I made an article on enabling Azure AD authentication in ASP.NET Core 1.0 almost a year ago.

ASP.NET Core 2.0 authentication changes

Many things have changed in 2.0. Authentication is one of them. I will go through changes to other parts in future articles.

In ASP.NET Core 1.X, authentication middleware were registered in the Configure method in the Startup class. That has had a major change. There is now only a single middleware that you add:

Other middleware, like cookie authentication middleware need not be added.

Instead, authentication is now done through services. You will add them in ConfigureServices. Here for example we add cookie authentication.

Another thing that has changed is that we can now define the default authentication/challenge/sign-in handler in one place. You can see an example of the new approach in the next section.

Setting up Azure AD authentication in Startup

In an MVC application that wants to use Azure AD authentication, we need two authentication handlers:

  1. Cookies
  2. Open Id Connect

We can add them to the service collection like this:

Cookies is responsible for two things:

  1. Signing the user in (creating the authentication cookie and returning it to the browser)
  2. Authenticating cookies in requests and creating user principals from them

Open Id Connect is responsible for only one thing really: Responding to challenges from [Authorize] or ChallengeResult returned from controllers.

When it receives a challenge, it sends the user to authenticate against the identity provider (in this case Azure AD). When the user gets redirected back to the app, it does a multitude of things to authenticate the returned info, and then requests the default sign-in handler to sign the user in.

So let’s configure the default handlers:

Note there that by default, cookie authentication handles authentication and sign-in. Open Id Connect only handles challenges. In 1.X, these would have been defined in the middleware options (except for the default sign-in middleware).

Then we need to add the authentication middleware to Configure as mentioned before:

For basic scenarios, we are actually almost done. Just one thing missing, the configuration!

Configuring Open Id Connect automatically/slightly manually

Previously we added Open Id Connect authentication like this:

If you check it’s documentation, it says:

Adds OpenIdConnect authentication with options bound against the “OpenIdConnect” section from the IConfiguration in the service container.

So, it expects you have a section like this e.g. in appsettings.json:

And in user secrets:

These will automatically map to properties in OpenIdConnectOptions.

So, configuration? Done.

Now, in some cases you want to e.g. define handlers that do something when you receive the authorization code.

There’s just one small thing. When you specify handlers like this:

Configuration is not bound in this case. You can do that however just by adding one line of code:

If you just need the authentication and no access tokens to APIs etc., the first option with no arguments that auto-binds to the configuration is best.

Otherwise, at least bind options from configuration so you don’t have to type configuration keys manually.

Here is a more complete example of configuring Open Id Connect:

We first bind the configuration section “Authentication” to the Open Id Connect options. Then we setup an event handler for when we get an authorization code from Azure AD. We then exchange it for an access token for Microsoft Graph API.

The token cache class that I made here uses the distributed cache to store tokens. In development that would be a memory-backed cache, but in production it could be backed by a Redis cache or an SQL database.

Now while the handler can acquire an access token, I prefer using ADAL/MSAL as tokens then get cached, and it handles token refresh automatically.

We also setup an exception filter for MVC so that if ADAL token acquisition fails (because the token was not found in cache), we redirect the user to Azure AD to get new tokens. The reason why we use the absolute newest bits (at the time of writing) in the sample app on GitHub, is because Automatic ChallengeBehavior is finally gone in these versions 🙂 Now when you return a ChallengeResult, you get the challenge behaviour every time. If you want to return a 403, you return a ForbidResult. VS StarLogic – Which one is the best ASP.NET Core 2.0 Hosting VS StarLogic – Which one is the best ASP.NET Core 2.0 Hosting | Best and cheap ASP.NET core 2.0 hosting. ASP.NET, as a free and powerful framework, is highly recommended to build great web sites. Since a large number of web hosting providers swarm into ASP.NET hosting market, there are abundant options in front of people.

After reviewed 80+ Windows ASP.NET hosting, we had come out with the best Windows ASP.NET hosting, Microsoft control libraries, databases, Microsoft technical support, and web hosting price. To make your buying decision easy we have the Windows ASP.NET Hosting providers which are reliable and offer Cheap Windows ASP.NET Hosting so that everyone can afford it.

ASP.NET Core 2.0 Hosting – VS StarLogic Windows ASP.NET hosting is Microsoft No #1 Recommended Windows and ASP.NET 5 / ASP.NET Core 1.0 Hosting in European Continent. They proudly announce that they are the leader in ASP.NET 5 / ASP.NET Core 1.0 Hosting Technology. They have provided a wide-range of ASP.NET service, starting from the Classic ASP, ASP.NET1.1 Hosting, ASP.NET 2 Hosting, ASP.NET 3.5 Hosting, ASP.NET 4 Hosting, ASP.NET 4.5 Hosting, ASP.NET 4.5.1 Hosting, ASP.NET 4.5.2 Hosting, ASP.NET 4.6 Hosting and the latest ASP.NET 5 / ASP.NET Core 1.0 Hosting.


Startlogic is one of the biggest shared hosts around, with years of experience. They do offer diverse plans and prices are competitive. Startlogic obviously is looking for large user base to to make sense of their pricing. VS StarLogic Hosting Features Windows ASP.NET hosting releases four plans called Classic, Budget, Economy and Business at the prices of €3.00/month, €5.50/month, €8.00/month and €11.00/month if you choose annual payment method. Three billing cycles with different prices are available in best ASP.NET hosting package. You can choose between 3-months, 1-year and 3-years payment methods. also supports 30-days money back. On the contrary, offers Starter, Bronze, Silver and Gold plans with £5.24/month, £7.43/month, £9.38/month and £11.24/month if you choose 3 years payment method.



StartLogic offers three shared hosting plans.

● PersonalLogic is a limited, low-cost plan marketed a beginners. Pro Logic is effectively an upgrade to that plan which includes free gifts, unlimited resources and eCommerce tools. Pro Logic also allows customers to host unlimited domains. Both appear to be Linux-based.

● The WindowsLogic plan is an equivalent to the ProLogic plan, but provided on Windows 2003 server. Customers can host unlimited domains on WindowsLogic.

In addition to shared hosting, StartLogic offer three VPS hosting plans: VPSLogic, VPSLogic Pro and VPSLogic Premium. The amount of disk space, bandwidth and memory increases with the price, as does the number of domains that can be hosted. All plans include one IP address.

Screenshot_5 VS StarLogic Hosting Uptime Windows ASP.NET hosting currently operates data center located in Amsterdam (Netherlands), London (UK), Washington, D.C. (US), Paris (France), Frankfurt (Germany), Chennai (India), Milan (Italy), Toronto (Canada) and Sao Paulo (Brazil) Data Center. All their data center offers complete redundancy in power, HVAC, fire suppression, network connectivity, and security. Their data center has over 53,000 sq ft of raised floor between the two facilities, HostForLIFE has an offering to fit any need. The datacenter facility sits atop multiple power grids driven by TXU electric, with PowerWare UPS battery backup power and dual diesel generators onsite. Their HVAC systems are condenser units by Data Aire to provide redundancy in cooling coupled with nine managed backbone providers.

EIG-owned web hosting companies generally don’t provide any uptime guarantee, and it appears that StartLogic is no different. The company does not publish an uptime statistics either.

StartLogic’s data centres are located in Boston, MA in the USA. It appears that the company doesn’t own them itself. In total, the two data centres contain 800 Dell servers, The data centre specification is fairly standard, and security is provided on-site 24/7. Both facilities run in N+1 power and utilise redundant routers, two firewalls and clustered server technology. VS StarLogic Hosting Support award-winning supporting team is ready to help people around the clock. People can search help via 24/7 live chat, tickets and email. What’s more, the supporting staffs are professionals with Networking and Computer Science degree. Even experienced senior networking technicians and software developers are responsible for answering questions. What’s more, also provides you knowledgebase includes web hosting article and tutorial to help you solve the hosting problem. While the support department at StartLogic is open round the clock, with support offered via live chat and telephone (via a US toll-free number). It’s not clear where the support team are physically located. StartLogic’s support portal is pretty much identical to other EIG-owned hosts’ support areas, with a knowledgebase, user guide and tutorials. The support information provided is fairly basic, but would suffice for a beginner.

Recommendation ASP.NET Core 2.0 Hosting

As shared web hosting, StartLogic is a fairly standard, unremarkable host. The company that owns StartLogic, EIG, is truly massive, and many of their hosting companies are almost uniform in the hosting products they offer. StartLogic is no different. Across the board, their shared plans are very similar to their competitors’. Features and pricing are all quite standard, and support is also a carbon copy of other EIG hosts’ sites. So, for reliable Windows ASP.NET Hosting, we would recommend

Best Indian ASP.NET Core 2.0 Hosting Comparison – VS Square Brothers

Best Indian ASP.NET Core 2.0 Hosting Comparison – VS Square Brothers | Best and Cheap ASP.NET Core 2.0 hosting in India. Compare the web hosting plans of popular web hosting providers with that of with this most elaborate list of feature comparison and check out how we stack up against them.

To choose the best Windows hosting for your websites, we will compare two of this India Windows hosting providers in the industry. This VS Square Brothers comparison is about to make clear that who is a better option for India Windows hosting. We will focus on their plans, performance, customer service and technical support which have been tested and proven by our Microsoft professionals.

Overall India ASP.NET Core 2.0 Hosting Review

ItemWindowsASPNETHosting.inSquare Brothers
Price ***** ****
Features ***** *****
Uptime ***** ****
Speed ***** **
Technical Support  ***** ***

wI35 is the India’s #1 Windows hosting provider that offers the most reliable world class Windows hosting solutions for customers. provides high quality affordable India’s Windows hosting services for personal and companies of all sizes. You can host your website with an innovative, reliable, and a friendly India’s Windows hosting company who cares about your business.


Square Brothers has been working in web hosting field for eight years. At this time, they are providing servers and web host to more than 33000 domains. They are providing now web hosting on Linux, Window, Window reseller hosting, Linux Reseller hosting, VPS Hosting. They are situated in Chennai, Tamil Nadu. Their main motive is appeasement of costumers. They also treat their costumer as family member and costumer’s trouble as their own trouble. VS Square Brothers: Pricing & Features releases four plans called Personal, Developer, Business and Expert at the prices of INR 159.99/month 35% OFF , INR 299.99/month 35% OFF , INR 679.99/month 35% OFF andINR 1099.99/month 35% OFF . Three billing cycles with different prices are available in best India Windows hosting package. You can choose between 3-months, 1-year, 3-years and 5-years payment methods. also supports 30-days money back guarantee. On the contrary, Square Brothers offers several kinds of India Windows hosting plan starting from INR 999/year in regular time. Square Brothers only provide the costumers yearly payment method.

In below, we create a feature-comparison table of this two best India ASP.NET Core 2.0 hosting companies:

ItemWindowsASPNETHosting.inSquare Brothers
Bandwidth30 GB10 GB
Disk Space3 GB1 GB
Windows Server Version 2008/2012Version 2008
IIS VersionIIS 7/7.5/8.0IIS 7
ASP.NET VersionASP.NET v. 5/4.6/4.5.2/4.5.1ASP.NET v. 2.0 /3.0/4.0
ASP.NET MVC VersionASP.NET MVC v. 5.1.1/5.15.2/
ASP.NET MVC v. 2.0/3.0
MSSQL VersionMSSQL 2008/2012/2014MSSQL 2008/2012
Complete Features MORE INFOMORE INFO

From the above comparison list, both of them are fully ASP.NET compatible. However, and Square Brothers are different from each other in many features. They both support the .NET technology, like Windows Server, IIS, isolated application pool, LINQ, AJAX, Silverlight, Full Trust, URL rewrite module. But supports almost all version of Windows Server, ASP.NET, ASP.NET MVC, IIS and MSSQL database. also supports ASP.NET 4.6 hosting with affordable price. What’s more also provides unlimited domain while Square Brothers still limit their domain. From the above table, we can conclude that has more rich-featured India Windows hosting that what Square Brothers has offered. VS Square Brothers: Uptime & Speed

To ensure uptime and speed, both and ewebIndia have been investing much money and time. leverages best-in-class connectivity and technology to innovate industry-leading, fully automated solutions that empower enterprises with complete access, control, security, and scalability. They own and operate three world-class data centers strategically located in Mumbai (India), London (UK) and Washington D.C.(US). promise you in delivering 99.9% uptime. When it comes to Square Brothers, they also located their data center in Chennai, Tamil Nadu and promise 99.9% uptime guarantee. However, most of Square Brother’s costumers are disappointed because of their slow speed website. VS Square Brothers: Technical Support offers 24/7 support through tickets, e-mail and contact form. When we contacted the their support representatives via e-mail, we got responses from within an average of 5 minutes. In the other hand, Square Brothers only provide phone call for their costumer. We’ve tried to call their support but they always show the busy tune. We do believe that has more responsive support team.

Conclusion: VS Square Brothers?

From the combination of high performance, responsive support, rich-featured hosting and reasonable pricing, we conclude that is better in serving India Windows hosting. It is clear that is a more favorable choice due to its cost-effective features and considerate customer service.

2017’s Best “ASP.NET Core 2.0 Hosting” Providers

2017’s Best “ASP.NET Core 2.0 Hosting” Providers | Best and cheap ASP.NET Core 2.0 hosting. Microsoft created and open-sourced ASP.NET as a server-side web application framework for developers to create dynamic web properties. If you’re looking for a Windows host to help you launch such a project, you’ve come to the right place. Here, our developers have thoroughly reviewed the top providers of shared hosting for Windows and ASP.NET users, specifically noting framework version compatibility, uptime rates, and storage, among other features that are mission-critical for this particular niche of developers. is the leader in ASP.NET 5 / ASP.NET Core 1.0 /2.0 Hosting Technology. HostForLIFE have provided a wide-range of ASP.NET service, starting from the Classic ASP, ASP.NET 1.1 Hosting, ASP.NET 2 Hosting, ASP.NET 3.5 Hosting, ASP.NET 4 Hosting, ASP.NET 4.5 Hosting, ASP.NET 4.5.1 Hosting, ASP.NET 4.5.2 Hosting, ASP.NET 4.6 Hosting and the latest ASP.NET 5 / ASP.NET Core 1.0 Hosting.


HostForLIFE has been recognized as one of the best ASP.NET Core 2.0 hosting For people who are unsatisfied with the services, HostForLIFE offers a 30 day money back guarantee allowing the clients to cancel their accounts within the first 30 days and getting a full refund. When it comes to the payment, two payment methods are available including CC and PayPal to ensure that every client reaches the services in a convenient way.

Recommended: We highly recommend you to host your ASP.NET website or application on web hosting. This website is also hosted with HostForLIFE and we’re sure you must have noticed the speed. You can also take advantage of HostForLIFE’s special promotion offer and can buy cheap ASP.NET (Windows) Hosting with Unlimited Bandwidth.

Affordable price for a High availability solution
Built on enterprise-grade hardware
24/7/365 Customer Care & Support
99.9& Uptime Guarantee
Dedicated App Pool
Amsterdam (NL) , London (United Kingdom), Paris (France), Frankfurt (DE) and Seattle (USA) Data Center

Best “ASP.NET Core 2.0 Hosting” Providers

hflnhfln1We highly recommend you to buy’s ASP.NET core 2.0 Hosting (Windows Hosting) for better performance & reliablity.’s ASP.NET hosting is Cheap and Unlimited only cost €3.49/mo15% OFF with Unlimited domain, Disk Space, and Bandwidth. Click Here To Know More about

Reasons to host with HostForLIFE ASP.NET Core 2.0 Hosting recommendation :

  • .NET Hosting Services tested by
  • Microsoft-Recognized .NET Hosting Companies
  • Award-Winning .NET Hosting Solutions
  • Latest .NET Hosting technologies
  • The best .NET Hosting Prices
  • Strong Customer Testimonials
  • 24×7 Phone & Email Support
  • 99.9+% Uptime Guarantee
  • Money Back Guarantee

Why HostForLIFE is the Best ASP.NET Hosting

  1. Windows OS: the latest version of Windows OS is the key point of a quality ASP.NET hosting solution. And now, the best choices are Windows Server 2012R2, Windows Server 2012 and Windows Server 2008R2. In fact, all the recommended hosting companies support the mentioned Windows operating systems.
  2. ASP.NET Frameworks: as ASP.NET websites have to run in the corresponding .NET framework, it’s better that the web host can support most of frameworks from v1.1 to v4.0. In this case that you can have maximum flexibility for you websites and keep the possibility upgrading to the higher version.
  3. ASP.NET Trust Level: it’s configured for each website by .net infrastructure. you should know the exact configuration before the payment. in our research, 70% websites can be run only under the fully trust level. if your hosting company doesn’t tell that they support fully trust, you should be careful that your website may not run correctly in the host finally. surely, you can ask for money back but it’s time wasting.
  4. RAM: this is the maximum memory in the server that can be used for your site, which is configured in IIS application pool. Only sufficient RAM allocation can bring the website a reliable hosting condition.
  5. MSSQL Edition: MSSQL makes a big difference to store all data from the website, which is a Windows based database. Note that, the latest version of MSSQL is the SQL Server 2012.
  6. Control Panel: Plesk is the best reliable control panel for web hosting but PleskPanel is the best visual and easy-to-use control panel  these two control panels are both fine in our opinion.
  7. Add-on Features: the installation required third party libraries are important when your website depends on then. E.G. Chat controls library, Altas library and more.
  8. knowledge of Microsoft technology support: you can easily call the technical support of the web host and ask some technical questions about ASP.NET website configuration and deployment. This is certainly important especially when you have a problem in the future.
How To Configuration ASP.NET Core 2.0 with Razor Pages Part 1

How To Configuration ASP.NET Core 2.0 with Razor Pages Part 1 | Best and cheap ASP.NET Core 2.0 hosting. At Build 2017, there were a lot of new features announced for ASP.NET Core 2.0, .NET Core 2.0 and .NET Standard 2.0.

Today, we’re going to look at a few of the changes, specifically: the new configuration model and Razor Pages


A lot of the changes that the ASP.NET Core team have brought to ASP.NET Core 2.0 are all about taking the basic application setup and making it as automatic, and quick and easy to change as possible. The first and easiest way that they have done this is by creating the AspNetCore.All package.

AspNetCore.All Package

In previous versions of ASP.NET Core when we’ve created an application and wanted to add in functionality, we’ve had to search on NuGet or using the Package Manager to find the NuGet packages for the functionality that we want.

This lead to a csproj which looks like this:

Re-targeting this project as a netcoreapp2.0 (.NET Core 2.0) application with ASP.NET Core 2.0 libraries, we get the following csproj file:

The AspNetCore.All package is a meta package which pulls down all of the relevant (Anti Forgery, Auth, Entity Framework Core, MVC, Static files, etc.) packages to our application when package restore happens.

Because we no longer have to track down each of these individual packages, our job is made easier. Also, when the packages within the AspNetCore.All package are updated, the updated versions will be included in the AspNetCore.All meta package.

The AspNetCore.All package is included in .NET Core 2.0’s Runtime Store, and is compiled to native code, rather than IL. This means that all of the libraries included in the AspNetCore.All package are pre-compiled as native binaries for the Operating Systems that .NET Core 2.0 supports.

Boot Time Improvements

Dan and Scott were able to show that ASP.NET Core 2.0 applications can cold boot in less than a second, versus up to 7 seconds for ASP.NET Core 1.0 applications.

The ASP.NET Core team have achieved this by shipping the AspNetCore.All package in native code for each platform, and by enabling view pre-compilation. By pre-compiling the views, they no longer have to be compiled at start up.

View pre-compilation is a trick that has been around in .NET Framework for a while, but it isn’t a default build action.

New Program Setup

This leads me nicely onto the new program setup model.

In ASP.NET Core 1.0 the program.cs file contained a single method for configuring and running the server, and there was a lot of manual configuration required. As in the following code block:

To enable server features, you had to know what those features where called or rely on intellisense in order to find the right methods.

But in ASP.NET Core 2.0, a lot of the configuration is taken care of for us. So much so that the following code snippet is the default program.cs for an ASP.NET Core 2.0 application:

From the off, you can see how much simpler the new program.cs file is. The new program.cs goes hand in hand with the new startup.cs

First a refresher on what the ASP.NET Core 1.0 startup.cs:

Configuration is handled by us developers and we have to explicitly list all configuration files and enable logging.

Compare this to the new startup.cs:

There’s a lot that’s changed here, so let’s look at the changes in turn.

The Constructor and DI

Taking a look at the constructor, we can see that the configuration is Dependency Injected in for us.

This is because all of the explicit configuration that we had to do in ASP.NET Core 1.0 is done automatically for us. ASP.NET Core 1.0 will look for any and all relevant json/ini files and attempt to deserialise them to objects for us and inject them into the IConfiguration object.

The ConfigureServices method is pretty much the same, but the Configure method has been very simplified:

In the ASP.NET Core 1.0 Configure method, we had to inject the ILoggerFactory in order to enable logging:

However, the ASP.NET Core 2.0 Configure method doesn’t have the ILoggerFactory injected in:

This is because the contents of the appsettings.json are parsed and added into the IConfiguration object which is injected in at the constructor level of the class:

If we take a look at the appsettings.json, we can see that the logging is set up for us there:

And looking at the highlighted lines, we’ll see that logging is set up so that we’ll only get warnings. This can be proven by running the application from the terminal. Doing so, and navigating around in the application, you won’t receive any messages in the terminal other than warnings:

However, if we edit the appsettings.json file to match the following:

Then re-run the application and click around, we’ll see the familiar log messages again:

Its entirely up to the developer and their needs as to which level of logging they require. I prefer information logging when I’m developing and to switch to warnings once I’ve published, but your requirements may be different.

Razor Pages

The other big new thing in ASP.NET Core 2.0 is the concept of Razor Pages. Razor Pages are enabled by default, as they are a feature of MVC, thus the following line in the startup.cs enables them:

Razor Pages cover the situations when creating a full blown Controller, View and a Model for a single or small number of pages seem a little over kill. Take for instance a simple homepage with no controller required, presumably something which could be handled by a static page, but which should have a simple model.

An example of this can be seen in the ASP.NET Core Web App (Razor Pages) template, which is installed as part of the .NET Core 2.0 preview1:

Taking a look at the directory structure for this new template, we can see that the new Razor Pages are located within the Pages directory.



Before we take a look at the contents of one of the Razor Pages, it will be worth covering how the routing for Razor Pages works. The request URL for a Razor Page is mapped to it’s path within the Pages directory – the Pages directory being the default location which the Runtime checks for any Razor Pages which could match the requested URL.

The following table shows a few examples of how the location of Razor Pages maps to requests: