ASP.NET Core FindByEmailAsync is not responding and getting error 500 - asp.net-core

Using ASP.NET Core with the Identity framework.
I have a project running on Azure, with a SQL Server database, a web site and an API.
Suddenly, today when trying to login to the system (from the app that calls the API), it is stuck for around 15 seconds and then I get an error http 500.
I try to run the API function that authenticate the user from the local env. and was able to reproduce the bug.
The first line of the function is :
var user = await _userManager.FindByEmailAsync(model.Username);
This is the line the program is stuck till getting error message 500.
I don't even know how to approach this, I try to add a line that retrieves one of the user details, just to make sure the API can still talk to the database and it works fine.
How can check what is wrong with it? If I had the implementation of this function, maybe I can debug it.
Any suggestions?

Related

identity server multiple issues after deployment

My current setup is like this. The entire project was built using the official docs here - https://identityserver4.readthedocs.io/en/latest/
API Server
Auth Server with local login, google login and github login
Console based c# client
JS based client
MVC based client.
(all of it, as described in the official docs)
Locally, all of them work beautifully. Able to login, access api endpoints, logout, redirect, the whole thing works smooth.
I have deployed all 5 of them to five different azure web apps. They all have the standard xyz.azurewebsites.net domains ready to use. Now, I have run into some problems.
the console C# client is able to talk to the deployed auth server, collect token using a local account on the auth server and make calls to the deployed API server. Based on this, I assume that both the api server and the auth server working hand in hand, as they should.
Problem #1 - the JS client keeps saying
'The login is blocked because of CORS Missing Allow Origin '
Problem #2 - the MVC client loads the auth server, and then the auth server gives me this error.
Sorry, there was an error : unauthorized_client
Request Id: 80005c0f-0000-eb00-b63f-84710c7967bb
Note : I have set the CORS policy on the auth server, both these clients, under client definition as follows. I am not too concerned about keeping the auth server open, so dont mind if any and every domain can call the auth server.
AllowedCorsOrigins = { "*.*" },
Also Note : I have set the URLS in the code before deployment. all loclahost:port number lines have been replaced correctly with the corresponding now published URLs.
So, what am I missing out here?
Update 1
I was able to solve the CORS issue. Have posted a answer here on another question.
Not able to enable CORS for identity server 4 in asp.net core
Update 2
So, now, both the JS client and the MVC client, are giving identical errors.
Sorry, there was an error : unauthorized_client
Request Id: 80005c0f-0000-eb00-b63f-84710c7967bb
Update 3
I have opened an issue which has log details.
https://github.com/IdentityServer/IdentityServer4/issues/4691
I am not sure if this counts as an answer, but posting for my own question, as it might might help others. Also, this is only a guess at this point.
I found out that the redirects were permanently stored in the database I used with EF migrations. That mean, local in memory redirects were being overwritten anyway by the database stored migrations. I believe this is the issue.
I also realized that the console app is working fine for it does not depend on redirect URLs where as the JS and MVC based clients dont work because they do depend on redirect URLs.
At this point, the best thing to do and for you (if you used EF migrations to store your auth server configuration) on database would be start over and switch to in memory only. Alternatively, you can try and update the database to suit your deployment requirements.
Ultimately, I believe, unless it is absolutely necessary, keep the auth server config (like redirects and CORS settings) in memory as they dont take up much value and are rarely changed.

Umbraco cms backoffice postlogin 500 error

The umbraco version Im currently using is 7.5.14, have been uppgraded from 7.3.x. The presentation part of umbraco is always working without any problems, but the backoffice is acting strange.
When sign in to the backoffice all of a sudden the backoffice stops working and in the web browser console 500 errors are thrown. There is nothing in the umbraco log about the errors or in the event log. When I or any other user is trying to sign in after this has occurred, we cant. In the web browser console there is nothing useful. The only thing it says is that postLogin is throwing 500 error with the message "an error has occurred".
Even when no one is signed in to the backoffice and doing stuff, when a user is trying to sign in the backoffice is throwing 500 erros. The only solution is to recycle the application pool, after restarting the pool we are able to sign in and work in the backoffice again. But the problem can occurre again briefly after restarting the app pool or within an hour or two.
I have been trying to find a solution in many ways but simple cant get rid of the problem.
Edit
I discovered that if Im signed in to umbraco backoffice while the problem occurres. There is a Get request to "umbraco/backoffice/UmbracoApi/Authentication/GetCurrentUser" that returns http 500 code. But there is nothing in the logs about the error...
After decompiling the umbraco controller (AuthenticationController), I noticed a connection in the PostLogin function and GetCurrentUser function. They both use Automapper when mapping user information.
Another project that my web application has reference to has a AutoMapper configuration that is used when a certain class is instantiated. The class calls Mapper.Initialize and after that the umbraco backoffice will fail to map its users. Thats why the error occurs arbitrarily.

