asp.net-mvc-5

Using ASP.NET Identity for a Role Provider easily

白昼怎懂夜的黑 提交于 2019-12-01 05:12:23
问题 I just spent the last two days researching and implementing the new ASP.NET Identity system with my existing database. More on that here: Integrating ASP.NET Identity into Existing DbContext. Now, I have a working UserStore and RoleStore , but I can't seem to figure out how to leverage them in my ASP.NET MVC 5 application without writing what seems like colossal amounts of code like in all the Identity samples that confuse me. There's two things I want to achieve: 1) use cookies to maintain

Resolving 'No key Defined' errors while using OnModelCreating with ApplicationDbContext?

瘦欲@ 提交于 2019-12-01 04:44:36
I've been trying to create navigation properties for my collection types and I found this example of how one person accomplished it using OnModelCreating. I gave it a try in my MVC 5 application and I recieved this error when trying to update my database: One or more validation errors were detected during model generation: BlogEngine.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. BlogEngine.Models.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType. IdentityUserLogins:

Hide/Show Div on button click using Jquery

 ̄綄美尐妖づ 提交于 2019-12-01 04:42:42
问题 This is supposed to be my first Jquery code that I am writing. I have used this and many more examples to make the simplest jquery code to display Hello on Button Click(W3Schools worth mentioning). I am trying to show a div that contains the Hello in it on a button click. <div> <input type="button" id="btn" class="btn btn-default" value="click me"> </div> <div id="Create" style="visibility:hidden"> Hello </div> @section Scripts{ @Scripts.Render("~/bundles/jqueryval") <script type="text

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

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 04:22:26
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())); context.Identity.AddClaim(new Claim("profile", context.User.GetValue("profile").ToString())); } } };

StructureMap MVC 5 html.Action Issue

旧街凉风 提交于 2019-12-01 03:56:52
问题 I am trying to call an Action from my view using @Html.Action("ActionName","controllerName") . But my page fails to load with below error: A single instance of controller 'Web.Areas.Area1.Controllers.ActionController' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request. I am using structure map for Dependency injection. Please help me what am i missing. 回答1: You need to add x.For<

ASP.NET Identity - Forcing a re-login with security stamp

妖精的绣舞 提交于 2019-12-01 03:39:08
So from What is ASP.NET Identity's IUserSecurityStampStore<TUser> interface? we learn that ASP.NET Identity has a security stamp feature that is used to invalidate a users login cookie, and force them to re-login. In my MVC app, it is possible for admins to archive users. When arched, they should immediately be logged out and forced to log in again (which would then reject them since they're archived). How can I do this? I understand that the security stamp is the key. The default setup looks like this: app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType =

SignalR Fails with more than 2 connections

会有一股神秘感。 提交于 2019-12-01 03:15:40
问题 I have written a fairly simple chat application in SignalR. It seems if i connect with more than 2 tabs/browsers/devices the third will hang and never connect and eventually cause problems. Why can I only connect with 2 users? The third request goes through as soon as I disconnect one of the other 2. Doesn't matter if I use the same user or different users. I am using IIS on Windows 10, Asp.Net MVC5 with SignalR 2.2 It never calls the hub code, if I try to connect with a fourth client while

How to use Exception filters in MVC 5

一曲冷凌霜 提交于 2019-12-01 03:15:21
How i can implement Exception Filters in MVC5. I want to throw the exception to NLog and redirect the page to a default error page which displays "Something is gone wrong" I have a Filter class as follows using System; using System.Diagnostics; using System.Security.Policy; using System.Web.Mvc; using System.Web.Mvc.Filters; using System.Web.Routing; using System.Web.UI.WebControls; using Delivros.UI.Controllers; using Delivros.UI.Areas.User.ViewModel; using System.Web; namespace Delivros.UI.Filters { public class CustomAuthenticationFilter : IAuthenticationFilter { public void

Setting Result in the context of ChallengeAsync method in an authentication filter

僤鯓⒐⒋嵵緔 提交于 2019-12-01 02:41:38
问题 This question is related to the answer I have provided here. OP's comment got me thinking a bit. I suggested using a class implementing IHttpActionResult like this in the ChallengeAsync method of the authentication filter. public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken) { context.Result = new ResultWithChallenge(context.Result); return Task.FromResult(0); } public class ResultWithChallenge : IHttpActionResult { private readonly

Resolving 'No key Defined' errors while using OnModelCreating with ApplicationDbContext?

99封情书 提交于 2019-12-01 02:39:56
问题 I've been trying to create navigation properties for my collection types and I found this example of how one person accomplished it using OnModelCreating. I gave it a try in my MVC 5 application and I recieved this error when trying to update my database: One or more validation errors were detected during model generation: BlogEngine.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. BlogEngine.Models.IdentityUserRole: :