asp.net-mvc-5

Why isn't [Authorize(Roles = “Admin”)] working in MVC 5 RTM with ASP.NET Identity?

一笑奈何 提交于 2019-11-30 03:39:51
Does [Authorize(Roles = "Admin")] work out of the box in MVC 5 RTM with ASP.NET Identity ? I've had no luck. Note that [Authorize] and [Authorize(Users = "AdminUser")] work just fine, and the AspNetUserRoles and AspNetRoles tables are populated as I would expect them to be, establishing a relationship between the AdminUser user and the Admin role. This issue seems specific to roles. The user may need to be re-authenticated to receive new claims that include membership in the Admin role. Since MVC 5 uses ASP.NET Identity out of the box, and by default in MVC 5, ASP.NET Identity stores claims

How to use ASP.NET Identity without a database

 ̄綄美尐妖づ 提交于 2019-11-30 03:39:30
I am trying to implement custom authentication using the new ASP.NET Identity in an MVC 5 project. I have a single username and password that I want to use to restrict which pages of the website the user can see via [Authorize] tags on controllers and views. (Easy) I am migrating from a FormsAuthentication model whereby this was as simple as putting the credentials in the web.config. Because I only have a single username and password I don't want to use a database as the UserStore , instead I want ASP.NET Identity to retrieve the username and password from a custom configurationsection in the

Identity 2.1 - UserId not found but was working before

家住魔仙堡 提交于 2019-11-30 02:51:59
问题 This code worked before numerous times but after adding in a couple new properties for a user in Identity 2.1 it has ceased to work suddenly. I am getting a UserId not found error, despite there being a value visible in the debugger for UserId. Anyone have an idea on why this has suddenly happened? It's very frustrating to see the least. Here's code: (Controller) // POST: /Account/Register [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Register

How to add claims during user registration

懵懂的女人 提交于 2019-11-30 02:47:19
问题 I'm using ASP.NET MVC 5 project with identity 2.1.0 and VS2013 U4. I want to add claims to user during registration in order to be stored in db. These claims represent user custom properties. As I created a web page for administrator to create/edit/delete users, I'm still using create method from AccountController to create a user, but I don't want to login that user. How can I add those claims to the user ? 回答1: You probably already have a UserManager class. You can use that one to create

Update Visual Studio 2017 MVC View Scaffolding to Bootstrap 4

邮差的信 提交于 2019-11-30 02:40:15
问题 I've just updated my Visual Studio 2017 ASP.NET MVC 5 application from Bootstrap v3 to v4. I'm finding when I add a new edit partial view using scaffolding, it is still using the Bootstrap v3 CSS class names for the form. Is there a way to update the scaffolding to use BS v4? Edit There seems to be some confusion about what I'm talking about. In Visual Studio 2017, in an MVC project, in Solution Explorer, right click the Views folder > Add > View... > MVC 5 View > Click Add . This brings up

Setting the redirect_uri in Asp.Net Identity

杀马特。学长 韩版系。学妹 提交于 2019-11-30 02:03:57
I am trying to set the redirect_uri for the facebook login with Asp.Net Identity. However, the GetExternalLogin REST method in the AccountController is only triggered if the redirect_uri is '/'. If I add anything else it does not trigger GetExternalLogin , the browser only shows error: invalid_request . However the url contains the redirected parameter as it should e.g. if I add the redirect_uri as http://localhost:25432/testing the response URL looks like this: http://localhost:25432/api/Account/ExternalLogin?provider=Facebook&response_type=token&client_id=self&redirect_uri=http%3A%2F

MVC-6 vs MVC-5 BearerAuthentication in Web API

旧时模样 提交于 2019-11-30 01:59:24
问题 I have a Web API project that use UseJwtBearerAuthentication to my identity server. Config method in startup looks like this: public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseJwtBearerAuthentication(options => { options.AutomaticAuthentication = true; options.Authority = "http://localhost:54540/"; options.Audience = "http://localhost:54540/"; }); // Configure the HTTP request pipeline. app.UseStaticFiles(); // Add MVC to the request pipeline. app.UseMvc(); }

Get all role names in ASP.NET MVC5 Identity system

只谈情不闲聊 提交于 2019-11-30 01:50:04
MVC5 uses a new Identity System. How can I get all role names? I try do access it via IdentityStore but without success. I've found that you can use the DbContext via the IdentityStore instance and use the well-known method .Set<T>() . This works for me: var identityStore = new IdentityStore(); foreach (var role in identityStore.DbContext.Set<Role>()) { Debug.WriteLine(role.Name); } joe This is a bit more intuitive var roles = dbContext.Roles.OrderBy(x => x.Name); There's currently no way to do enumeration style methods via the identity interfaces, that will be coming in a future update

MVC5 hangs on MapSignalR when reconnecting after AppPool cycles

孤者浪人 提交于 2019-11-30 01:19:12
问题 I have the following code in my Startup.SignalR.cs: using Microsoft.AspNet.SignalR; using Owin; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Admin { public partial class Startup { public void ConfigureSignalR(IAppBuilder app) { var Config = new HubConfiguration() { EnableDetailedErrors = false, Resolver = new DefaultDependencyResolver() }; #if DEBUG Config.EnableDetailedErrors = true; #endif // Any connection or

What is the XsrfKey used for and should I set the XsrfId to something else?

家住魔仙堡 提交于 2019-11-30 01:18:07
问题 In my MVC 5 web app I have this (in AccountController.cs): // Used for XSRF protection when adding external sign ins private const string XsrfKey = "XsrfId"; and public string SocialAccountProvider { get; set; } public string RedirectUri { get; set; } public string UserId { get; set; } public override void ExecuteResult(ControllerContext context) { var properties = new AuthenticationProperties { RedirectUri = RedirectUri }; if (UserId != null) { properties.Dictionary[XsrfKey] = UserId; }