asp.net-core-mvc

.NET Core using Azure B2C Authentication, looking for the User Attributes such as @User.Identity.UserID after logged in

不羁岁月 提交于 2020-01-25 10:19:07
问题 I'm using .NET Core, with Azure B2C Authentication. On the project I'm developing, I can find the @User.Identity.Name, but I cant find the C# object name/path for the other "built in" User Attributes such as @User.Identity.UserID , @User.Identity.firstTimeLogging, @User.Identity.firstName. These Attribute are enabled in Azure AD. Thank you for your time. 回答1: You can access custom claims by including them in the token sent to the app or by querying the Azure AD Graph API (not the Microsoft

BindAttribute doesn't seem to work in ASP.Net MVC Core (2.0.8)

会有一股神秘感。 提交于 2020-01-25 09:12:28
问题 I'm trying to use the Bind attribute to include only specific properties in my model. I know I can use a view model and only specify the properties I need, but I can't use that because the code has to run through some static code analysis that triggers an error if the Bind attribute is not present, and I can't change that rule (it's not controlled by me). This is what I tried. Model: [Bind("One")] public class SomeModel { public int One { get; set; } public int Two { get; set; } } Controller

.NET Core MultiTenancy causing Area routing in ajax to not work

Deadly 提交于 2020-01-25 08:22:11
问题 I am using the Finbuckle Multitenant Library and I have encountered an issue with routing to Areas in my Views when I try to do ajax calls. private static void ConfigRoutes(Microsoft.AspNetCore.Routing.IRouteBuilder routes) { routes.MapRoute("Login", "Login", new { controller = "Account", action = "Login", area="Identity"}); routes.MapRoute("Default", "{__tenant__=}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute("AreaGeneric", "{area:exists}/{controller=Home}/{action=Index}/{id?}")

Cookie not expiring per StartUp.cs settings

早过忘川 提交于 2020-01-25 07:26:10
问题 I have tried a plethora of solutions over the course of 2 days and still have not been able to get this to work. What I want is for a user cookie to expire after a set amount of time E.g. User A logs in and goes to home page, User A goes for a lunch break. User A comes back and clicks on the nav bar and gets redirected to the login page. I have tried everything from AddAuthentication() , AddSession() and AddCookie() options all having an ExpireTimeSpan and Cookie.Expiration of my choosing.

Azure Monitor / Application Insights not showing stack trace for errors

断了今生、忘了曾经 提交于 2020-01-25 06:55:28
问题 I've got an ASP .Net Core 3.0 Web API hosted on Azure App Service. I'm am trying to figure out why it's throwing a 500 Internal Server Error in one of the controller action methods. I've got Application Insights set up, and I can see on the "Failures" page on Azure Portal that there are a number of 500 exceptions. However, I cannot see a stack trace for them. Is there something I need to do to turn on stack trace reporting in Application Insights or Azure Monitor. P.S. Even when my API was on

Session State being cleared or lost after one AJAX call to .NET CORE 2.1 application hosted on IIS server

ε祈祈猫儿з 提交于 2020-01-25 06:51:08
问题 I have run into this problem for which I have been scratching my head for hours now. The problem: The Session State that I create on Login gets mysteriously cleared or lost after calling an API controller which is also in .NET CORE 2.1. This happens when I call a API method that looks like: [Authorize(Policy = "AdminViewPolicy")] [HttpGet("GetAllUsersId")] public IActionResult GetAllUsersId() { var user = _userService.GetAllUsersId(); return Ok(new { data = user }); } The roles and other

Update label on post using Razor Pages

时间秒杀一切 提交于 2020-01-25 03:05:50
问题 I'm trying to update a label on an http post within a Razor Page. I have a public property called Confirmation as follows: public string Confirmation { get; set; } Then I have my post method: public async Task<IActionResult> OnPostAsync() { //some conditional logic here Confirmation = "Settings saved!"; return Page(); } In my view I have: <label asp-for="Confirmation"></label> However, this renders as: <label for="Confirmation">Confirmation</label> I don't want the word "Confirmation" showing

How to use Attributes Property in HtmlTargetElement (Tag Helpers) to target one tag or another?

痴心易碎 提交于 2020-01-25 00:23:26
问题 I'm wrestling with understanding how to show the string assigned to Attributes in the HtmlTargetElement class attribute works. I have a couple questions that I think will highlight my issue and understanding. Let's say we want activate an Html Element only when make starts with gm and there is any model. I think there is a way to do this with a single class attribute (not multiple ones). I'm trying the following but it is just a SWAG and does not work. I'd appreciate tips so I can understand

is Bind[(exclude ..)] removed from ASP Core?

半城伤御伤魂 提交于 2020-01-25 00:23:13
问题 I am trying to exclude some properties from binding when getting values from View I am using at the action level : Bind exclude as the following : I need this property to sent to the view (as readonly) but not allowing the user to update the value or even hacker try to inject value .... the question:is exclude no longer available in ASP MVC Core ? is there any other way ? again I know I can exclude the Property at Model level (using neverbind) but I want only send the value to the view , but

What am I missing that causes [TempData] decorated property not to retain value from get to post?

半世苍凉 提交于 2020-01-25 00:23:12
问题 My understanding of the TempData attribute in asp.net core is that it marks a model property as needing to persist in value between posts and gets of same page (and possibly wider lifetime than that, but at least that). My issue is that any property I have marked as TempData and set successfully in OnGetAsync has been reset to null by the time user posts back the form. Why might that be? Or have I misunderstood what TempData is supposed to do as an attribute? If I have, what's the best way to