I am in the process of upgrading an existing Asp.Net Core 2.2 project to ASP.NET core3 and have followed most of the steps necessary in this: https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio to make that happen. There is an angular app attached, and I was having issues connecting to it from there, (the Core app is a web API project). I tried to start over with the upgrade from scratch, having to remove Swagger code from it as it isn't working and isn't necessary right now. I get this:
// http://localhost:{port}/
{
"source": "Microsoft.AspNetCore.Server.Kestrel.Core"
}
as the only thing on the page, and when I set up a Postman request to hit an Anon-Allowed GET action, it returns the same thing in the result, instead of the expected result.
I have converted services.AddMvc to services.AddControllers, in ConfigureServices => Startup.cs, and converted to use app.UseRouting, UseCors, UseAuthentication, and UseEndpoints, (in that order), in Configure => Startup.cs. I also set MapControllers inside the UseEndpoints method while defining the EndpointBuilder to pass in.
I know that it is not even hitting the method because I have placed a breakpoint at the beginning of it to see what happened and why it was returning an error and that result. That breakpoint does not get hit at all.
Related
Trying to provide more info and not sure how much is relevant.
One of our webapi is deployed to IIS : abcdomain.com/xyzweb. We started upgrading our env to .net 7 from .net 5. Web api also uses ServiceStack 6.4.
One of the route defined in the c# Webapi, ServiceStack plugin is "/api". Until recently requests to endpoint abcdomain.com/xyzweb/api was fine. But now (.net 7 upgrade?) we noticed that the calls to endpoint does not reach the (http get/post method) handler. We have a small middleware defined in startup.cs configure method and see the execution flow through the middleware code when the abcdomain.com/xyzweb/api request is made and the middleware ends by calling next() and after which execution flow lost (webapi is still live).
After much trials, something I read but could not put my fingers on the content, went ahead and changed the route definition to "/apihello" instead of "/api" and then the requests started working as before.
Any pointers what made it break or what made it work?
Searching is difficult with "api", brings only irrelevant results.
I would like to add that before changing /api to /apihello, the http request would return HTTP status 200 (though it did not go to the handler) and Raw response "Error: System.NotImplementedException: The operation '' does not exist for this service".
You can disable (or change) ServiceStack's JSON /api pre-defined route with:
ConfigurePlugin<PredefinedRoutesFeature>(feature => feature.JsonApiRoute = null);
I'm trying to make an ASP.NET Core Web application to host IdentityServer and use it as my main authorization service, shared across many other apps.
I followed the quick start tutorial that consists in installing a nuget package (called IdentityServer4) in an empty MVC application template.
Everything is working fine on my machine (debugging with VS2017 & VS2019 preview).
I tried to publish the app as an Azure App Service like i did with previous apps and worked fine.
While debugging, if i open a browser and type "https://localhost:44316/", i see this page:
But navigating to "https://xxx.azurewebsites.net" (that is where i published the app) is not working. Responding 404 not found.
Just to add some detail, if i navigate this "https://localhost:44316/Account/Login?ReturnUrl=%2Fgrants", i obtain the correct login page and doing the same on Azure produces the same result.
So, essentially, looks like it's working, except for the home page.
I'm not an expert in routing with ASP.NET Core, so don't blame me if my question is not so smart.
So, essentially, looks like it's working, except for the home page.
This is actually the intended behaviour - If you take a look at the implementation of the HomeController provided in the IdentityServer4.Quickstart.UI project, you'll see the following implementation (source):
public IActionResult Index()
{
if (_environment.IsDevelopment())
{
// only show in development
return View();
}
_logger.LogInformation("Homepage is disabled in production. Returning 404.");
return NotFound();
}
When running in Azure, the application's environment isn't set to Development environment and so returns 404 NotFound, as shown above.
I'm trying to achieve the following behavior in my Core 2 application. If the URL is:
like /swagger, then go to /swagger (unchanged path),
like /api/.*, then go to /api/.* (unchanged path),
like anything other, then go to /index.html.
I've been trying combinations of the following theme.
app.UseRewriter(new RewriteOptions()
.AddRewrite("^swagger$", "/swagger", true)
.AddRewrite("(^api/.*)", "$1", true)
.AddRewrite(".*", "index.html", true)
);
This doesn't seem to work. Swagger gets repeatedly more /swagger parts, the API gets nothing in return. I'm rather unclear on the correlation between the code and the behavior. The last parameter is supposed to stop more rules from running but it seems not to be the case.
(If it's of any importance, I'm trying to get the routing in my Angular app to work.)
I am trying to insert the localization using PO file. My project is on Asp.Net core and uses Orchard core.
I am following this guide - Configure Portable Object but I have a problem with the initial registration of the localization.
I should add the following code:
services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
Technically, my project should have service.AddMvc() by default, but I am using services.AddOrchardCms() instead.
When I try to call the first code to register the localization:
...
services.AddOrchardCms();
services.AddMvc()..AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
...
I receive an error as the application "Can not find the index page" (It actually does not exist as I am using services.AddOrchardCms() and I think they have a conflict).
And, of course, if I don't insert the AddViewLocalization() the PO files don't work.
Does anyone know how can I solve this problem?
AddOrchardCms is internally calling AddMvc, by calling it again you are overwriting Orchard pipline with basic MVC pipeline. Try calling:
services
.AddOrchardCms()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
instead.
I created a asp.net core rc2 web application with user identity, however i'm confused how the account controller class is getting it's arguments, usermanager, signinmanager? Where are they being passed in from? I follow the call stack and I get external code, what external code is passing in these objects? Help me understand, how these 2 objects are being initialized.
In your Startup.cs you will see a call to this method
services.AddIdentity<ApplicationUser, IdentityRole>()
Afte reading the links on dependency injection suggested by #AndrésRobinet you can actually see where the services are being wired up.
This extension method lives in `IdentityServiceCollectionExtensions - You can then go and look at the source code for this method call (.NET core is on github):
line 67 of the AddIdentity method
services.TryAddScoped<SignInManager<TUser>, SignInManager<TUser>>();
what external code is passing in these objects?
Right-click on External code and click Show External Code - now you can get an idea of what is happening under the hood. the code down to and including the Kestrel webserver is also browsable/downloadable on github
image truncated