asp.net-core-2.0

Not creating database using Migration command Update-Database in ASP.Net Core 2

喜欢而已 提交于 2021-02-06 04:22:29
问题 I created new ASP.Net core project with WebAPI. Using the below link. jwt-authentication-with-aspnet-core-2-web-api-angular-5-net-core-identity-and-facebook-login I have to use add-migration update-database manually. Here I add one thing more that I don't know how to debug app in VS Code. After created my project in VS Code I open my project in Visual Studio 2017. When I about to run the update command Update-Database in Package Manager Console. I encounter below error also in my

Entity Framework map model class to table at run time

血红的双手。 提交于 2021-02-05 10:30:26
问题 In a project using ASP.NET Core 2.0 and Entity Framework, I'm trying to map a known table schema (coded into class MyTableClass ) to an unknown table name. This table name is given by the user at run time, so this is done outside of the OnModelCreating method of the Context class. Is there a way to do something like the following pseudocode: void OnUserEnteredTableNameFromUI(string tableName) { var modelBuilder = new ModelBuilder(???); // how? modelBuilder.Entity<MyTableClass>().ToTable

Entity Framework map model class to table at run time

安稳与你 提交于 2021-02-05 10:27:39
问题 In a project using ASP.NET Core 2.0 and Entity Framework, I'm trying to map a known table schema (coded into class MyTableClass ) to an unknown table name. This table name is given by the user at run time, so this is done outside of the OnModelCreating method of the Context class. Is there a way to do something like the following pseudocode: void OnUserEnteredTableNameFromUI(string tableName) { var modelBuilder = new ModelBuilder(???); // how? modelBuilder.Entity<MyTableClass>().ToTable

Unable to connect to MongoDb (using authentication) using mongocsharpdriver 2.7.0

一曲冷凌霜 提交于 2021-01-29 14:13:23
问题 I have created a sample c# console application to connect to mongodb hosted on CentOS machine on a docker. The command used to create container is below: docker run -d --name mongodb-container -p 2020:27017 -v /home/mongodb_data:/var/lib/mongodb/data -v /home/mongodb_log:/var/log/mongodb -v /home/mongod.conf:/etc/mongod.conf -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e MONGO_INITDB_ROOT_PASSWORD=secret mongo System IP: 172.17.103.158 Mongodb docker port: 2020 Now coming to c# code class users

How to update target framework of .net project?

廉价感情. 提交于 2021-01-29 11:08:20
问题 I had created a project in .Net Core 2.0 and now with the new release of .Net Core 2.1, I want to update to it. So is it just ok that I go to project properties and update Target Framework to 2.1 or do I also need to make any change in my code? According to this article https://docs.microsoft.com/en-us/aspnet/core/migration/20_21?view=aspnetcore-2.1, Microsoft.AspNetCore.All package is now replaced by Microsoft.AspNetCore.App. So I want to ask if I don't update this package, will anything

ASP.Net Core: keep windows authentication

。_饼干妹妹 提交于 2021-01-29 11:01:40
问题 I'm actually working on an website where users login via windows authentication. My problem is, that actually all users have to login whenever they open our webpage. I wonder if it is possible to keep that windows authentification alive? Maybe with cookies? I implemented the authentification by adding this to my Startup.cs : services.Configure<IISOptions>(options => { options.AutomaticAuthentication = true; }); services.AddAuthentication(IISDefaults.AuthenticationScheme); And activating

Set default input value Datetime.Now on create view MVC ASP.NET Core 2?

南笙酒味 提交于 2021-01-29 10:37:02
问题 How can I set default value of input OpenDate is date and time of server. <div class="form-group"> <label asp-for="OpenDate" class="control-label">Ngày đăng ký</label> <input asp-for="OpenDate" class="form-control" /> <span asp-validation-for="OpenDate" class="text-danger"></span> </div> 回答1: In your model: [BindNever] public System.DateTime OpenDate { get; set; } In your Controller (where you are posting the form) yourModel.OpenDate = DateTime.Now; In your View: You can exclude the code that

Microsoft Graph, adding multiple attachments to an email

↘锁芯ラ 提交于 2021-01-29 08:26:35
问题 I am using .netCore and Microsoft Graph and trying to add multiple attachments to an email and send it. The email sends nicely, all is there (if i send 2 attachments you see that there are 2 attachments), however only the first attachment is able to be opened up by the recipient. (the attachments all together are less than the 4MB max, so that is not the issue). The code is string content = "{\"message\":{" + "\"subject\":\"" + email.Subject + "\"," + "\"body\":{" + "\"contentType\": \"HTML\"

Area is not passed to Url.Action() in ASP.net Core

爷,独闯天下 提交于 2021-01-29 05:25:24
问题 The following code is working in normal ASP.net MVC. Url.Action("actionName", "controllerName", new { Area = "areaName" }); But it is not work well in ASP.net Core. Area is recognized as a query string parameter. How can I solve it? Thanks for any help. 回答1: Make sure you're registering routes as below : app.UseMvc(routes => { routes.MapRoute( name: "areaRoute", // if you don't have such an area named as `areaName` already, // don't make the part of `{area}` optional by `{area:exists}`

asp.net core headers caching issue

[亡魂溺海] 提交于 2021-01-29 02:50:56
问题 Here are the request headers from postman to my asp.net_core 2.0 API. Content-Type: application/json Accept: application/json Response from my asp.net core application is an exception thrown in a string format. But the below response headers have been sent from the API to postman. Cache-Control : no-cache, no-store, must-revalidate Pragma : no-cache Transfer-Encoding : chunked Content-Type : application/json ; charset=utf-8 Age : 0 Server : Kestrel Since the Request body is a string , and the