Posts

Showing posts with the label asp.net-core

Default route at startup with ASP.NET Core [duplicate]

Default route at startup with ASP.NET Core [duplicate] This question already has an answer here: With a brand new ASP.NET Core API application, how do you set the default route to navigate to when F5 debugging? I have the SPA being served correctly but every time the application is started with Visual Studio, it defaults to https://localhost:44323/api/values https://localhost:44323/api/values There appears to be nowhere in Visual Studio to configure this. In previous versions of ASP.NET this was an option under project properties. (The /api/values route being the route of the default controller setup by the template.) /api/values This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. Go to the project properties, Debug tab, look to the right of the checkbox that is labelled "Launch browser:" Hiding in plain sight. – JamieMeyer ...

ASP.NET Core API search parameters from path/route

Image
ASP.NET Core API search parameters from path/route I am porting a PHP/CI API that uses $params = $this->uri->uri_to_assoc() so that it can accept GET requests with many combinations, such as: $params = $this->uri->uri_to_assoc() With lots of code like: $page = 1; if (!empty($params['page'])) { $page = (int)$params['page']; } 1) Conventional routing with catchall: app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Properties}/{action=Search}/{*params}" ); }); But now I have to parse the params string for the key/value pairs and am not able to take advantage of model binding. params 2) Attribute routing: [HttpGet("properties/search")] [HttpGet("properties/search/beds/{beds}")] [HttpGet("properties/search/beds/{beds}/page/{page}")] [HttpGet("properties/search/page/{page}/...

Using User.IsInRole returns random result when UserRole changes

Using User.IsInRole returns random result when UserRole changes I'm using asp.net core 2.1 with default identity settings and every time a role is changed the user should re-login to see the role changes. If I add the following settings, roles should be updated on each request, the Authorize attribute works well but User.IsInRole() method returns random results on each request. Authorize User.IsInRole() services.Configure<SecurityStampValidatorOptions>(options => { options.ValidationInterval = TimeSpan.Zero; }); What's the problem with User.IsInRole() ? How to fix it? User.IsInRole() Edit: I was incorrect about the Authorize attribute behavior, that works random too. Authorize When you say random, do you mean that the changed roles only take sometimes? You could try hooking up OnValidatePrincipal and confirm that it's getting called. – Mark G 2 days ago ...

ASP.NET Core Equivalent to OwinContext.Environment?

ASP.NET Core Equivalent to OwinContext.Environment? I am trying to port over some Owin middleware that uses OwinContext.Environment. I know I can support the old Owin stuff using the AspNetCore.Owin nuget package but since owin is now integrated into ASP.NET Core, I'd like to update it all. I know the Environment Property is just a IDictionary, but what I'm unsure of is what, if anything, is special about that object as far as the context is concerned, scoping, lifetime, etc. Looking at the source code it looks like it's little more than a public virtual on the OwinContext class with a private setter. Implementing similar functionality in .net core obviously wouldn't need all of the other key value pairs that the old Owin context used, because well it doesnt exist anymore. So it seems like it would be relatively easy to replicate that functionality. That said, Im just trying to figure out if there ise anything else in .net core that might provide similar functionality, ...

Asp.net Angular Template application Npm update does not work

