asp.net-core-mvc

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

拥有回忆 提交于 2019-12-03 14:17:54
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . 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? 回答1: According to this link- https://docs.asp

Implementing custom claim with extended MVC Core Identity user

若如初见. 提交于 2019-12-03 14:14:22
How can I create a custom authorize claim in MVC Core 2.0 (using AspNetCore.identity) to verify a custom user boolean property? I have extended the IdentityUser (ApplicationUser) to include a boolean value "IsDeveloper". I am using claims based authentication and would like to add a custom claim, but am not certain where to start. How can I create a custom claim that will: Find the current (customized) Core.Identity user. Evaluate the a custom identity user bool value? I understand the core identity claims MSDN: Claims Based Authentication , but am new to custom claims, so I am not sure where

ASP.NET Core: How to get remote IP address?

走远了吗. 提交于 2019-12-03 13:34:41
问题 I try to get remote (client) IP addres: var ip = httpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress But it works only for local requests (it will return ::1 value) When I load page from remote machine the value is null. I investigated there is no IHttpConnectionFeature in the Features collection in this case. Why? And how to get remote ip address correctly? 回答1: I know that this post is old but I came here looking for the same question and finnaly I did this: On project.json

Get AuthenticationProperties in ASP.NET 5

拥有回忆 提交于 2019-12-03 13:16:01
In ASP.NET 5 MVC 6 RC1 how do I retrieve AuthenticationProperties from within a controller or from a filter? HttpContext.Authentication does't seem to have this functionality. I thought about registering an CookieAuthenticationEvents.OnValidatePrincipal handler and then using the Properties property on the CookieValidatePrincipalContext argument. Then I could store those AuthenticationProperties in the request cache so that later I'm able to get things like IssuedUtc . Is there a better solution where I don't need to store this myself? I'm not using ASP.NET Identity but the cookie middleware

AddOAuth linkedin dotnet core 2.0

喜夏-厌秋 提交于 2019-12-03 12:47:07
I'm using dotnet core I want to setup a LinkedIn authentication on the site since there is no default authentication builder for LinkedIn as facebook, google and twitter I decided to use the generic implementation as follows: services.AddAuthentication().AddOAuth("LinkedIn", c => { c.ClientId = Configuration["linkedin-app-id"]; c.ClientSecret = Configuration["linkedin-app-secret"]; c.Scope.Add("r_basicprofile"); c.Scope.Add("r_emailaddress"); c.CallbackPath = "/signin-linkedin"; c.AuthorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization"; c.TokenEndpoint = "https://www.linkedin

Translating Ninject to ASP.NET MVC 6 DI

冷暖自知 提交于 2019-12-03 12:41:15
I am trying to get into the new ASP.NET MVC 6 stuff, but I'm having a very hard time with their new DI system. I have tried to find resources online, but everything I find covers only the absolute most bare minimum to use it. I was previously using Ninject , and I have several wire-ups that work like this: Bind<IDocumentStore>() .ToMethod(c => CreateDocumentStore()) .InSingletonScope(); private static IDocumentStore CreateDocumentStore() { // lots of initialization code, etc. return documentStore; } But so far I am having a difficult time finding out how to translate this kind of behaviour to

Special characters in Razor template not being encoded correctly

旧城冷巷雨未停 提交于 2019-12-03 12:10:31
I make some test with ASP.NET Core MVC. I am trying to display special character like çùé. But it is displayed as �. Exemple : Create new view and put : <div>àçù</div> By default, the .cshtml file is encoded in "UTF-16". The charset in HTTP response header is "UTF-8". In _layout, the <head> contains the <meta charset="utf-8" /> tag. To resolve the problem, I can convert all .cshtml file to uft-8. What's the correct way to manage encodage in ASP MVC Core? Edit : Visual Studio 2017 RC create .cshtml file in 'utf-8', but the scaffolding create the .cshtml file in 'ISO 8851-1'. Can I explain to

Require SSL Client Certificate only for specific routes or controllers

送分小仙女□ 提交于 2019-12-03 12:05:12
I have an ASP.NET MVC Core project using Kestrel as the server. It is both serving up user content (asp.net mvc) and hosts web API controllers that agents (software) communicate with. I have enabled HTTPS and client certificate support. The issue is that I want to require client certificates for agents (software) that call Web APIs but I do not want to require/prompt for client certificates for regular browser based users. I have enabled HTTPS/client certificate support the following way: var host = new WebHostBuilder() .UseKestrel(options => { HttpsConnectionFilterOptions httpsoptions = new

Posting form data to MVC Core API

落花浮王杯 提交于 2019-12-03 11:57:55
I would like to post data to my API using AJAX but I'm having issues. I'm using Fiddler to test my API and I'm able to post JSON correctly but when posting a name/value urlencoded string I get a 400 Bad Request with the response body being '{"":["The input was not valid."]}'. My debug window displays: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor:Information: Executing ObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.SerializableError'. The JSON being posted is: { "Name": "Test" } The form data being posted is: Name=Test This is the Controller and Action: [Route(

How can I get started with ASP.NET (5) Core and Castle Windsor for Dependency Injection?

风格不统一 提交于 2019-12-03 11:47:17
问题 Background: I've used Castle Windsor with Installers and Facilities according to the Castle Windsor tutorial with earlier versions of MVC (pre-6) and WebAPI. ASP.NET (5) Core has included some Dependency Injection support but I still haven't figured out exactly how to wire it up, and the few samples I have found look a lot different than how I've used it before (with the installers/facilities). Most examples predate ASP.NET (5) cores recent release and some seem to have outdated information.