asp.net-core-2.0

Empty authorization header on requests for Swashbuckle.AspNetCore

感情迁移 提交于 2019-12-31 06:29:04
问题 Currently having an issue with authorization headers in swashbuckle for .net core The first line of code on every endpoint is: string auth = Request.Headers["Authorization"]; When using postman, everything works smoothly, but when making a request from localhost/swagger, the header is empty when a breakpoint is inserted, the header is a null value. the body of the request is in tact and everything works properly when the authorization is removed from the endpoint In my services.AddSwaggerGen

Cannot pass data with ajax to razor pages

梦想的初衷 提交于 2019-12-31 03:43:26
问题 I am trying to send some data to razor page method, but the problem is that in method it takes always as 0 . Heres the code: Razor Page: public IActionResult OnGetProducts(int page) { var products = _productRepository.GetProducts(); decimal pagesInDecimal = (products.Count() / 18); var totalPages = pagesInDecimal % 1 == 0 ? pagesInDecimal : pagesInDecimal + 1; products = products.Skip((page - 1) * 20).Take(20); return new JsonResult(new { totalPages = totalPages, products = products }); }

Validate query parameters without using a model in .netcore api

僤鯓⒐⒋嵵緔 提交于 2019-12-31 03:41:28
问题 Is it possible to validate query parameters on an action without using a model? A lot of the calls in my API are one-offs and I don't see a point in making models for them if they will only be used one time. I saw the following article, which seemed like it was exactly what I needed, except I don't want it to return a 404 if the required parm doesn't exist, I want it to return an object of error messages similar to the baked in model validation - really, I just want the parameters to be

Cookie Authentication Early Expiration

别来无恙 提交于 2019-12-31 00:48:31
问题 Issue In my ASP.NET MVC Core 2.0 application I have setup to use the cookie authentication scheme without using Identity as we have our own backend authentication storage and api. The authentication and authorization works perfectly every time. However, no matter what the login/session expires after approximately 30 minutes. You can see that we are setting the timeout to 120 minutes for both authentication cookie and session cookie. Application information: Platform: .Net 4.7.x (Windows)

What's the point of hosting.json since appsettings.json is sufficient

前提是你 提交于 2019-12-30 07:07:28
问题 In .NET Core 2 Web API app, I could override configuration urls using appsettings.json , but in the official docs they introduced extra file "hosting.json", Why? What's the point of adding complexity? Below code is fully working using appsettings.json : public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) //see Side

Sharing Cookies Between Two ASP.NET Core Applications

风流意气都作罢 提交于 2019-12-30 06:58:20
问题 I'm using WsFederation in two separate ASP.NET Core projects. Each project has the following in Startup.cs services.AddAuthentication(sharedOptions => { sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultChallengeScheme = WsFederationDefaults.AuthenticationScheme; }) .AddWsFederation(options => { options.Wtrealm = Configuration["Wtrealm"]; options

Cannot access a disposed object Asp.net Identity Core

﹥>﹥吖頭↗ 提交于 2019-12-30 06:21:07
问题 I am getting this error System.ObjectDisposedException HResult=0x80131622 Message=Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take

Claims transformation support missing in ASP.NET Core 2.0

独自空忆成欢 提交于 2019-12-30 03:16:28
问题 I am using JWT Bearer auth in my new asp.net core 2.0 api app and want to add some extra claims to the current identity. This extra info is located in another api which need to be queried. My understanding is that claims transformation would be the proper place to do this. In .net core 1.1 you have the IClaimsTransformer interface in Microsoft.AspNetCore.Authentication nuget package, but I cannot install this one in my .net core 2.0 app. Is there a alternative way to transform claims in asp

Unable to cast object of type Newtonsoft.Json.Linq.JObject even though I am trying to cast to an object with matching properties

人走茶凉 提交于 2019-12-29 09:56:30
问题 I am working with ASP.NET Core 2.0 in VS2017. I am trying to deserialize some JSON that is returned in an HttpResponseMessage but I am getting an "Unable to cast object of type..." exception. Here is the code that is failing; FilesUploadedListResponse fileUploadListResponse = new FilesUploadedListResponse(); string jsonResult = response.Content.ReadAsStringAsync().Result; fileUploadListResponse = (FilesUploadedListResponse)JsonConvert.DeserializeObject(jsonResult); The last line is where I

How to use log4net in Asp.net core 2.0

流过昼夜 提交于 2019-12-29 03:14:05
问题 I configure log4net in my asp.net core 2.0 application as mentioned in this article LINK program.cs public static void Main(string[] args) { var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); BuildWebHost(args).Run(); } HomeController public class HomeController : Controller { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(HomeController)); public IActionResult