asp.net-core-2.0

When using an API route, return Http Response 401 instead of redirect to login page when not authorised

怎甘沉沦 提交于 2019-12-07 16:00:21
问题 I'm building an ASP.NET Core 2.0 website using MVC and WebAPI to provide access to a series of microservices. Where a WebAPI controller requires a user to be authenticated and authorised (using the Authorize attribute), any unauthorised or not-logged in user gets the response back as the entire HTML for the MVC login page. When unauthorised users access the API, I would like to return the HTTP status code 401 and its associated error message in the response, instead of an entire HTML page. I

How do I get JWT working in Autorest generated SDK? (ASP.NET Core 2.0)

三世轮回 提交于 2019-12-07 15:38:03
问题 I want to be able to login to my identity database with user name and password and retreive a JWT. Then I want to use the JWT to access data securely from my API. I found out that the SDK code generated by VS2017 uses an old version of autorest, so I have switched to using Azure Autorest The api and the SDK are both ASP.NET Core 2.0 To generate the SDK I use AutoRest -mynamespace mytrack.Client -CodeGenerator CSharp -Modeler Swagger -Input swagger.json -PackageName mytrack.client

connet to asp.net core signalR server from a javascript client

蓝咒 提交于 2019-12-07 15:10:41
I have asp.net core web api server that is streaming a signalr, And it works for asp.net client , I am trying to make a connection with the code showen beelow but it only connects to a none core servers it wouldnt work for the core servers. //the hub class in the server code [EnableCors("AllowAllOrigins")] [HubName("LogNotifierHub")] public class LogNotifierHub : Hub { //methods defined here } startup code for the routing : app.UseSignalR(routes => { routes.MapHub<LogNotifierHub>("/NotifierHub"); }); javascript code for making the connection var hubUrl ="http://localhost:52273/logNotifierHub";

ASN.NET Core 2.0 Facebook authentication ExternalLoginSignInAsync Fails (IsNotAllowed)

岁酱吖の 提交于 2019-12-07 13:30:51
问题 I am creating a new application in ASP.NET Core 2.0 with Ddentity. I have enabled the Facebook Authentication according to the docs. The flow that is running right now is the following: When a new user authenticates from facebook the applicatiion asks for an email in order to be used for the application When the user provides the email a user is created in my dbo.AspNetUsers table with the email provided by the user and a new line is created in my dbo.AspNetUserLogins with the reference to

How to use ASP.NET Core Identity without roles?

半世苍凉 提交于 2019-12-07 11:07:28
问题 Is it feasible to implement identity in asp.net core 2 without roles implementation? I have tried to implement the following: services.AddIdentityCore<TUser>(); but that does not seem to work as well. 回答1: I got it! I have upload a repo in github: https://github.com/tolemac/IdentityWithoutRoles You have to create your custom ApplicationDbContext with corrects DbSets : public class ApplicationDbContext : DbContext { public ApplicationDbContext(DbContextOptions options) : base(options) { } ///

How to generate unit test cases in VS 2017 .net core project?

梦想与她 提交于 2019-12-07 08:58:55
问题 "Create Unit Tests" context menu option is missing in Visual Studio 2017 for .Net core project? I read some articles saying that "Create Unit Tests" context menu option is removed in VS2017/Core/x64 config. But those were old articles. So, wanted to check if this option is available now? If not, do we have any other alternatives (extensions) to generate the test cases? If so, kindly let me know the steps. I am working on VS 2017/.NetCore 2.0 project. Appreciate your help! 回答1: Perhaps you've

ASP.NET Core 2 - develop using custom domain names and ssl using IISExpress

坚强是说给别人听的谎言 提交于 2019-12-07 08:44:52
问题 I want to be able to develop locally using a custom domain and ssl rather than localhost. How can I setup a custom domain + ssl in VS Solution instead of localhost? 回答1: Simple Setup - Using Server URLs If you want to associate your server to use all the IP addresses assigned to the server/web host then you can do this: var host = new WebHostBuilder() .UseUrls("http://*:80", "http://localhost") .UseKestrel() .UseIISIntegration() .Build(); Note: If you don't want all IP addresses, then you can

alternative for System.Web.Hosting.HostingEnvironment.RegisterObject in asp.net core 2.0

邮差的信 提交于 2019-12-07 08:12:27
问题 I have a legacy application where HostingEnivronment.RegisterObject is used. I have been tasked with converting this to asp.net core 2.0. however I am unable to find a way to either implement this or find an alternative to this in asp.net core 2.0. the namespace Microsoft.AspNetCore.Hosting.Internal does not contain the registerobject method nor does it have the IRegisteredObject interface. I am at a loss on how to get this implemented. 回答1: The way to achieve similar goal in asp.net core is

Asp.net core 2.0 middleware - accessing config settings

让人想犯罪 __ 提交于 2019-12-07 06:34:57
问题 In a asp.net core web api middleware, is it possible to access the configuration inside the middleware? Can someone guide me how this is done? 回答1: In a middle-ware you can access settings. To achieve this, you need to get IOptions<AppSettings> in the middle-ware constructor. See following sample. public static class HelloWorldMiddlewareExtensions { public static IApplicationBuilder UseHelloWorld( this IApplicationBuilder builder) { return builder.UseMiddleware<HelloWorldMiddleware>(); } }

How to set timeout of soapclient in .net core project

我的未来我决定 提交于 2019-12-07 05:32:26
I have to use a SOAP service in a .Net Core 2.0 project. I added service reference as described in following link: ( Missing link, 404 ) Service is working fine for some methods. However, some methods are taking long time (due to the operations service is doing) and in this case the program is throwing exception:"System.Net.Http.WinHttpException: The operation timed out" I tried to set the timeout value but it has no effect. MyService.MyServiceSoapClient Pr = new MyService.MyServiceSoapClient( new MyService.MyServiceSoapClient.EndpointConfiguration()); Pr.InnerChannel.OperationTimeout = new