asp.net-mvc-5

Scaffolding controllers with repositories in Mvc5, EF6, VisualStudio 2013

对着背影说爱祢 提交于 2019-11-30 01:10:54
问题 In vs2012 I used to use Steve Sanderson's mvcScaffolding Package with this package I could scaffold Action Methods with unit tests and controllers with repositories and dependency injection. My question is simple. Is there a way to do so in vs2013? When I install the package in vs2013 I get the following errors: Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE At C:\dev\WebApplication2\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:50 char:9 + Set-DefaultScaffolder -Name

How to Extend Microsoft.AspNet.Identity.EntityFramework.IdentityRole

依然范特西╮ 提交于 2019-11-29 23:31:15
问题 I want to be able to extend the default implementation of IdentityRole to include fields like Description. It's easy enough to do this for IdentityUser because IdentityDbContext takes a generic parameter of type IdentityUser. However, IdentityDbContext doesn't allow you to do this for IdentityRole. How can I accomplish this? I know I can create a basic DbContext, and implement my own IUserStore, so that I can use my own role class, but I really don't want to have to do that. Any thoughts? 回答1

MVC 5 Remote Validation

こ雲淡風輕ζ 提交于 2019-11-29 23:04:01
I need to validate an input field value from user before the form is submitted. I have created an action in my custom controller and decorated the field with it: action name: CheckValue controller name: Validate [Remote("CheckValue", "Validate"), ErrorMessage="Value is not valid"] public string Value { get; set; } The problem is when I press submit, the form is being submitted and then the message Value is not valid is shown if the value entered by the user is not valid. How can I validate the value entered by user and prevent the form to be submitted if value is not valid, and display the

MVC - Mixed Auth - OWIN + Windows Auth

吃可爱长大的小学妹 提交于 2019-11-29 22:23:55
I need to have both windows authentication and owin (forms) authentication but i can't get it to work. Probably the best option is to have two sites that have different authentication methods. I found a project that does what i want: MVC5-MixedAuth . But it uses IISExpress and i can't get it to work with Local IIS. The error that occurs is: Request filtering is configured on the Web server to deny the request because the query string is too long. If i remove all my ConfigureAuth() method inside Startup.Auth.cs it doesn't throw the error but i can't login because it is needed to do

Enable CORS for Web Api 2 and OWIN token authentication

谁说胖子不能爱 提交于 2019-11-29 20:41:38
I have an ASP.NET MVC 5 webproject (localhost:81) that calls functions from my WebApi 2 project (localhost:82) using Knockoutjs, to make the communication between the two projects I enable CORS. Everything works so far until I tried to implement OWIN token authentication to the WebApi. To use the /token endpoint on the WebApi, I also need to enable CORS on the endpoint but after hours of trying and searching for solutions it is still now working and the api/token still results in: XMLHttpRequest cannot load http://localhost:82/token. No 'Access-Control-Allow-Origin' header is present on the

OWIN cookie authentication without ASP.NET Identity

此生再无相见时 提交于 2019-11-29 20:30:11
I'm new to ASP.NET MVC 5 and I'm finding very uncomfortable with Identity authentication + authorization framework. I know this is a new feature of the ASP.NET MVC framework, so I'd like to apply an alternative way to implement authentication in m y application. Is it possible? I read I could use the FormsAuthenticationModule . Is this a good alternative? How can I use it in a MVC 5 based application? I felt the same way when taking a look at Identity. It adds lots of unnecessary abstractions and does not suit with my case that I have legacy system which implemented customised authentication

Multiple RoutePrefixes per controller using MVC Attribute routing?

[亡魂溺海] 提交于 2019-11-29 20:07:52
问题 With the new MVC Attribute routing, I know you can assign multiple Route attributes to a single ActionResult , but I am looking for a way to do the same at the RoutePrefix level. I have a controller which, in every action, should be accessible by three routes: /Games/{Title}/Characters/{Route} /Books/{Title}/Characters/{Route} /Cinema/{Title}/Characters/{Route} I tried putting three individual RoutePrefix attributes, but I get the error Deuplace RoutePrefix attribute . If I try to use a comma

Unit Testing ASP.NET MVC5 App

冷暖自知 提交于 2019-11-29 19:53:59
I'm extending the ApplicationUser class by adding a new property (as shown in the tutorial Create an ASP.NET MVC 5 App with Facebook and Google OAuth2 and OpenID Sign-on (C#) ) public class ApplicationUser : IdentityUser { public DateTime BirthDate { get; set; } } Now I want to create a Unit Test to verify that my AccountController is correctly saving the BirthDate. I've created an in-memory user store named TestUserStore [TestMethod] public void Register() { // Arrange var userManager = new UserManager<ApplicationUser>(new TestUserStore<ApplicationUser>()); var controller = new

No ASP.NET MVC 5 Web Application Template on VS 2012?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 19:48:41
I'm using Visual Studio 2012 and have just installed "Microsoft ASP.NET and Web Frameworks 2013.1 - Visual Studio" . As expected, it added the option to create an "ASP.NET MVC 5 Empty Project" . The thing is, I see no way of jump-starting an already functional "base application" as I had when I was using MVC 4 (e.g. "Asp.NET MVC 4 Web Application" ). I only see an empty template. I've seen answers such as: How can I add the MVC 5 project template to VS 2012? Create and Run MVC 5 Project in VS 2012 Direct download link to ASP.NET MVC 5 for VS 2012 And found this article on the matter. This is

How to sync model after using Code First from Database using Entity Framework 6.1 and MVC 5?

霸气de小男生 提交于 2019-11-29 19:42:32
Assumptions Using EF 6.1, MVC 5, VS 2013, C# I have an existing database model designed in Toad DM for SQL Server and it's very important keep it always updated Steps and Notes Using ADO.NET Entity Data Model I chose Code First from Database ( new feature in EF 6.1 ) to generate the models. Note: Model classes and DbContext class generated successfuly but NO .edmx or .tt file was generated . Next I added a new scaffold item: MVC 5 Controllers with views, using Entity Framework. Note: Success, controllers and views generated Question From now on I don't want to use Code First to update my