asp.net-mvc-5

Nested layouts for MVC5

穿精又带淫゛_ 提交于 2019-12-03 11:35:54
问题 I've seen a few posts on this topic: Razor Nested Layouts with Cascading Sections MVC 3 - Nested layouts - sections don't render in Areas And it always seems to be problematic. However they are both pretty old so wondering if things have changed. Basically I have a master layout, and 3 different body templates based on what kind of page it is. For examples sake: _Layout.cshtml <html lang="en"> <head> </head> <body style="padding: 50px 0;"> <header class="navbar navbar-default navbar-fixed-top

Viewbag.Title error: One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?

落爺英雄遲暮 提交于 2019-12-03 11:31:37
I have an ASP.NET MVC 5 web application. In every .cshtml view file i get the following error for Viewbag : One or more types required to compile a dynamic expression cannot be found. Are you missing a reference? I have references to Microsoft.CSharp.dll and System.Core.dll. Here is my root web.config file: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <

How to integrate Autofac with WepApi 2 and Owin?

风流意气都作罢 提交于 2019-12-03 10:54:57
问题 I am using this package to integrate Autofac with my WebApi Owin application: https://www.nuget.org/packages/Autofac.WebApi2.Owin And following this post: http://alexmg.com/owin-support-for-the-web-api-2-and-mvc-5-integrations-in-autofac/ My code in Startup.cs looks like this: var config = new HttpConfiguration(); IContainer container = EngineContext.InitializeEngine(); var dependencyResolver = new AutofacWebApiDependencyResolver(container); config.DependencyResolver = dependencyResolver; app

'Microsoft.Owin.IOwinContext' does not contain a definition for 'GetUserManager' and no extension method?

安稳与你 提交于 2019-12-03 10:52:56
问题 The following code is copied from the Asp.Net Identity 2.0 sample. private ApplicationUserManager _userManager; public ApplicationUserManager UserManager { get { return // Error _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); } private set { _userManager = value; } } However it gets the following error? Error 3 'Microsoft.Owin.IOwinContext' does not contain a definition for 'GetUserManager' and no extension method 'GetUserManager' accepting a first

MapMvcAttributeRoutes: This method cannot be called during the application's pre-start initialization phase

前提是你 提交于 2019-12-03 10:23:33
I have a very simple test in a test project in a solution using ASP MVC V5 and attribute routing. Attribute routing and the MapMvcAttributeRoutes method are part of ASP MVC 5. [Test] public void HasRoutesInTable() { var routes = new RouteCollection(); routes.MapMvcAttributeRoutes(); Assert.That(routes.Count, Is.GreaterThan(0)); } This results in: System.InvalidOperationException : This method cannot be called during the applications pre-start initialization phase. Most of the answers to this error message involve configuring membership providers in the web.config file. This project has neither

Resolving IOwinContext in MVC5 application using Autofac

拈花ヽ惹草 提交于 2019-12-03 10:17:51
问题 I have trouble using MembershipReboot with the new ASP MVC5 template and Autofac . I have used the default MVC5 template to set up the site and then tried to wire up the MembershipReboot framework as a replacement for the ASP Identity framework that ships with the template. This issue I am having is trying to resolve an IOwinContext from the Autofac container. Here is my wiring in the Startup class (cut down to basics). This is the wiring used in the samples for the MembershipReboot Owin

ASP.NET Identity 2 UserManager get all users async

左心房为你撑大大i 提交于 2019-12-03 10:07:08
Can somebody tell if there is a way to get all users async in ASP.NET Identity 2? In the UserManager.Users there is nothing async or find all async or somwething like that There is no way to do this asynchronously with the UserManager class directly. You can either wrap it in your own asynchronous method: (this might be a bit evil) public async Task<IQueryable<User>> GetUsersAsync { return await Task.Run(() => { return userManager.Users(); } } Or use the ToListAsync extension method: public async Task<List<User>> GetUsersAsync() { using (var context = new YourContext()) { return await

Could not load file or assembly 'System.Web.Mvc' . How to use the correct reference?

落爺英雄遲暮 提交于 2019-12-03 10:01:27
I have an application built on ASP.NET web forms which also supports MVC 5. I included MVC 5 API controllers in my project for which I had to upgrade Json from version 4.5 to 7.0. After making those changes when I launched the application, I get the following error: Could not load file or assembly 'System.Web.Mvc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) I checked the reference for System.Web.Mvc . In the property dialog run time version is v4.0.30319 and version is 5.0.0.0 . In web.config

How to use Roles in user identity in MVC 5

大憨熊 提交于 2019-12-03 09:51:41
问题 I want to use asp.net useridentity in mvc 5, I do these steps: 1) create a mvc project. 2) create my own database and change the connectionstring in web.config form: to: 3) I run the project and create a new user to add related table to my database. 4) I wanted to add a role to a user after registration a user like this code in accountControler: public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser() { UserName = model

How to add claims in a mock ClaimsPrincipal

血红的双手。 提交于 2019-12-03 09:37:01
I am trying to unit test my controller code which gets the information from the ClaimsPrincipal.Current. In the controller code I public class HomeController { public ActionResult GetName() { return Content(ClaimsPrincipal.Current.FindFirst("name").Value); } } And I am trying to mock my ClaimsPrincipal with claims but I still don't have any mock value from the claim. // Arrange IList<Claim> claimCollection = new List<Claim> { new Claim("name", "John Doe") }; var identityMock = new Mock<ClaimsIdentity>(); identityMock.Setup(x => x.Claims).Returns(claimCollection); var cp = new Mock