asp.net core's default application using docker starts with two launch urls - docker

I created a basic Asp.net core 2.0 web application in the following way:
New Application => ASP.Net Core Web Application => Web Application =>
(MVC) => Change Authentication => Individual User Accounts (With docker enabled)
Debugging this will give you this:
This will obviously give you a 404, if you get rid of https://localhost:44360/ then the application is debugging there. I've seen this answer, but this didn't work for me.
I created a hosting.json as the answer suggested:
{
"server": "Microsoft.AspNetCore.Server.Kestrel",
"server.urls": "http://localhost:4000"
}
I added this to the Configure() method in startup:
var config = new ConfigurationBuilder()
.AddJsonFile("/app/hosting.json", optional: false)
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
.Build();
var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
This didn't fix my startup issue. What am I doing wrong or what do i need to do to fix this debug issue?

I was seeing the same issue after creating a new project and installing Docker for Windows with Visual Studio Community 2017.
It appears that the docker-compose Property Pages had a bad Service URL property, which in my case was generated as: http://localhost:{ServicePort}/https://localhost:44339/
To fix the issue:
Right-click the docker-compose project
Select Properties
Replace Service URL with: http://localhost:{ServicePort}

Related

Swagger UI : Failed to Load API Definition

I've deployed a simple Web API in net5 with swagger enabled (using default settings), which means in Startup.cs:
Configure Services method:
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "MyCompany.WebApi", Version = "v1" });
});
Configure method:
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyCompany.WebApi v1"));
And i deploy the same application to 2 Local IIS websites, the first as an application of the Default WebSite running on default port 80, as shown below:
And the second as a Separate WebSite node running on port 8085, as shown below:
Then for the second (hosted as a separate WebSite node), all works fine, so i can see my API definition:
But for the first, hosted as an application under the Default Web Site the API documentation can not be loaded:
Even though the swagger.json file is accessible:
So it look's like swagger is searching for the index.html to display the Swagger-UI in the "root" of the WebSite, and in the case of the first option where the application is hosted under the Default WebSite folder it can not find a way to display the swagger UI. Do we need to add something specific in the swagger definition in this case ?
Thx for any responses !
Emmanuel.
Did you tried this:
app.UseSwaggerUI(c => c.SwaggerEndpoint("swagger/v1/swagger.json", "MyCompany.WebApi v1"));
i removed beginning '/' from swagger json path.

ServiceStack Admin UI

I'm trying to integrate the /admin-ui functionality in my application, that uses the ServiceStack's built-in ApiKeyAuthProvider, for give the user the possibility to register other users.
In the login page that this functionality renders, when I write my apikey and press the sign in button, through the developer tool console, I see the error "!AuthProvider", that sounds like that the app cannot recoignize the ApiKeyAuthProvider.
This is my AppHost Configure method:
public override void Configure(Container container)
{
//Create and register an OrmLite DB Factory configured to use Live DB by default
var dbFactory = new OrmLiteConnectionFactory(
AppSettings.Get<string>("connString"), SqlServerDialect.Provider);
container.Register<IDbConnectionFactory>(dbFactory);
//Tell ServiceStack you want to persist User Auth Info in SQL Server
container.Register<IAuthRepository>(c => new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));
container.Resolve<IAuthRepository>().InitSchema();
//Register the AuthFeature with the API Key Auth Provider
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[] {
new ApiKeyAuthProvider(AppSettings)
}));
Plugins.Add(new AdminUsersFeature());
}
Could someone help me please? (ServiceStack v.6.0.2)
Thanks in advance
EDIT:
This issue should be resolved from the latest v6.0.3 pre-release that's now available on MyGet.
If you have an existing ServiceStack v6.0.3 installed you'll need to clear your NuGet packages cache to update to the latest version, e.g:
$ nuget locals all -clear

implement Microsoft Authentication (owin) on an existing WebForms web app

