asp.net-core-mvc

WS-Federation sign-in Asp.NET 5 MVC 6 ADFS

感情迁移 提交于 2019-12-20 19:44:09
问题 Hello so I've been trying to achieve WS-Fed SSO on my MVC6 web application, I've read a bit on authentification and all to identify my requirements. I have to use WsFederationAuth so no oauth nor saml protocol would work for me. Edit : After @Pinpoint suggestion I tried to use owin middleware to achieve the connection, but I will use the full framework DNX451 rather than DNXCore but it's something while waiting for ws-fed to be supported by Vnext. Pinpoint adapter extension: public static

Cookies in ASP.Net MVC 5

偶尔善良 提交于 2019-12-20 17:32:12
问题 I am developing an application in which users are SignUp or SignIn by External Identity Providers like AAD, Google, WS-Federated Authentication etc. Now I want to create cookies on a user machine to logged in until user SignOut. Give me some thought and guide me how I can overcome it. thanks in advance. 回答1: Use Request.Cookies and Response.Cookies to handle your situation. once user coming back from third party authorization create cookie and store it in browser and once user Logout clear

ASP.NET Core MVC Mixed Route/FromBody Model Binding & Validation

夙愿已清 提交于 2019-12-20 11:53:09
问题 I am using ASP.NET Core 1.1 MVC to build an JSON API. Given the following model and action method: public class TestModel { public int Id { get; set; } [Range(100, 999)] public int RootId { get; set; } [Required, MaxLength(200)] public string Name { get; set; } public string Description { get; set; } } [HttpPost("/test/{rootId}/echo/{id}")] public IActionResult TestEcho([FromBody] TestModel data) { return Json(new { data.Id, data.RootId, data.Name, data.Description, Errors = ModelState

Return HTTP 403 using Authorize attribute in ASP.Net Core

与世无争的帅哥 提交于 2019-12-20 11:18:09
问题 When using ASP.Net WebAPI, I used to have a custom Authorize attribute I would use to return either an HTTP 403 or 401 depending on the situation. e.g. if the user is not authenticated, return a 401 ; if the user is authenticated but doesn't have the appropriate permissions, return a 403 . See here for more discussion on that. It seems now, in the new ASP.Net Core, they don't want you overriding the Authorize attribute anymore instead favoring a policy-based approach. However, it seems Core

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

牧云@^-^@ 提交于 2019-12-20 10:58:40
问题 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,

.NET CLI how to run app after publish on Linux

最后都变了- 提交于 2019-12-20 10:39:20
问题 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

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

限于喜欢 提交于 2019-12-20 10:33:31
问题 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

How to automatically populate CreatedDate and ModifiedDate?

混江龙づ霸主 提交于 2019-12-20 10:33:20
问题 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

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

这一生的挚爱 提交于 2019-12-20 10:33:07
问题 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

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

纵然是瞬间 提交于 2019-12-20 10:28:05
问题 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