I'm currently debugging an ASP.NET MVC application that was just deployed to a different server.
All the versions between the staging server and the production server are the same, but in the production server (which is 64bit, but is running the app in 32bit mode) I'm getting a timeout in this controller action:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Person person, PeopleCertificationLevel peopleCertificationLevel, Address address)
{
try
{
person.PeopleCertificationLevels.Add(peopleCertificationLevel);
person.Addresses.Add(address);
_peopleService.SavePerson(person);
SetMessage("O marĂtimo foi registado com sucesso.");
return Redirect("~/People/Show/" + person.ID);
}
catch
{
SetErrorMessage("Por favor valide e preencha devidamente os campos assinalados a asterisco (*).");
Create();
return View(person);
}
}
I've already tried throwing an exception before the try block, but I always get a request timeout here.
It seems to me that the request isn't getting to this action. Any suggestions on how I should debug this or what should I do?
UPDATE: I figured it has to do with the model binding. If I remove the bindings, the request gets dispatched, FAST. However, i've tried several approaches, such as using the Bind attribute before the action parameters, tried creating a NewPersonForm class which contained 3 properties (Person, PeopleCertificationLevel, Address), and even tried with a FormCollection and UpdateModel calls. All to no avail.
UPDATE 2: This application is compiled in 32bit and running in a 64bit environment. Although 32bit applications are enabled in the AppPool, I suspect that is what might be causing the problem.
It may not be this silly, but just my 2 cents:
did you actually check if the form is posted through a submit button ?
are all the parameters exactly matching with the names specified in the routing?
Related
I am new to .NET Core, Entity Framework, AWS, and pretty much everything here (please comment and let me know if anything needs to be added to the post).
What I am trying to do is deploy a .NET Core Web API with AWS Lambda. My API seems to be working locally, as I tested it (I have an Angular frontend app, with which I am able to successfully execute all the APIs). However, when I deploy with AWS and run a few of the APIs on Postman, I get a "502 Bad Gateway" error.
My serverless.yml file looks like this:
service: angularawardwebapi
provider:
name: aws
runtime: dotnetcore2.1
region: us-east-1
package:
artifact: bin/release/netcoreapp2.1/deploy-package.zip
functions:
api:
handler: angularawardwebapi::angularawardwebapi.LambdaEntryPoint::FunctionHandlerAsync
events:
- http:
path: /{proxy+}
method: ANY
My Model Class looks something like this:
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace angularawardwebapi.Models {
public class Student {
[Key]
public int StudentId{get;set;}
[Required]
[Column(TypeName="nvarchar(50)")]
public string StudentFirstName{get;set;}
[Required]
[Column(TypeName="varchar(50)")]
public string StudentLastName{get;set;}
}
}
My DbContext file looks like this:
public class DatabaseContext:DbContext {
public DatabaseContext(DbContextOptions<DatabaseContext> options):base(options) {
}
public DbSet<Student> Students {get;set;}
}
}
I have two methods in my Controller:
[HttpGet("temp")]
public ActionResult<List<String>> GetTemp() {
return Ok("here");
}
[HttpGet]
public ActionResult<IEnumerable<Student>> GetStudent()
{
return Ok(_context.Students);
}
The first of which works without a hitch (as expected). However, when I try to return a list of the Students that are in the DB, it seems that I'm encountering issues.
I tried using the second API locally as well, and received the appropriate response:
[
{
"StudentId": 1,
"StudentFirstName": "John",
"StudentLastName": "Doe"
}
]
I also checked the AWS CloudWatch Logs, which showed something like this:
[Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request starting GET https://[myurl]/dev/api/Student/
[Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Route matched with {action = "GetStudent", controller = "Student"}. Executing action WebApi.Controllers.StudentController.GetStudent ([myprojectname])
[Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Executing action method WebApi.Controllers.StudentController.GetStudent ([myprojectname]) - Validation state: Valid
[Information] Microsoft.EntityFrameworkCore.Infrastructure: Entity Framework Core 2.1.8-servicing-32085 initialized 'DatabaseContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
END RequestId: f57417d3-4075-4680-a78d-e90e2c710760
REPORT RequestId: f57417d3-4075-4680-a78d-e90e2c710760 Duration: 6006.80 ms Billed Duration: 6000 ms Memory Size: 1024 MB Max Memory Used: 141 MB
2019-06-06T14:19:41.116Z f57417d3-4075-4680-a78d-e90e2c710760 Task timed out after 6.01 seconds
This time out issue is not seen when I run the API locally, as I immediately get the correct response (as specified above).
Update
So I now have an RDS Database, which I can successfully connect to and play around with in SSMS. Running APIs locally also still work. However, after I deploy it using serverless deploy -v, I'm still facing the previous issue. As suggested, I tried modifying the permissions for the DB, although I'm not sure I'm doing the right thing there either. What I've done is:
Went into SSMS and modified the database permissions by right-clicking the server, going to Permissions, selecting my login (that I set up while configuring the RDS), and granted the "Alter any database" option. I then went to the database itself and modified some permissions (Delete, Insert and Update).
I also enabled the Windows Management Instrumentation (WMI-In) Windows Firewall rule.
Neither of these seems to have solved my problem.
You're probably using the same connection string you used for testing in your local Db, you should change it to use some database that the api can access to from aws.
If that's the case then your api is trying to access to a local db (which obviously it's not going to find), that would explain the timeout issue.
In order to fix it you should probably deploy your database to AWS as well and change the connection string of the project to the connection string of that database inside of AWS.
My code works fine in dev, but when I publish to a test server, one screen is giving an error:
The model item passed into the dictionary is of type 'System.Collections.Generic.List1[Intranet.ViewModels.EditingRequestsViewModel]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[Intranet.ViewModels.ITRequestsViewModel]'.
This is the controller code, and as intended, it uses the EditingRequestsViewModel:
public ActionResult Index()
{
var myList = db.Database.SqlQuery<EditingRequestsViewModel>("EXEC [DBO].[spGetRequests]").ToList();
return View(myList);
}
And here is the first line of the view:
#model IEnumerable<Intranet.ViewModels.EditingRequestsViewModel>
Why would this same code expect a different model when published to a test server? I've tried "Clean Solution," "Rebuild Solution," deleting the Dlls, and redeploying (repeatedly) using both debug and release configurations. No change.
I should remark that, before this started, I checked my code into TFS and had a conflict where I took the server version of my Project file. This caused some issues with this "editing" controller not being seen (it was new) but I fixed that and everything works fine in dev.
Is there a hidden reference in a file, that might be jacked up?
Just try try to change
#model IEnumerable<Intranet.ViewModels.EditingRequestsViewModel>
to
#model List<Intranet.ViewModels.EditingRequestsViewModel>
I try to get certificates hash from web-site bindings(IIS) using official Microsoft Library Microsoft Web Administration.I stack with one interesting problem.When I try to complete this trivial operation:
foreach (Binding binding in site.Bindings)
{
binding.CertificateHash;
binding.CertificateStoreName;
}
I get this exception: Method or operation is not implemented
The most strange and curious thing that when I create another test project and did same things everything work's fine.This situation blows my mind!I compared the versions of the library.They are equal.(Version 7.0.0)
Of course, I try many other solutions and answers:
1)Got an error while using WorkerProcess.GetRequests method from Microsoft.Web.Administration.dll IIS 8.5
2)State property of Site throwing "NotImplementedException" in IIS Express
3)The method or operation is not implemented. while stopping IIS website in C#
but nothing had happened.So that way I here.
Thanks for your attention!
I promise I searched for the answer...
My application consist of both a Mobile backend in azure and a Web-client application that makes calls upon this back-end.
I have run across a bizarre bug that creates 404 not found errors when calling a Http Get function on my backend.
The bizarre part of this issue is that the error is random. It is probably a %50 chance that I might get a 404 or a 200 ok response from the server. This only happens on one specific method that was recently added.
I am wondering if breaking the back-end into instances might have created a non-identical copy of my app.
I removed the instance, and the specific api I have been calling is not longer available on the published version it is visible while running on debug.. I get 100% error on the published version now.
What is wrong with azure? cleaning and rebuilding the back-end does nothing.
[Route("api/UserProject/{projectId}")]
[HttpGet]
public HttpResponseMessage GetUserProjectByProjectId(int projectId)
{
//Get all UserProject
List<DTO.User> userList = new List<DTO.User>();
DataTable UserdataTable = SqlHelper.ExecuteDataset("dbo.UserGetByProjectId", projectId).Tables[0];
if (UserdataTable.Rows.Count > 0)
{
foreach (DataRow dataRow in UserdataTable.Rows)
{
DTO.User u = new DTO.User();
Map.DataToObject(dataRow, u);
userList.Add(u);
}
}
return this.Request.CreateResponse(HttpStatusCode.OK, userList);
}
going to the api/help page on Debug the UserProject route works and is shown in DEBUG mode, but as soon as I publish the app the UserProject function is not longer anywhere to be found.
Wow I finally fixed it. I did the one thing I though would be useless and it worked.
I restarted the service from the azure portal....
My opinion: I guess the created intances where the ones working of the latest version while the original was unable to be updated and the only way to make the original update was to restart the whole thing.
I really don't know why this happened, if you guys want to comment on this please do so.
I've got an app where I created an empty Domain Service from the template. The domain service has a single method on it where I return a presentation model class that I project into with some LINQ stuff. Here's the method signature, etc. for the domain service:
[EnableClientAccess()]
public class StatisticsService : DomainService
{
private ServiceInspectorEntities ctx = new ServiceInspectorEntities();
[RequiresRole(RoleNames.Administrator, RoleNames.ServiceAdministrator)]
public StatisticsPM GetStatistics(int DealerId, DateTime startDate, DateTime endDate)
{
// do LINQ
StatisticsPM stats = new StatisticsPM();
// add LINQ results
return stats; // <- breakpoint here
}
Here's the problem: I code on two different machines
desktop -> running VMWare Player with the virtual machine: WinServer2008, SQL Server 2008R2, .NET 4, IIS7, etc.
laptop -> running VMWare Fusion with the identical sourced virtual machine (I copied it from one to the other, so the environments are identical)
I sync the code between each using git/github
In the code above, I breakpoint the return statement:
desktop -> stats are as expected
laptop -> stats are as expected
Then I breakpoint the client side where I call the domain service and when it returns I inspect LoadOperation.Entities:
desktop -> LoadOperation.Entities are as expected (match what I returned on server side)
laptop -> LoadOperation.Entities are empty
LoadOperation.Error is null for both -- no errors at all
It is the second result here that baffles me. Same environment, same code, same results before being sent over the wire. Somewhere in the serialization process on either the client or server side the results are lost, and I'm looking for any clues from seasoned veterans who might say, "Oh yea, I've seen that before...you have to tweak such and such"...b/c I've quadruple checked my git status and database on each machine...done several clean builds and cleared the browser cache, etc., running out of ideas.
I haven't compared what Windows Update may have done between each Virtual Machine to verify if they have the same patch level / updates. It could be they are different, but I'm hoping it is something simpler.
Thanks