asp.net-core-mvc

What is the advantage of using Tag Helpers in ASP.Net MVC 6

江枫思渺然 提交于 2019-12-03 01:12:16
Apologized that I am not very good in asp.net mvc that I would like to confess. I just come across a good write up for asp.net 5 new feature from this url . From there I heard about a term called Tag Helpers in ASP.Net MVC 6 and I saw there people say before developer create form this below way: @model MyProject.Models.Product @using (Html.BeginForm()) { <div> @Html.LabelFor(m => p.Name, "Name:") @Html.TextBoxFor(m => p.Name) </div> <input type="submit" value="Create" /> } and now people can code the same with tag helper the below way @model MyProject.Models.Product @addtaghelper "Microsoft

Submitting a razor form using JQuery AJAX in MVC6 using the built-in functionality

百般思念 提交于 2019-12-03 00:30:06
问题 I would like to know if there is a specific way to submit a form using jQuery AJAX in MVC6, still using the Auto Binding features of ASP.NET MVC. I believe in other versions of MVC you could use jquery.unobtrusive-ajax and simply use @using (Ajax.BeginForm("SaveData", new AjaxOptions(){} Since there have been some changes with MVC6 I am wondering what the new recommended way to do this would be besides doing a normal AJAX post to the server when the form is submitted. This meaning I would

.NET CLI how to run app after publish on Linux

你离开我真会死。 提交于 2019-12-02 23:44:33
I spent ~4 hours investigation and still can't find out how to run published application ( dotnet publish ) Now I can download sources to my remote machine, then call dotnet build and dotnet run - then my app runs as intended. But I want to publish just DLL's (or *.so ?) to my VPS without source files. What official docs says? To define command in project.json "commands": { "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/var/aspnet/HelloMVC/kestrel.sock", } But it is obsolette, isn't it? What about default samples? In default VS2015 sample solution they use publish-iis, Full

How to automatically populate CreatedDate and ModifiedDate?

自古美人都是妖i 提交于 2019-12-02 23:32:16
I am learning ASP.NET Core MVC and my model is namespace Joukyuu.Models { public class Passage { public int PassageId { get; set; } public string Contents { get; set; } public DateTime CreatedDate { get; set; } public DateTime ModifiedDate { get; set; } } } The Passage table is used to save passages I wrote. Scenario Create view just has one field Contents to input a passage. CreatedDate and ModifiedDate must be automatically set equal by the server (using UTC format). Edit view just has one field Contents to edit a passage. ModifiedDate must be automatically set by the server. Question What

How to register custom UserStore & UserManager in DI

佐手、 提交于 2019-12-02 23:20:29
Here is my setup: public class ApplicationUser : IdentityUser<Guid> { } public class ApplicationRole : IdentityRole<Guid> { } public class ApplicationUserLogin : IdentityUserLogin<Guid> { } public class ApplicationUserClaim : IdentityUserClaim<Guid> { } public class ApplicationRoleClaim : IdentityRoleClaim<Guid> { } Here is the definition of my UserStore public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, MyContext, Guid> { public ApplicationUserStore(MyContext context, IdentityErrorDescriber describer = null) : base(context, describer) { } } Here is the definition

Best practice for storing ASP.NET Core Authorization claims when authenticating users against Active Directory?

萝らか妹 提交于 2019-12-02 23:02:32
I am creating an enterprise intranet ASP.NET Core MVC application. I want my users to authenticate using Active Directory and I want user authorizations (claims) stored in ApplicationDbContext . I assume that I need to use Microsoft.AspNetCore.Identity and Microsoft.AspNetCore.Identity.EntityFrameworkCore to accomplish my goals. What is the best practice for storing ASP.NET Core Authorization claims when authenticating against Active Directory? The following code will give me access to the current windows user security context (current logged in user), from within the pipeline. Somehow I need

ASP.Net MVC Angular 2 Final

夙愿已清 提交于 2019-12-02 22:20:34
Has anyone tried Angular 2 RC Final with ASP.Net MVC? I am having trouble with configuring Angular 2 RC 6 with ASP.Net MVC, till beta 17 everything was working fine. The package.json with below configuration doesn't seems to be working: "dependencies": { "@angular/common": "2.0.0-rc.6", "@angular/compiler": "2.0.0-rc.6", "@angular/core": "2.0.0-rc.6", "@angular/forms": "0.3.0", "@angular/http": "2.0.0-rc.6", "@angular/platform-browser": "2.0.0-rc.6", "@angular/platform-browser-dynamic": "2.0.0-rc.6", "@angular/router": "3.0.0-rc.1", "systemjs": "0.19.27", "core-js": "^2.4.0", "reflect-metadata

How to gzip static content in ASP.NET Core in a self host environment

这一生的挚爱 提交于 2019-12-02 22:17:53
Is there are way to serve gzip static cotent when using self host environment to publish an ASP.NET Core website? [Edit 2016-11-13] There is another way to serve gzipped files that replaces steps 2 and 3. It's basically quite the same idea, but there is a nuget package that does it all for you readily available. It basically checks if the is .gz or .br file that matches the requested one. If it exists it returns it with the appropriate headers. It does verify that the request has a header for the corresponding algorithm. Github code if you want to compile it yourself is here . There is also an

ISO UTC DateTime format as default json output format in MVC 6 API response

心不动则不痛 提交于 2019-12-02 22:06:48
Does anyone know how to configure MVC6's json output to default to a ISO UTC DateTime string format when returning DateTime objects? In WebApi2 I could set the JsonFormatter SerializerSettings and convert datetimes however i'm a bit stuck with how to do this in MVC6 And I just stumbled onto something that helped me figure it out. Just in case anyone wants to know In your Startup.ConfigureServices services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc; }); 来源: https://stackoverflow.com/questions/41728737/iso-utc-datetime-format

Is ViewData the new standard over ViewBag for ASP.Net 5 (core)?

一世执手 提交于 2019-12-02 21:56:49
I have noticed that in all the examples and tutorials on ASP.Net 5 (core) I have seen from Microsoft and the default Web Application template in VS 2015 use @ViewData["XXX"] instead of @ViewBag.XXX . Is this the, now, recommended way of passing data up from the controller instead of ViewBag ? I know that ViewBag is a wrapper for ViewData but in the old tutorials (ASP.NET 4.5) they use ViewBag . If they are now encouraging developers to use ViewData why the change? Both are still valid. There is no specific guidance on the docs.asp.net github project . Although there is this discussion on docs