IApplicationBuilder does not includes a definition for UseHealthChecks - kubernetes-health-check

As suggested at the tutorial for kubernetes health check I like to implement the health chack at my .NET Core WebApi at class startup.cs at method Configure.
But the method .UseHealthCheck() is unknown.
I don't know what creates this problem. I guess all usings are there?!?
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseHealthChecks("/health");
app.Run(async (context) =>
{
await context.Response.WriteAsync(
"Navigate to /health to see the health status.");
});
here the using:
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Identity.Client;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Protocols;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
How to fix this problem?
Thanks for your help!
Frank

Thanks mxmissile!
I add the NuGet package
Microsoft.AspNetCore.Diagnostics.HealthChecks 2.2.0
and there for also and first
Microsoft.AspNetCore.Http.Features 2.2.0
Microsoft.AspNetCore.Http.Abstractions 2.2.0
Microsoft.Net.Http.headers 2.2.0
Now the method is known.

I've found you only need to install these two
Microsoft.AspNetCore.Diagnostics.HealthChecks 2.2.0
Microsoft.Extensions.Diagnostics.HealthChecks 2.2.0

Related

Request.CreateResponse missing

Visual Studio 2019 new project Core, webAPI template project.
Controller file that comes with the project starts as such (I added .Net namespaces)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Net;
using System.Net.Http;
using System.Web;
namespace testwebapi.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class WeatherForecastController : ControllerBase
{
public HttpResponseMessage Get(string gender = "All")
{
Request.CreateResponse()
}
}
}
however the .CreateRequest() does not exist. Request is (AspNetCore.Http.HttpRequest ControllerBase.Request) and I think that is wrong but I do not know how to do it correctly.
looks like I was using the wrong project type.
it does not appear to exist in the Core version of Api web. I still need to learn the difference and why that is

.Models does not appear in using ProjectName."Models" in asp core2 empty application

I'am starting on an empty template and following implemented stuffs on aspcore2 mvc template but when I tried to do using MyProject.Models the .Models does not appear only the .Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Webeu.????
namespace Webeu.Controllers
{
public class HomeController : Controller
{
}
}
Solved it by adding a new Model in Models folder. I guess that how it works(The Models folder must not be empty to do this).

How to use SignalR with aspnetcore 2.0.0 preview

I am trying to use SignalR with aspnetcore 2.0.0 preview. The preview version is supposed to have support for signalR as per the release notes and I can add references to the "Microsoft.aspnetcoreSignalR" package.
However, I am unable to find the MapSignalR extension method or something like useSignalR() on the IApplicationBuilder.
Googling around for this gives lots of examples of the UseAppBuilder extension method. However, I still get stuck at MapSignalR with the below code:
using Microsoft.AspNetCore.Builder;
using Microsoft.Owin.Mapping;
using Microsoft.Owin.Helpers;
using Microsoft.Owin.Extensions;
using Microsoft.Owin.Builder;
using Owin;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MyNamespace
{
using AppFunc = Func<IDictionary<string, object>, Task>;
public static class SignalRExtensions
{
public static IApplicationBuilder UseAppBuilder(this IApplicationBuilder app, Action<IAppBuilder> configure)
{
app.UseOwin(addToPipeline =>
{
addToPipeline(next =>
{
var appBuilder = new AppBuilder();
appBuilder.Properties["builder.DefaultApp"] = next;
configure(appBuilder);
return appBuilder.Build<AppFunc>();
});
});
return app;
}
public static void UseSignalR2(this IApplicationBuilder app)
{
app.UseAppBuilder(appBuilder => appBuilder.MapSignalR());
}
}
}
This is unable to find the MapSignalR extension method. Any thoughts on if I can find this some nuget package that will work with aspnetcore? Or is there a different mechanism to initialize signalR with aspnetcore 2.0.0 preview?
I am using visual studio 2017 preview 15.3 with .Net core 2.0 preview installed.
I basically hada the wrong set of nugget references. If I only have aspnetcore 2.0.0 preview 1 and the corresponding Microsoft.aspnetcore.signalR 1.0.0 preview package, there is already a UseSignalR() method available as an extension method for IApplicationBuilder and we don't need any of the above code.

SHA256CryptoServiceProvider not working in Xamarin

I create cross-platform project Xamarin.Forms (shared) in Visual Studio 2015, add one page; and I need SHA256CryptoServiceProvider, but i have a problem:
"Error CS0246: The type or namespace name 'SHA256CryptoServiceProvider' could not be found (are you missing a using directive or an assembly reference?)"
MD5CryptoServiceProvider - working good.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using Xamarin.Forms;
namespace App1
{
public partial class Page1 : ContentPage
{
public Page1 ()
{
InitializeComponent ();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider();
}
}
}
It is because this class... really doesn't exist. Why? Using Xamarin, you are using portable .NET which lacks some of the full .NET features. I'm afraid you need to use some external libraries like PCLCrypto to fulfill your needs, or implement it by yourself (this is what I've done when I needed hash function in my Xamarin App)

BundleTable.Bundles.RegisterTemplateBundles

I have MVC4 RC project created with VS2010. I am not sure what happened, all of a sudden I started getting the following error:
Error 1 'System.Web.Optimization.BundleCollection' does not contain a
definition for 'RegisterTemplateBundles' and no extension method
'RegisterTemplateBundles' accepting a first argument of type
'System.Web.Optimization.BundleCollection' could be found (are you
missing a using directive or an assembly
reference?) C:\xxxx\xxxx\Global.asax.cs 40 33 xxxx
The error is comming from Application_Start():
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BundleTable.Bundles.RegisterTemplateBundles();
}
I have the following using statements in my Global.asax.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
Any ideas????
Did you upgrade your Optimization package to RC? We removed that method and instead moved the bundle configuration into a BundleConfig.cs class that gets created by the new project/website template. It has a single static method called RegisterBundles which explicitly shows you what bundles are being registered, you should be able to call this in global.asax instead(you might have to tweak the bundles to match your existing app). The goal was to hopefully make bundle setup more transparent and easily tweaked.

Resources