Asp.net Angular Template application Npm update does not work I am trying to follow the documentation found here however it is going well. All of the packages that gets created with the application are out of date such as the @angular/compiler which really the version at the time of this post is 6.0.2 not 4.2.5 as listed below in the generated packages.json . @angular/compiler 6.0.2 4.2.5 packages.json Things to note. With the packages being this out of date there are many angular things I can take advantage of. I have been looking around however I have not found any solutions that work. Things I have tried: My dependencies: { "name": "TestingApp", "private": true, "version": "0.0.0", "scripts": { "test": "karma start ClientApp/test/karma.conf.js" }, "devDependencies": { "@angular/animations": "4.2.5", "@angular/common": "4.2.5", ...

How do I publish a MEAN Stack App to work on a Rasperry Pi?

How do I publish a MEAN Stack App to work on a Rasperry Pi? I have a MEAN Stack app running on ASP.NET on one port. That app starts a Node.js express server on a different Port. using the following command.. "dotnet-run": "concurrently "dotnet run" "node server.js" ", ..and all of it works perfectly in development mode on my Computer. Now I'm trying to use the following command to publish it and use it on a Raspberry Pi with Debian: dotnet publish -c debug -r linux-arm -o debug --self-contained The App starts but the Node.Js Server does not. Also I'm getting: Uncaught ReferenceError: vendor_ is not defined I was using this Tutorial as a Guide : https://www.thomaslevesque.com/2018/04/17/hosting-an-asp-net-core-2-application-on-a-raspberry-pi/ So now to my Question: What is considered best practice to publish such a MEAN Stack app with two servers running next to each other (to work on a Raspberry Pi)? ...

Reloading Options with reloadOnChange in ASP.NET Core

Reloading Options with reloadOnChange in ASP.NET Core In my ASP.NET Core application I bind the appsettings.json to a strongly typed class AppSettings . public Startup(IHostingEnvironment environment) { var builder = new ConfigurationBuilder() .SetBasePath(environment.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{environment.EnvironmentName}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } public void ConfigureServices(IServiceCollection services) { services.Configure<AppSettings>(Configuration); //... } In a singleton class I wrap this AppSettings class like this: public class AppSettingsWrapper : IAppSettingsWrapper { private readonly IOptions<AppSettings> _options; public AppSettingsAdapter(IOptions<AppSettings> options) { _options = options ?? throw n...

EF Core + npgsql DateTime uses windows 10 localization for formatting

EF Core + npgsql DateTime uses windows 10 localization for formatting I updated my development machine to Windows 10 and tried to add a new Required DateTime property to a class. I created the migration with Add-Migration and a reasonable migration was generated: { migrationBuilder.AddColumn<DateTime>( name: "AskingTime", table: "Questions", nullable: false, defaultValue: new DateTime(2000, 1, 1, 15, 0, 0, 0, DateTimeKind.Unspecified)); } I tried to apply it with Script-Migration, but it fails with this error: ALTER TABLE "Questions" ADD "AskingTime" timestamp without time zone NOT NULL DEFAULT TIMESTAMP '2000-01-01 15.00.00'; Npgsql.PostgresException (0x80004005): 22007: invalid input syntax for type timestamp: "2000-01-01 15.00.00" We tried this with my coworkers machine which still has Windows 7 and it works as expected without errors. The problem was that ...

Using a view as Create and Detail Method, Organize TimeLine

Image
Using a view as Create and Detail Method, Organize TimeLine What I'm trying to do: I'm trying to Add to the Candidate history (Description and Title, and DateTime.Now), Here is a image representation of what I want and what I managed to do: Also how can I add to the timeline to the left side when the select option is " candidate ", and right side when it's " Hitachi ", the property for that is adding timeline-Inverted to the <li> Class . timeline-Inverted <li> Class What I have now: @model HCCBPOHR.Data.Candidate @{ ViewData["Title"] = "CandidateHistory"; } <h2>Canidate - @Model.Name</h2> <label>History</label> <hr /> History Of @Model.Name @* *@ @*Isto é para inverter o lado*@ Title @Model.DateOfDescription.ToShor...

Serve static file index.html by default

Serve static file index.html by default I've got a very simple angular app project that needs to do nothing more than serve static files from wwwroot . Here is my Startup.cs : wwwroot Startup.cs public class Startup { public void ConfigureServices(IServiceCollection services) { } public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.UseStaticFiles(); } // Entry point for the application. public static void Main(string args) => WebApplication.Run<Startup>(args); } Whenever I launch the project with IIS Express or web I always have to navigate to /index.html . How do I make it so that I can just visit the root ( / ) and still get index.html ? /index.html / index.html 2 Answers 2 You want to server default files and static files: public void Configure(IApplicationBuilder application) { ... // Enable serving of stat...