asp.net-mvc-5

Attribute inheriting from AuthorizeAttribute not working

帅比萌擦擦* 提交于 2019-12-21 17:56:46
问题 I'm currently trying to implement security in a new ASP MVC 5 application, based on user roles. The goal is to prevent users from accessing certain controllers or controller methods if they don't have a certain role (or higher). Based on what I've read on the question so far, I created an attribute that inherits AuthorizeAttribute which looks like this (MyAppRole is an enum, btw) : [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]

Is User.Identity.GetUserId cached or does it fetch from the database every time?

牧云@^-^@ 提交于 2019-12-21 13:07:52
问题 I'm using ASP.Net MVC 5 and I'm calling this line all over my code string userId = User.Identity.GetUserId(); Does ASP.NET MVC go and fetch this from the table for each call, or does it get cached? 回答1: It seems that the id along with the username are cached when you login. I've used SQL Server Profiler and after logged in running User.Identity.GetUserId(); the identity system made no queries to the database. This is the query made on loggin: exec sp_executesql N'SELECT [UnionAll2].[C2] AS

How to move MVC 5 IdentityModels.cs into a separate assembly

白昼怎懂夜的黑 提交于 2019-12-21 13:05:49
问题 I wonder if someone ran into the issue that I am having with trying to move ApplicationUser into Models project (where all other models reside including the ones related to Users table). My test MVC 5 solution consists of a web project and two class libraries: one for data access layer (DAL) and the other for Models. I references AspNet.Identity.EntityFramework in all three projects. In my DAL class I implement Repository pattern and a UnitOfWork. UnitOfWork extends IdentityDbContext

Sharepoint 2013 MVC 5 provider-hosted app. Fails to authenticate on HttpPost using [SharePointContextFilter]

拟墨画扇 提交于 2019-12-21 12:37:18
问题 I have been banging my head for the past week unable to resolve some issues with proper authentication for sharepoint provider-hosted app. I am currently developing a sharepoint app for a company's Sharepoint online. I am using Visual Studio 2013. I deploy the app as a Cloud-service on the company's Windows Azure portal. Everything goes smooth up to the point when i need to make a HttpPost, then the app fails to authenticate. The design of the Conroller is as it follows:

UserManager Error - A second operation started on this context before a previous asynchronous operation completed

ⅰ亾dé卋堺 提交于 2019-12-21 07:38:57
问题 I am facing this issue with my asp.net MVC5 web application, using Identity v2.0.0.0, EF 6, Castle Windsor IOC Container, Microsoft SQL Server 2005 I am trying to get the current logged in User by using UserManagerExtensions,FindById() method but it is throwing an error "System.NotSupportedException : A second operation started on this context before a previous asynchronous operation completed. Use 'await' to ensure that any asynchronous operations have completed before calling another method

Rendering partial views with Razor in MVC5

↘锁芯ラ 提交于 2019-12-21 07:08:17
问题 I'm trying to get a partial view to render using Razor in MVC5. When I use @{ Html.RenderPartial("ViewName", model); } I get the parser error: Unexpected "{" after "@" character. Once inside the body of a code block (@if {}, @{}, etc.) you do not need to use "@{" to switch to code. When I remove the {} , i.e.: @Html.RenderPartial("ViewName", model); I get the compilation error Cannot implicitly convert type 'void' to 'object'. What am I doing wrong? 回答1: You haven't posted the context of that

Mapping User.Identity in .NET MVC app to active directory user

北战南征 提交于 2019-12-21 06:06:09
问题 I'm writing a .NET MVC 5 app which is on an intranet, uses Windows Authentication and needs to query Active Directory to see what groups are available and then check if a user is in that role. The source of group and user names will be active directory. I then need to check identity and membership using .NET Identity. I'm not sure what fields map to what. Fields of interest in AD seem to be: SamAccountName: I think this is the username that I get from User.Identity, but the docs say that this

Automatically switching to minified CSS & JS files in different environments

随声附和 提交于 2019-12-21 05:37:06
问题 I am using ASP.Net MVC 5 and also taking advantage of WebEssentials LESS and bundle features. WebEssentials is setup to create minified css and js files on save. This is a feature I want because I can monitor the output and it lowers the application startup time ( not using Asp.Net MVC bundles ). How can I automatically get my app to use the minified version of the files when it is deployed without having to manually change the file names? So, for example, from: <link href="somestyles.css" ..

ASP.NET MVC 5 Identity 2.0, Windows Auth, User model with role attribute

做~自己de王妃 提交于 2019-12-21 05:07:09
问题 I'm trying to create an MVC5 application that uses Windows Authentication but uses roles pulled from a User model. I've searched high and low for an example, but the only ones I can find are based on the old ASP.NET identity framework. Anyone care to point me in the right direction?! Thanks! 回答1: So I've figured out one approach to solving this problem. I created a custom Authorization Attribute that checks the User model for a role. using System.Linq; using System.Web; using System.Web.Mvc;

ASP.NET MVC 5 Identity 2.0, Windows Auth, User model with role attribute

天涯浪子 提交于 2019-12-21 05:07:02
问题 I'm trying to create an MVC5 application that uses Windows Authentication but uses roles pulled from a User model. I've searched high and low for an example, but the only ones I can find are based on the old ASP.NET identity framework. Anyone care to point me in the right direction?! Thanks! 回答1: So I've figured out one approach to solving this problem. I created a custom Authorization Attribute that checks the User model for a role. using System.Linq; using System.Web; using System.Web.Mvc;