I am getting net error ERR_CONNECTION_RESET when calling an API method using ajax

We have a IIS 8 web server on which Web API is deployed. We have a front end application written in extJS. When the application accessed, it makes sever API calls to the server and many of these calls return success except one specific API call. Chrome says request status as cancelled (ERR_CONNECTION_RESET), and I am not able to figure out how to troubleshoot and fix this error. I have checked many places online but I could not get much help.
Please help.
Are you using Entity Framework Core? If so, you may have an object graph loop in your many-to-many relationships as EFCore does not support lazy loading at this time.
If so, you can configure your serializer to not follow graph loops.
In your Startup.cs file, replace the services.AddMvc() line with this:
services.AddMvc()
.AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

Silverlight ClientHttp Stack / windows authentication / and RIA services issue (I'm guessing it's a cookie thing)

I was investigating how to get status code 500 error messages to give me more information when these occur and happened upon the MSDN post about using the ClientHttp stack.. Which was all just so magical seeming until the application got deployed on the staging servers and it seems to completely fail now with authentication
I'm guessing this is due to the whole cookie issue as it relates to the ClientHttp stack...
I'm using RIA services and when the application starts it runs 3 or 4 RIA WCF service calls preloading data in the background and now with the new ClientHttpStack an authentication dialog pops up pretty much every single time a request is made. We're using Windows Authentication so before it would just make you authenticate in order to access the page serving the XAP file... But now you login with Win Auth and then all the subsequent calls repetitively ask for your credentials...
I'm assuming the only way I can fix this is by doing this
http://msdn.microsoft.com/en-us/library/dd920298(v=vs.95).aspx
And then possibly adding an endpoint behavior onto the DomainClient so that before requests are handled it tacks on the cookies...
I've tried doing this for a bit now and I'm not really succeeding... When I run the app in FF or Chrome it still pops up with a whole bunch of login boxes. So I'm just curious if I'm barking up the wrong tree or if I should continue trying to figure out where I'm not quite propagating the cookies through
If you are using the ClientHttp stack, you'll need a place to store your cookie client side, said a HttpCookieContainer. It's just a wcf behaviour to be inserted in the ClientHttp stack. Please, have a look at this post from Kile McClellan and see if it helps you.

ASP.NET WebAPI fails from MVC4 controller

I'm new to ASP.NET Web API and I'm struggling with a very strange problem.
I have some code which calls a RESTful service and it executes fine from a console project, but I can't get it to run from an MVC4 project running under .NET 4.0
The code to call the service is very simple:
internal string Test()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://testserver");
var task = client.GetAsync("/someUri")
var response = task.Result;
response.EnsureSuccessStatusCode();
return response.Content.ReadAsStringAsync().Result;
}
}
As mentioned, called from a console project it works as expected and I get a response in milliseconds, however if I call the method from an action in my MVC4 controller after a few seconds I get a message stating that:
"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to repond".
Weirdly, when debugging the MVC4 version, the task status always shows as WaitingForActivation.
Running fiddler doesn't show any request being made from the MVC4 version, but again does for the Console version.
After a fairly serious bit of googling I can't find anyone else who seems to have had this problem, so I'm guessing that I've fundamentally misunderstood something, but at the moment I'm not sure what!
Updated 16:55 BST, 11/09/2012
To make things even weirder, I've just created a new MVC4 site and I can call the method without any problems! I'm now trying to compare the sites, however one was an existing site that was upgraded to MVC4 and the other is a new blank site, so spotting the relevant difference could be tricky.
Updated 16:44 BST, 14/09/2012
This is now looking like some infrastructure / networking issue.
I upgraded the project to VS2012 with .NET 4.5 so that I could use async/await to try the suggested implementations to avoid a deadlock. This didn't change anything so I went back to square 1.
I created a new solution with a new MVC4 project, a new services library and a unit test project to run the service library outside of MVC.
In the service library I created one method to call a public "what's my IP" service, and another to call a company service that's exposed publicly but only responds properly to company IP addresses.
For some background, I connect in to the company LAN via a VPN.
When disconnected from the VPN, in both unit tests and MVC, the IP service responds HTTP 200, the company service responds HTTP 404 as expected.
When connected to the VPN, unit tests both respond HTTP 200, MVC both timeout.
Next I ran MS Soap Tool locally and used that to proxy calls to the company services. All calls (whether from unit tests or MVC) show a request and response, but the unit test registers the response whilst the MVC controller does not.
My only other thought is that it could be something to do with the size of the reply? All the "successes" have very small replies other than the unit test calling the company service?
The Microsoft recommended way to upgrade an MVC3 to MVC4 site is to start with a completely new MVC4 site a migrate your views, controllers & code over. So I think that your upgrade steps may be part of your issue, since you were able to get it to work in the new MVC4 site you created. If you need to manually upgrade your existing site, I would follow the steps outlined in Upgrading ASP.NET MVC 3 Project to ASP.NET MVC 4