asp.net-core-mvc

Visual Studio 2017 csproj .NET Core build - views not being copied correctly

霸气de小男生 提交于 2019-12-05 23:31:45
问题 I have a project running in .NET Core and I am using VS2017 as IDE. When I build my project through Visual Studio 2017 it does not automatically add the Views folder and the wwwroot folder to the output in [projectRoot]/bin/Debug/netcoreapp1.1/win10-x64 ( BuildDir ). This means that if I try to run my website directly from the .exe file created in the bin folder, I get an error with the missing views and wwwroot . If I manually copy these folders to the BuildDir then the views load correctly.

How to logout all users in ASP.NET Core cookie authentication?

我是研究僧i 提交于 2019-12-05 23:12:29
问题 I'm using ASP.NET Core MVC with CookieAuthentication. Is there a way I can sign all users out at once? I tried resetting IIS - didn't work. I tried deleting all the users' sessions (I'm using a database for session storage) - didn't work. Any ideas? 回答1: With CookieAuthentication, the cookie is simply an encrypted string containing the user's name, roles, and auxilliary data. In short, it identifies the user , not the session. Killing sessions does not invalidate the cookie. That being said,

How to turn on Roles in Asp.net Identity 3.0 and MVC 6?

假如想象 提交于 2019-12-05 22:54:47
I am not sure if I am missing something here. By Default User.IsInRole() does not work even if user DOES HAVE some roles. I don't have my own implementation of role stores. I am assuming that the default ones should work. Is there something special that I need to do in the Startup.cs to get the roles working? I'm using mvc 6 beta 2 default template. The User.IsInRole() does not work if I add a role like this: await UserManager.AddToRoleAsync(user, "Admin"); But it does work if I do this: await UserManager.AddClaimAsync(user, claim: new Claim(ClaimTypes.Role.ToString(), "Admin")); It looks like

How to get Action and Controller name in ASP.Net Core MVC app?

喜欢而已 提交于 2019-12-05 22:43:01
How to get Action and Controller names in ASP.Net MVC Core RC1 Application in Startup.cs ? I want to create a middleware and log the information (I want to Log detailed response to my Database, so I need Action and Controller info.) after following code in configure method of startup.cs - app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=User}/{action=Index}/{id?}"); }); //Want to get Action and controller names here.. You'll want to inject the IActionDescriptorCollectionProvider service into your middleware. From that, you can use the property ActionDescriptors

How to get the database context in a controller

蓝咒 提交于 2019-12-05 22:04:55
问题 I am trying all day to figure out to get the ApplicationDbContext in the ManageController.cs of a default MVC 6 project. I went online and Googled a lot but no one seems to have the same problem as I have with it. It is probably simple but I can't figure it out. Anyone has an idea? Here is what I tried: IServiceProvider service = new IServiceProvider(); var _context = service.GetService<ApplicationDbContext>(); 回答1: Use constructor injection: public class ManageController { private readonly

Debugging not hit breakpoints in .NET CORE MVC 6 application

亡梦爱人 提交于 2019-12-05 21:56:57
问题 I am working on .NET CORE 1.0 MVC 6 application and I stuck with the debugging point as it stopping hitting yesterday. with number of try I delete project and start again. First time it load symbols even due I have uncheck in Tool --> Debugging --> symbols, however it hit breakpoints. Now it only hitting C# class 'Startup.cs' if I choose 'Enable Just My Code' but in controller. I have Debug option from dropdown, not really sure why. Need help here. I change as Select Debug->Options->Debugging

How to precompile views in ASP.NET Core 2.0?

天大地大妈咪最大 提交于 2019-12-05 21:54:02
问题 I set up my solution according to this article. I left out some of the things because according to this, ASP.NET Core 2.0 precompiles views by default. In the end, I publish it to a folder, which ends successfully, but my precompiledviews.dll is missing. I tried setting it explicitly in .csproj, but no luck. Edit: Both of the projects inside the solution are just default MVC templates. 回答1: I bet you use Self-contained deployment, i.e. publish with command like dotnet publish --configuration

Dependency injection in Xunit project

不想你离开。 提交于 2019-12-05 21:24:25
问题 I am working on an ASP.Net Core MVC Web application. My Solution contains 2 projects: One for the application and a second project, dedicated to unit tests. I have added a reference to the application project in the Tests project. What I want to do now is to write a class in the Tests project which will communicate with the database through entity framework. What I was doing in my application project was to access to my DbContext class through constructor dependency injection. But I cannot do

Deploy .NET Core ASP.NET Website - HTTP Error 502.5 - Process Failure

折月煮酒 提交于 2019-12-05 20:40:55
I'm trying to publish the template project "ASP.NET Core Web Application (.NET Framework)" from Visual Studio 2015 to IIS. I use the Visual Studio publish to File System feature. I'm using Windows 10. I followed the guide from here . I set up a website in IIS and changed the Application Pool .NET CLR Version to No Managed Code I instaled the .NET Core Windows Server Hosting bundle I restarted my machine. I get this error: I added a logs folder, but no logs get created. Any ideas on how I can solve this? EDIT: Output of running the .exe from powershell: PS C:\TestCoreWebsite> .\Web

Error in Service IUserStore being created in Identity Asp.net core 3 MVC

℡╲_俬逩灬. 提交于 2019-12-05 20:40:28
Update See Update below. I have asked a previous stackoverflow question very recently, but I face an issue after implementing the suggested solutions from the following 2 places Identity model customization in ASP.NET Core and Custom storage providers for ASP.NET Core Identity . I am just not able to get the solution to work. I have implemented the extension of IdentityUser as recommended and the extension of IdentityRole . I have implemented IUserPasswordStore and IUserRoleStore and IUserStore for UserStore and I have implemented IRoleStore for RoleStore . I have also implemented the new