asp.net-mvc-5

Why MVC 5 Owin Oauth is not hitting /Account/ExternalLoginCallback action

北城余情 提交于 2019-12-07 00:55:47
问题 I am new to MVC 5 authentication. Currently I tried Google Authorization using Owin The code in startup.Auth.cs var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions { ClientId = "Client-id", ClientSecret = "secret-key", CallbackPath = new PathString("/Account/ExternalLoginCallback"), Provider = new GoogleOAuth2AuthenticationProvider() { OnAuthenticated = async context => { context.Identity.AddClaim(new Claim("picture", context.User.GetValue("picture").ToString()));

User Role/Authorization doesn't work in ASP.NET Identity

不羁的心 提交于 2019-12-07 00:28:28
have this (model builder) code on our DbContext.cs base.OnModelCreating(modelBuilder); modelBuilder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId); modelBuilder.Entity<IdentityRole>().HasKey<string>(r => r.Id); modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId }); modelBuilder.Entity<ApplicationUser>().ToTable("ApplicationUser"); Everything works fine except for Authorization/User Roles . After checking all tables I noticed that IdentityUserRoles table creates 4 columns: RoleId, UserId, IdentityRole_Id and ApplicationUser_Id. I found out that, IdentityRole

When should I be using AutoMapper and when not

时光怂恿深爱的人放手 提交于 2019-12-07 00:00:51
问题 I have a Data layer which holds my EF6 DbFirst edmx, repositories, and AutoMappings. I also have a Model layer with a Poco for each auto generated entity in my Data layer. The properties pretty much match exactly except for a few name changes. AutoMapper is installed to my DataLayer only and this is where I set all of my mappings in a config file. At this point I have a mapping from each DataLayer entity to each ModelLayer entity and each ModelLayer entity to each DataLayer entity. Any name

GetExternalLoginInfoAsync always return null when i trying login using Facebook or Google

送分小仙女□ 提交于 2019-12-06 23:36:38
问题 I have a problem with OWIN Authentication. I always receive null value from GetExternalLoginInfoAsync() when I trying log in using Facebook or Google. BUT there is some mystical case.. When I open Fiddler. I get correct data using this method. I can't get the reason var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); Thanks in advance!! 回答1: I have solved my problem by adding this code context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;

Asp.Net MVC Unique id per request

我是研究僧i 提交于 2019-12-06 19:20:45
问题 In our MVC 5 site, no session, we need to get/generate a unique ID per request. THhis will be used as an ID for logging all activity in the request. Is there a way to assign/get a value to a Request to enable this? 回答1: Add it to the request item collection odetocode.com/articles/111.aspx Guid.NewGuid() Will generate a unique id. http://msdn.microsoft.com/en-us/library/system.guid.newguid(v=vs.110).aspx 回答2: Here's some extension methods that I created for this purpose: public static Guid

Set default for DisplayFormatAttribute.ConvertEmptyStringToNull to false

谁说我不能喝 提交于 2019-12-06 18:28:18
问题 I just converted a bunch of web services to Web API2. Now my C# code blows up when the browser sends an empty string and it enters my code converted to null. I have researched global solutions and none that I have found work for me. I can of course set it manually for every string in all my Web API models, but I have scores of models so would prefer a global solution. Been here: string.empty converted to null when passing JSON object to MVC Controller and other pages and attempted to

MVC5 and Bootstrap3: Html.EditorFor wrong class? How to change?

本小妞迷上赌 提交于 2019-12-06 17:10:50
问题 I just noticed that MVC 5 is using a different class for input fields when using EditorFor. I think its from a lower version of bootstrap, so the current class doesn't really add up. I'm talking about this: <div class="form-group"> @Html.LabelFor(model => model.Contact.CellphoneNo, new { @class = "control-label col-md-4"}) <div class="col-md-8"> @Html.EditorFor(model => model.Contact.CellphoneNo) @Html.ValidationMessageFor(model => model.Contact.CellphoneNo) </div> </div> Which results to

Creating a matrix of checkboxes which supports post back in ASP.NET MVC

眉间皱痕 提交于 2019-12-06 16:31:20
I'm trying to think of a way to manage the selection of a matrix of values via view models in MVC 5. I have a list of companies and a list of roles. The roles are the same for each company. What I want is to output a matrix of companies/roles with a checkbox for each combination. This allows the user to select which role the person will have for each company. I can render the output with nested foreach loops but I can't help but think there's a better way to achieve this with MVC and Editor Templates. Below is a crude example of the layout. So every company is output as a column and every role

Decimal symbol issue in MVC, C#?

半腔热情 提交于 2019-12-06 16:02:20
I'm using MVC 5.0 I set the culture in config: <system.web> <globalization uiCulture="fa-IR" culture="fa-IR" /> </system.web> I have a model as the following: public class MyModel { [DisplayName("NbatPersent")] [Range(0, 100)] public double NbatPersent{ get; set; } } MVC shows the NbatPersent value in View like 22/5 and when I wanna submit form the form validator alert me The field NbatPersent must be a number. . It can't convert 22/5 to 22.5 It will be OK if I enter 22.5 but if the property has a value it convert . to / How can I convert all numeric properties' culture to en-US to show value

Extending ASP.NET MVC 5 Identity with another object

陌路散爱 提交于 2019-12-06 15:45:26
问题 I'm currently using Fluent API in which I cannot find many resources regarding extending the Identity model with another object. Here I have my object called ApplicationUser: public class ApplicationUser : IdentityUser { public virtual Staff Staff { get; set; } public int StaffId { get; set; } } In which I'd like to map it to my current Staff object: public class Staff { public int StaffId { get; set; } public string DisplayName { get; set; } public string FirstName { get; set; } public