asp.net-core-mvc

HttpContext.User is null inside controller in Asp.net core MVC 3.1

依然范特西╮ 提交于 2020-04-30 06:25:05
问题 In my application I sign-in with Claim and Use cookie authentication without ASP.NET Core Identity For that in login action use bellow code ,as describe here var claims = new List<Claim>(); foreach (var customclaim in customclaims) { claims.Add(new Claim(customclaim.Type, customclaim.Value)); } var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var authProperties = new AuthenticationProperties { //AllowRefresh = true, //ExpiresUtc =

How do I send a string through html into a controller. ASP.NET MVC

别来无恙 提交于 2020-04-18 05:35:53
问题 I have a method that exports data into Excel called ExportCSV(). I would like a method that has some added ability: ExportCSV(string searchString) where the string that's in the search bar on the web page is sent to this method where I can then use it. So my question is, how can I send the string in the search bar into this method? The relevant code is below. the html The 's are for a search function that does work, but I can't get a similar functionality to work for exporting <input type=

Overriding ModelBindingMessageProvider error messages

可紊 提交于 2020-04-18 03:49:24
问题 I have a .net core 2.2 webapi. There is a POST action that accepts a model. The model has a Guid as one of the properties. When I post this model but supply a string and not a Guid, I get a ModelState.IsValid = false , which is correct. The default model binding error message is "Error converting value \"string\" to type 'System.Guid'. Path 'memberId', line 3, position 22." This is not a friendly message that I want to return, also, this message needs to get localized to user's language. All

how to migrate dotnet core 2.2 webapi to dotnet core 3.0

雨燕双飞 提交于 2020-04-14 07:38:11
问题 I was following this guide in here https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#mvc-service-registration but failed, so I create a new project with .net 2.2 (empty and fresh one with just one controller) then trying to migrate to 3.0. And I have failed again, especially in Startup.cs, the DI cannot detect method services.AddMvc(); It seems my code still refer to .net 2.2 instead of to .net 3.0 if I run .net watch run I got this error:

how to migrate dotnet core 2.2 webapi to dotnet core 3.0

假如想象 提交于 2020-04-14 07:38:09
问题 I was following this guide in here https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#mvc-service-registration but failed, so I create a new project with .net 2.2 (empty and fresh one with just one controller) then trying to migrate to 3.0. And I have failed again, especially in Startup.cs, the DI cannot detect method services.AddMvc(); It seems my code still refer to .net 2.2 instead of to .net 3.0 if I run .net watch run I got this error:

Loading views in WPF self-host asp.net core application

青春壹個敷衍的年華 提交于 2020-04-13 18:10:20
问题 We need to self-host an Asp.Net Core application in a WPF APP, APIs are working fine but there is some issues loading cshtml views. Here is our code: Host Builder: public static class HostBuilder { private static IWebHost host; public static async Task Start() { if (host == null) { var ip = System.Net.IPAddress.Parse("127.0.0.1"); var port = 9388; host = new WebHostBuilder() .UseKestrel(options => { options.Listen(ip, port); }) .UseStartup<HostStartup>() .Build(); await host.RunAsync(); } } }

How to correctly resolve services to use in the ConfigureServices() in ASP.NET Core 3.1?

帅比萌擦擦* 提交于 2020-04-13 07:04:50
问题 I have an ASP.NET Core 3.1 based app. During the app startup, in the ConfigureServices(IServiceCollection services) I want to register my services. But during configuring services, I want to boot the app based on settings found in the database. Here is my code public void ConfigureServices(IServiceCollection services) { // Register context services.AddDbContext<AppDbContext>(options => { options.UseMySql(Configuration.GetConnectionString("MySqlServerConnection")); }); // Reister the setting

Conditional validation in MVC.NET Core (RequiredIf)

*爱你&永不变心* 提交于 2020-04-12 17:41:27
问题 I am trying to conditionally validate the field within the MVC.NET Core. I have two radio buttons. If I select Yes (for the Ownership) I want to make a field below required (Activity dropdown) However, no matter how hard I try, the value to be validated always comes from the Activity field, not from the Ownership field ("N\A" instead of "Yes") Can somebody please tell me what I am doing wrong The View (chtml) <div class=" form-group"> <div class="bisformdynamiclabel"></div> <br /> @Html

Conditional validation in MVC.NET Core (RequiredIf)

江枫思渺然 提交于 2020-04-12 17:41:05
问题 I am trying to conditionally validate the field within the MVC.NET Core. I have two radio buttons. If I select Yes (for the Ownership) I want to make a field below required (Activity dropdown) However, no matter how hard I try, the value to be validated always comes from the Activity field, not from the Ownership field ("N\A" instead of "Yes") Can somebody please tell me what I am doing wrong The View (chtml) <div class=" form-group"> <div class="bisformdynamiclabel"></div> <br /> @Html

ASP.Net Core register Controller at runtime

☆樱花仙子☆ 提交于 2020-04-07 12:04:33
问题 I am asking myself if it is possible to load a DLL with Controller s in it at runtime and use it. The only solution I've found is to add an assembly via ApplicationPart on the StartUp : var builder = services.AddMvc(); builder.AddApplicationPart( AssemblyLoadContext.Default.LoadFromAssemblyPath( @"PATH\ExternalControllers.dll" )); Do anyone know if it is possible to register Controller at any time, because the issue with that solution is, that you have to restart the WebService when you want