I'm trying to implement Microsoft Authentication (owin) on an existing WebForms web application. I can't use the official guides from Microsoft, since they are made for modern solutions with MVC.
Any tips on where to start? I can't find any guides.
Please follow the document which helps you in old .NET forms to use OWIN Forms middleware and to use this middleware for Azure AD authentication please follow Docs.
Install the package for Microsoft.Owin.Security.Cookies
Right click the App_Start folder on your project Add -> New Item - > "OWIN Startup Class"
then create the following folder
public void Configuration(IAppBuilder app)
{
CookieAuthenticationOptions opt = new CookieAuthenticationOptions();
opt.AuthenticationType = CookieAuthenticationDefaults.AuthenticationType;// "Identity.Application";
opt.CookieName = ".SSO";
opt.CookieDomain = "localhost";
opt.SlidingExpiration = true;
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("192.168.1.96:6379");
IDataProtector proc = DataProtectionProvider.Create(new DirectoryInfo(#"C:\test\core"), buildAction =>
buildAction.SetApplicationName("MyApp").SetDefaultKeyLifetime(TimeSpan.FromDays(9000)).ProtectKeysWithDpapi().PersistKeysToStackExchangeRedis(redis)).CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware", "Cookies", "v2");
DataProtectorShim shim = new DataProtectorShim(proc);
opt.TicketDataFormat = new AspNetTicketDataFormat(shim);
app.UseCookieAuthentication(opt);
}

Orleans direct client in ASP.NET Core project

I am currently looking into Orleans as a backend for Asp.net core web api project, and was wondering if anyone has any experience with its new feature - "direct client". The orleans docs say "it allows co-hosting a client and silo in a way that let the client communicate more efficiently with not just the silo it's attached to, but the entire cluster", and I am aware that you can code something like this (and it works just fine in a console app):
var silo = new SiloHostBuilder()
.UseLocalhostClustering()
.EnableDirectClient()
.Build();
await silo.StartAsync();
var client = silo.Services.GetRequiredService<IClusterClient>();
I am struggling trying to figure out where to put this type of code in an asp.net project that has its own webhost builder in "Main" (should it go to Startup class in "ConfigureServices"?). In the end, we are aiming for a separate client/server setup, but for faster development it would be useful to play with a simple setup, which direct client appears to allow for. Any pointers to resources and/or sample solutions containing direct client with asp.net core would be appreciated. Thanks.
EDIT: Here's the code that kinda works for me now, but I am not happy with he way the DI is set up
public static async Task Main(string[] args)
{
var silo = new SiloHostBuilder()
.UseLocalhostClustering()
.ConfigureServices(services =>
{
services.AddDbContext<UserDbSet>(o => o.UseSqlite("Data Source=UserTest.db"));
services.AddMediatR(typeof(Startup).Assembly);
})
.EnableDirectClient()
.Build();
await silo.StartAsync();
var client = silo.Services.GetRequiredService<IClusterClient>();
await WebHost.CreateDefaultBuilder(args)
.UseConfiguration(new ConfigurationBuilder()
.AddCommandLine(args)
.Build())
.ConfigureServices(services =>
services
.AddSingleton<IGrainFactory>(client)
.AddSingleton<IClusterClient>(client))
.UseStartup<Startup>()
.Build()
.RunAsync();
}
If I put registration of the DbContext and Mediatr in the StartUp class, grain code fails with an exception indicating failure to instantiate the required dependencies. Maybe I am doing something wrong when setting up the Webhost?
For ASP.NET 2.x & Orleans below 2.3, I recommend creating & starting the silo before the Web host. When configuring the Web host, inject the IGrainFactory & IClusterClient instances from the silo (obtained via silo.Services):
var silo = new SiloHostBuilder()
.UseLocalhostClustering()
.EnableDirectClient()
.Build();
await silo.StartAsync();
var client = silo.Services.GetRequiredService<IClusterClient>();
var webHost = new WebHostBuilder()
.ConfigureServices(services =>
services
.AddSingleton<IGrainFactory>(client)
.AddSingleton<IClusterClient>(client))
.UseStartup<Startup>()
// Other ASP.NET configuration...
.Build();
For ASP.NET 3.0 & Orleans 2.3 or greater, the integration code becomes simpler due to the addition of Microsoft.Extensions.Hosting support in both frameworks:
var host = new HostBuilder()
.ConfigureWebHost(builder =>
{
// Adding IGrainFactory, etc, is not necessary, since Orleans
// and ASP.NET share the same dependency injection container.
builder.UseStartup<Startup>();
})
.UseOrleans(builder =>
{
// EnableDirectClient is no longer needed as it is enabled by default
builder.UseLocalhostClustering();
})
.Build();
await host.StartAsync();

How do I debug an ASPNET Core MVC Application Deployed in Azure

I've created a simple ASPNET Core 1.0 MVC app, which I am trying to deploy to Azure using Visual Studio. I am able to run this app locally on my machine using IIS Express, and navigate to my default route and display the page. However, in Azure I always get a 500 error every time, and at this point I am at a loss for how to get additional information.
I've enabled detailed request logging in my Azure app, but it doesn't really seem to tell me much.
ModuleName="AspNetCoreModule", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The operation completed successfully.
(0x0)", ConfigExceptionInfo=""
I've stripped down my Startup configuration to the bare essentials
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, ILoggerFactory loggingFactory)
{
loggingFactory.AddConsole();
loggingFactory.AddDebug();
app.UseMvc(routes => {
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}"
);
});
}
Something must be blowing up in the MVC pipeline but I have no idea how to add more visibility. What can I do to get more information?
And in case it matters, this is my Program.cs
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
Try setting ASPNETCORE_ENVIRONMENT to Development to display full exception message on the error page.
Remember to turn it off when finished, otherwise you will leak error information.

Resources