asp.net-core-mvc

ASP.net Core RC2 Web API POST - When to use Create, CreatedAtAction, vs. CreatedAtRoute?

末鹿安然 提交于 2019-12-03 04:12:37
What are the fundamental differences of those functions? All I know is all three result in a 201, which is appropriate for a successful POST request. I only follow examples I see online, but they don't really explain why they're doing what they're doing. We're supposed to provide a name for our GET (1 record by id): [HttpGet("{id}", Name="MyStuff")] public async Task<IActionResult> GetAsync(int id) { return new ObjectResult(new MyStuff(id)); } What is the purpose of naming this get function, besides that it's "probably" required for the POST function below: [HttpPost] public async Task

MVC 6 View Components vs. Partial Views: What is the difference? When should each be used? [closed]

谁说胖子不能爱 提交于 2019-12-03 04:09:48
Closed . This question is opinion-based. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . MVC 6 Introduced View components and said it is much stronger and flexible than partial views. Are view components meant to replace partial views? What is the difference and what kinds of situations call for each implementation? Jalpesh Vadgama According to this link- https://docs.asp.net/en/latest/mvc/views/view-components New to ASP.NET MVC 6, view components (VCs) are similar to

How to add Roles to Windows Authentication in ASP.NET Core

让人想犯罪 __ 提交于 2019-12-03 03:58:43
问题 I created an asp.net core project in visual studio 2015 with windows authentication. I can't figure out how to add roles to the Identity. I have a table with usernames for the windows account. And when the user opens the website the user is added to the Identity (I assume that's what happens, because I can display the username by User.Identity.Name) and I want to pull out Roles from another table and assign them to the user, is this possible? Or perhaps is there a better way to do it? (Why?,

How to design a Repository Pattern with Dependency Injection in ASP.NET Core MVC?

时光毁灭记忆、已成空白 提交于 2019-12-03 03:47:28
问题 Being fairly new to ASP.NET Core 1.0 MVC, I have decided to use a Repository Pattern for an MVC Core app; I'm using a SQL DB for the Data Layer SampleDbContext , and I want to have a Repository class for some of my business Entities. So far I have done the following in the startup.cs , CustomerController.cs and CustomerRepository.cs files, where a sample Entity is "Customer". In the ConfigureServices method of the Startup Class: public void ConfigureServices(IServiceCollection services) {

How to compile .less files on save in Visual Studio 2015 (preview)

旧时模样 提交于 2019-12-03 03:30:52
问题 Ok, so I've created a new ASP.Net 5 / MVC 6 project in Visual Studio 2015 Preview. In keeping with our current method of doing things, for styling I want to use .less files. Creating the files is straightforward, but Web Essentials no longer compiles them. So my question is this: what precisely do I need to do to get my .css files generated when I save the .less files? Based on my adventures getting Typescript to work nicely, I will have to use Grunt to accomplish this task, but I am brand

How override ASP.NET Core Identity's password policy

寵の児 提交于 2019-12-03 03:29:12
问题 By default, ASP.NET Core Identity's password policy require at least one special character, one uppercase letter, one number, ... How can I change this restrictions ? There is nothing about that in the documentation (https://docs.asp.net/en/latest/security/authentication/identity.html) I try to override the Identity's User Manager but I don't see which method manages the password policy. public class ApplicationUserManager : UserManager<ApplicationUser> { public ApplicationUserManager(

ASP .NET 5 MVC 6 Identity 3 Roles Claims Groups [closed]

我只是一个虾纸丫 提交于 2019-12-03 02:51:42
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I'm currently looking for a solution to use an advanced Roles/Group Permission management in ASP .NET 5 MVC 6 with Identity 3. I started a new Preview Starter Web Project with a integrated easy login system. Now I need a complex "users permission management" with following

How do I specify different Layouts in the ASP.NET Core MVC

冷暖自知 提交于 2019-12-03 01:51:18
I would like to have 2 separate Layouts in my application. Let say one is for the Public section of the website and the other is empty for some reasons we need. Before Core I could do this to define a filter: public class LayoutInjecterAttribute : ActionFilterAttribute { private readonly string _masterName; public LayoutInjecterAttribute(string masterName) { _masterName = masterName; } public override void OnActionExecuted(ActionExecutedContext filterContext) { base.OnActionExecuted(filterContext); var result = filterContext.Result as ViewResult; if (result != null) { result.MasterName =

MVC 6 install as a Windows Service (ASP.NET Core 1.0.0)

ⅰ亾dé卋堺 提交于 2019-12-03 01:47:06
UPDATE - 26th July 2016 I have added the solution to this in ASP.NET Core 1.0.0 in the answers below. I have created a simple MVC 6 app and have included the Microsoft.AspNet.WebListener library so I can host outside of IIS. From project.json: "dependencies": { "Microsoft.AspNet.Server.WebListener": "1.0.0-beta4", "Microsoft.AspNet.Mvc": "6.0.0-beta4" }, "commands": { "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000" } When I publish this I can run the web.cmd file and get the site running in a console window. Great! But in OWIN

ASP.NET Core Identity Add custom user roles on application startup

安稳与你 提交于 2019-12-03 01:31:53
In an ASP.NET Core application, I want to create certain roles as a basis to manage different user-permissions. Sadly, the documentation inform detailled how to use custom roles e.g. in controllers/actions, but not how to create them. I found out that I can use RoleManager<IdentityRole> for this, where the instance gets automatically injected in a controller-constructor, when its defined and ASP.NET Core identity is registered in the application. This let me add a custom role like this: var testRole = new IdentityRole("TestRole"); if(!roleManager.RoleExistsAsync(testRole.Name).Result) {