asp.net-core-mvc

How do I configure routing for MVC and SignalR in an ASP.NET Core project?

不想你离开。 提交于 2019-12-10 16:00:05
问题 I'm trying to build a web app with ASP.NET Core 2.1.0-preview1 and ASP.NET Core SignalR 1.0.0-alpha1 with an Angular4 client. So far I've been able to muddle through and can actually open a SignalR web socket connection from within the client. That came at a price, though, here's an excerpt of my Startup.cs : app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); /*routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new {

How to detect dnx451 web application shutdown in AspNet5 / Mvc6?

别等时光非礼了梦想. 提交于 2019-12-10 15:59:37
问题 To be able to shutdown background process (implemented with Quartz.Net) I need to detect web application shutdown in AspNet5 beta8. In previous versions of Asp.Net it was possible to execute code on Application_End. What is the equivalent of Application_End event in AspNet5? So far I tried IApplicatonLifetime in Configure, but it does not fire when I stop the web application: public void Configure(IApplicationBuilder app, IApplicationLifetime lifetime) { lifetime.ApplicationStopping.Register(

Checking for one of multiple policies with Authorize attribute in ASP.NET Core Identity

﹥>﹥吖頭↗ 提交于 2019-12-10 15:55:32
问题 I have setup a standard authentication system up in an ASP.NET Core application. Users, Roles, RoleClaims(acting as permissions) In Startup.cs I create a policy for each Role and each Permission. Assuming this would give me full flexibility in my Views to be able to say I want this button to show if user is part of a role that has claim DeleteCustomer or if User belongs to role Superuser. How can I do an OR condition using the Authorize attribute. For example all throughout my site I want

UserValidator in Microsoft.AspNet.Identity vnext

天涯浪子 提交于 2019-12-10 15:50:00
问题 I have a problem where I cant use email addresses as usernames when using microsoft.aspnet.identity (Individual user accounts selected when creating new project - default mvc project template for asp.net 5). I have read in many places that this is the solution: UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager) { AllowOnlyAlphanumericUserNames = false }; But in the new version of asp.net identity, UserManager doesnt seem to have a property called UserValidator. The

ModelState.IsValid always true, regardless of DataAnnotations attributes

↘锁芯ラ 提交于 2019-12-10 15:38:48
问题 I'm using the new MVC6 framework with Visual Studio 2015, and suddenly all my Data Annotations stopped working. All of them, without me changing the code. public sealed class RegisterUser { [Required(ErrorMessage = "required")] [RegularExpression(@"^((.|\n)*)$", ErrorMessage = "regex")] [StringLength(32, MinimumLength = 3, ErrorMessage = "length")] public string Name { get; set; } ... } And [Route(Address + "/membership")] public class MembershipController : Controller { // POST [address]

.NET Core : Process.Start() leaving <defunct> child process behind

守給你的承諾、 提交于 2019-12-10 15:31:18
问题 I'm building an ASP.Net Core (netcore 1.1) application deployed on CentOS 7.2. I have an action which calls an external process (a console application also built with .net core) through System.Diagnostics.Process and doesn't wait for it to exit before returning. The problem is that the said process becomes and stays <defunct> even after it has finished executing. I don't want to wait for it to exit because that process could take several minutes to do its job. Here is a sample code //The

How to get a session value in layout file in ASP.NET 5 MVC6

穿精又带淫゛_ 提交于 2019-12-10 15:02:34
问题 In ASP.NET 5 MVC 6 Beta 8 I need to read a session variable in in my _Layout.cshtml or alternatively get a reference to the current HttpContext. Take note: In ASP.NET 5 referencing the Session object has changed significantly from ASP.net 4 as detailed in this question The Context object has also been renamed to HttpContext between Beta7 and Beta8. In My current controller I currently save the session variable like this public IActionResult Index() { HttpContext.Session.SetInt32("Template",

Blocking anonymous access by default in ASP .NET 5

纵饮孤独 提交于 2019-12-10 15:00:09
问题 My team and I are starting up a new website project in ASP .NET 5 and I'm trying to set up the basis of our user authentication and authorization policy. So far, I've managed to use the [Authorize] and [AllowAnonymous] attributes to selectively define an authorization policy controllers or actions. The one thing I'm still struggling to achieve is defining a default authorization policy. Bascially, I'd like every controller and action to behave as if they had an [Authorize] attribute by

ASP.NET Core : Generate Razor Pages for all models

百般思念 提交于 2019-12-10 15:00:06
问题 I have created a ASP.NET Core 2.1 project With "Database first" approach and Razor Pages (no MVC). All my models are generated from the database context. I successfully created CRUD Razor Pages for one of my models with a command line like this one : dotnet aspnet-codegenerator razorpage -m Student -dc RazorDemoContext -udl -outDir Pages\Students I have approximatively 50+ models. Is there a command line to generate CRUD Razor Pages for all models at the same time and not just one by one ?

How to set the cookie validateInterval in ASP.NET Core?

旧街凉风 提交于 2019-12-10 14:45:33
问题 I'm trying to set the validateInterval for an ASP.NET 5 RC1 application which makes use of ASP.NET Identity 3 I am trying to implement the code in this answer. there are many code sample like this answer but it seems it isn't valid in ASP.NET 5 RC1 app.UseCookieAuthentication(new CookieAuthenticationOptions { Provider = new CookieAuthenticationProvider { OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>( validateInterval: TimeSpan