By default dotnet core limits the form element count to 1024. To submit forms with more elements, increase the limit in the ConfigureServices() method of the Startup.cs file:
Tag Archives: C#
Could not create an instance of type ‘Microsoft.AspNetCore.Http.HttpContext’
The new version of dotnet core cannot handle the HttpContext in the MVC model. An unhandled exception has occurred while executing the request. System.InvalidOperationException: Could not create an instance of type ‘Microsoft.AspNetCore.Http.HttpContext’. Model bound complex types must not be abstract or value types and must have a parameterless constructor. Alternatively, set the ‘HttpContext’ property to …
Continue reading “Could not create an instance of type ‘Microsoft.AspNetCore.Http.HttpContext’”
Read the database connection string and other secrets from environment variables
It is not good practice to store secrets in the source code repository. The sample C# dotnet core application code stores the database connection string in the appsettings.json file which eventually will be pushed into GitHub. To follow the Twelve-Factor App methodology, store the configuration values in environment variables and load them runtime. This method …
Continue reading “Read the database connection string and other secrets from environment variables”
Add identity into an ASP.NET Core 2.1 MVC project and maintain full control of the Identity UI
To maintain full control over the Identity UI in an ASP.NET Core 2.1 MVC project, scaffold the identity using the Windows version of Visual Studio 2017. Scaffold the Identity Right click the web application project and select Add, New Scaffolded Item… On the left side of the Add Scaffold dialog select Identity, and click the Add button …
Error unprotecting the session cookie in an ASP.NET Core MVC application.
The new ASP.NET Core MVC framework automatically displays a message for the user to accept the application’s privacy policy. The default message is “Use this space to summarize your privacy and cookie use policy.” No cookies are saved in the user’s browser until they click the Accept button. Even after accepting the terms, if the browser …
Continue reading “Error unprotecting the session cookie in an ASP.NET Core MVC application.”
Set the environment for an ASP.NET Core MVC web application
When the ASP.NET Core MVC web application starts, reads the name of the environment for an environment variable of the host computer. The compiled application contains the configuration for all supported environments, making possible to build and deploy the same artifact in every environment. If the ASPNETCORE_ENVIRONMENT environment variable is not defined, the Production environment settings are …
Continue reading “Set the environment for an ASP.NET Core MVC web application”
Block comment in ASP.NET MVC Razor file
To comment out a block of lines in the ASP.NET MVC Razor file, enclose them in @* and *@ @* Commented out instructions, including HTML and Extension methods *@
Procedure or function ‘`…_Insert`’ cannot be found in database …
When you use the Microsoft .NET Entity framework to access a MySql database, the autogenerated code throws an error when you try to insert a row into the database with context.MY_TABLE.Add(MY_OBJECT); Server Error in ‘/’ Application. Procedure or function ‘`…_Insert`’ cannot be found in database ‘`…`’. Description: An unhandled exception occurred during the execution of …
Continue reading “Procedure or function ‘`…_Insert`’ cannot be found in database …”
No connection string named ‘…’ could be found in the application config file.
Two-tier applications separate the presentation layer and the data layer, and all database access related objects are located in the data-tier. When the application runs, the config file of the main project is read. In web applications, it is the web.config, in console applications the app.config file. When you get the following runtime exception Exception thrown: ‘System.InvalidOperationException’ in …
Continue reading “No connection string named ‘…’ could be found in the application config file.”
NotSupportedException: Unable to determine the provider name for provider factory of type ‘MySql.Data.MySqlClient.MySqlClientFactory’. Make sure that the ADO.NET provider is installed or registered in the application config
In a two-tier web application, the data layer is in a separate project. This allows better separation between the presentation layer and the data layer. This way you can reuse the data project in another application that targets the same database. To access a MySql database you need to add the MySql.Data and MySql.Data.Entity NuGet packages to …