asp.net-mvc-5

ASP.NET MVC : Context type not found in assembly

谁都会走 提交于 2019-12-08 03:57:28
This is my first asp.net mvc project. I used EF code first approach and created a separate class library to write my model and context. I also referenced the class library in mvc project. But now after creating few more new models when I try to enable migration, it gives me an error. I also tried all the possible solutions mentioned here : No context type found in the assembly. ASP.NET MVC4 Still problem remains the same. Am I missing something? This is code for Context Class: using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Text; using

Creating a ViewModel from two EF Models in ASP.Net MVC5

余生颓废 提交于 2019-12-08 03:24:18
问题 I have been searching around and really can not find a decent answer on how to build a ViewModel and then fill that with the data from my EF model. The two EF models I want to push into a single ViewModel are: public class Section { [DatabaseGenerated(DatabaseGeneratedOption.Identity), HiddenInput] public Int16 ID { get; set; } [HiddenInput] public Int64? LogoFileID { get; set; } [Required, MaxLength(250), Column(TypeName = "varchar"), DisplayName("Route Name")] public string RouteName { get;

“The ConnectionString property has not been initialized.” - but only when publishing

泄露秘密 提交于 2019-12-08 02:47:46
问题 I have an MVC5 / EF6.1 website that runs perfectly on my development machine using LocalDb. However, when I publish this to an Azure Website with an Azure SQL Database, I get the following error when doing any database interaction: The ConnectionString property has not been initialized. I've searched all over and can't find the reason that this happens on Azure. The first file the stack trace points to is IdentityModels.cs:45 That contains the following: public class ApplicationDbContext :

Types not resolving with Unity [MVC 5]

限于喜欢 提交于 2019-12-08 02:47:34
问题 I am using ASP.NET MVC 5 with Unity 3 and Unity bootstrapper for ASP.NET MVC. In the UnityConfig.cs file, I registered the following type in the RegisterTypes method: public static void RegisterTypes(IUnityContainer container) { container.RegisterType<IProjectRepository, ProjectRepository>(); } In an MVC controller, I am resolving like this: UnityContainer container = new UnityContainer(); public ActionResult List() { var projectRepository = container.Resolve<IProjectRepository>(); return

Adding soft delete to Identity users table

社会主义新天地 提交于 2019-12-08 02:23:33
问题 I've added a deleted at column to my Users table but obviously registering new users method provided by Identity framework still sees these users in the database, is there a way of telling it to ignore a certain column? Registration // this needs to ignore any DeletedAt where not null var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { ... } Logging in // this needs to ignore any DeletedAt where not null result = await SignInManager.PasswordSignInAsync(

RouteValueDictionary ignores empty values

耗尽温柔 提交于 2019-12-08 02:14:43
问题 I have few empty route values I want in the query string: var routeValues = new RouteValueDictionary(); routeValues.Add("one", ""); routeValues.Add("two", null); routeValues.Add("three", string.Empty); If I then pass it to UrlHelper.RouteUrl() it ignores all the values and the generated query string is empty. However, urls like /?one=&two=&three= are perfectly valid. How can I do that? 回答1: This behavior is built into the default Route class. It calls into the ParsedRoute.Bind() method where

Token based authentication for both Web App and Web API using Azure AD B2C

ぃ、小莉子 提交于 2019-12-08 01:49:08
问题 Scenario: Both Web application and Web API need to be authenticated and protected from the server side. Requirement: Web application is serving the contents for the browser and browser should be calling Web API directly (i.e. Browser to API). Question: Is it possible to authenticate both Web APP and the API using tokens? Any sample code or clear direction would be highly appreciated. Normally web applications are authenticated using cookies and APIs are authenticated using tokens.There are

Compiler Errors after updating Microsoft.Aspnet.Identity in MVC5

笑着哭i 提交于 2019-12-08 01:45:15
问题 Using the Vs2013 preview, i created a c# webapp selecting MVC and WebAPI from the dialog. It compiled ok. If i update the references from the nuget package manager to the beta2 versions (include Prerelease), it then fails to compile. I get 21 errors, located in the AccountController.cs and the IdentityConfig.cs. I tried updateing to the latest nightly libraries which gave the same errors. Appreciate preview code is just that so start again from the template. Was wondering if anyone knew which

ASP.NET MVC GetFullHtmlFieldId not returing valid id

假装没事ソ 提交于 2019-12-08 01:40:51
问题 I have taken a look at but it did not help me out GetFullHtmlFieldId returning incorrect id attribute value ASP.NET GetFullHtmlFieldId not returning valid id Problem Basically I have the following problem: I have a custom validation attribute which requires to get the fieldId of the control public class MyValidationAttribute : ValidationAttribute, IClientValidatable { //...... Collapsed code public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata,

Implement Unity MVC 5 dependency injection in ActionFilter

一个人想着一个人 提交于 2019-12-08 01:39:17
问题 I'm trying to inject this user service via Unity (mvc5) in an actionfilter but it is null. How can I implement this? public class TestFilter : ActionFilterAttribute { // this is always null [Dependency] public IUserService UserService { get; set; } // other members } 回答1: You must register UnityFilterAttributeFilterProvider as a FilterProvider first. Modify the App_Start > UnityMvcActivator 's Start method like this: public static void Start() { var container = UnityConfig