Questions tagged [asp.net-mvc-5]
ASP.NET MVC 5 is the fifth major version of the ASP.NET Model-View-Controller platform for web applications.
asp.net-mvc-5
15,663
questions
402
votes
22
answers
127k
views
OwinStartup not firing
I had the OwinStartup configuration code working perfectly and then it stopped working. Unfortunately I'm not sure exactly what I did to get it to stop working and am having a really hard time ...
273
votes
20
answers
453k
views
HTTP Error 500.19 and error code : 0x80070021
I have a simple webAPI build by Visual Studio 2013. It works well when I run it from VS13 but when I copy the project in local IIS it gives me the following error.
HTTP Error 500.19 - Internal Server ...
258
votes
11
answers
361k
views
ASP.NET MVC 5 - Identity. How to get current ApplicationUser
I have an Article entity in my project which has the ApplicationUser property named Author. How can I get the full object of currently logged ApplicationUser? While creating a new article, I have to ...
221
votes
26
answers
490k
views
'router-outlet' is not a known element
I have a mvc 5 project with a angular frontend . I wanted to add routing as described in this tutorial https://angular.io/guide/router. So in my _Layout.cshtml I added a
<base href="/">
and ...
218
votes
8
answers
187k
views
How to add MVC5 to Visual Studio 2013?
I'm starting a new project, and would like to give a try to MVC 5 (I have built a web app using MVC 4 before).
In Visual Studio 2013, I click the New Project and navigate to Visual C# > Web > Visual ...
218
votes
3
answers
79k
views
What is ASP.NET Identity's IUserSecurityStampStore<TUser> interface?
Looking at ASP.NET Identity (new membership implementation in ASP.NET), I came across this interface when implementing my own UserStore:
//Microsoft.AspNet.Identity.Core.dll
namespace Microsoft....
218
votes
4
answers
160k
views
ASP.NET Identity DbContext confusion
A default MVC 5 App comes with this piece of code in IdentityModels.cs - this piece of code is for all the ASP.NET Identity operations for the default templates:
public class ApplicationDbContext : ...
218
votes
3
answers
81k
views
Do I need a Global.asax.cs file at all if I'm using an OWIN Startup.cs class and move all configuration there?
Let's say for example in a brand new ASP.NET MVC 5 application made from the MVC with Individual Accounts template, if I delete the Global.asax.cs class and move it's configuration code to Startup.cs ...
189
votes
15
answers
106k
views
Unauthorised webapi call returning login page rather than 401
How do I configure my mvc/webapi project so that a webapi method called from a razor view doesn't return the loginpage when its unauthorised?
Its a MVC5 application which also has WebApi controllers ...
162
votes
9
answers
226k
views
How to get current user, and how to use User class in MVC5?
How can I get the id of the currently logged in user in MVC 5? I tried the StackOverflow suggestions, but they seem to be not for MVC 5.
Also, what is the MVC 5 best practice of assigning stuff to ...
160
votes
12
answers
177k
views
GlobalConfiguration.Configure() not present after Web API 2 and .NET 4.5.1 migration
I recently started following this guide to migrate my project to .NET 4.5.1 and Web Api 2.
The very first thing MS developer Rick Anderson asks you to do is change:
WebApiConfig.Register(...
158
votes
1
answer
109k
views
How to add Web API to an existing ASP.NET MVC (5) Web Application project?
Assuming you forgot to tick the Web API checkbox (add it to the project) when making a new MVC (5) project, what do you need to do add Web API and get it working?
There are a bunch of migration ...
139
votes
6
answers
125k
views
How to extend available properties of User.Identity
I'm using MVC5 Identity 2.0 for users to log into my website, where the authentication details are stored in an SQL database. Asp.net Identity has been implemented in a standard way as can be found in ...
137
votes
4
answers
172k
views
How to implement oauth2 server in ASP.NET MVC 5 and WEB API 2 [closed]
First I'll sketch my project:
For my internship I need to add functionality to an existing system. A 3rd party client must be able to access data from AX Webservices once he is authorised by the user ...
134
votes
12
answers
237k
views
MVC 5 Access Claims Identity User Data
I am developing an MVC 5 web application using Entity Framework 5 Database First approach. I am using OWIN for the authentication of Users. Below shows my Login method within my Account Controller.
...
132
votes
26
answers
100k
views
Visual Studio 2013 IntelliSense stops working for ASP.NET MVC5 Controllers
I am facing a weird problem in my Visual Studio 2013 ASP.NET MVC 5 project. All of a sudden, the IntelliSense in the Controller classes of the MVC 5 project are not working at all.
I have other class ...
120
votes
3
answers
51k
views
What is the advantage of using async with MVC5?
What is the difference between:
public ActionResult Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
IdentityResult result = IdentityManager.Authentication....
116
votes
6
answers
126k
views
EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType
I am working with Entity Framework Code First and MVC 5. When I created my application with Individual User Accounts Authentication I was given an Account controller and along with it all the required ...
115
votes
29
answers
263k
views
The type or namespace name 'System' could not be found
I have the following errors (and more) in all my views (*.cshtml) when opening my project in Visual Studio 2015 Professional.
Error CS0246 The type or namespace name 'System' could not be found (...
114
votes
11
answers
162k
views
How do I install ASP.NET MVC 5 in Visual Studio 2012?
Is there a way to install ASP.NET MVC 5 in Visual Studio 2012?
I've tried using NuGet (http://www.nuget.org/packages/Microsoft.AspNet.Mvc). But I think that it should come as a Visual Studio ...
109
votes
6
answers
143k
views
How to get JSON object from Razor Model object in javascript
In viewmodel object, below is the property:
public IList<CollegeInformationDTO> CollegeInformationlist { get; set; }
In VIEW, javascript is as follow:
var obj = JSON.stringify('@Model....
109
votes
4
answers
176k
views
How to set Default Controller in asp.net MVC 4 & MVC 5
How do I set Default Controller for my ASP.NET MVC 4 project without making it HomeController?
How should I setup a default Area when the application starts?
105
votes
11
answers
141k
views
ASP.NET Identity change password
I need ability to change password for user by admin. So, admin should not enter a current password of user, he should have ability to set a new password. I look at ChangePasswordAsync method, but this ...
98
votes
7
answers
68k
views
MVC 5 Seed Users and Roles
I have been playing about with the new MVC 5, I have a few models, controller and views setup using code first migrations.
My question is how do I seed users and roles? I currently seed some ...
94
votes
7
answers
137k
views
How to get 'System.Web.Http, Version=5.2.3.0?
I just created an MVC5 project and added several packages from nuget, but then when I compiled the project, i got this error. It seems one of the packages really depends on system.web.http version 5....
93
votes
3
answers
60k
views
Async PartialView causes "HttpServerUtility.Execute blocked..." exception
I have a partial view that tries to retrieve a IEnumerable<Post> from the database using async...
Method
public static class PostService
{
public static int PostsPerPage = 50;
public ...
91
votes
11
answers
152k
views
Creating Roles in Asp.net Identity MVC 5
There is very little documentation about using the new Asp.net Identity Security Framework.
I have pieced together what I could to try and create a new Role and add a User to it. I tried the ...
90
votes
22
answers
138k
views
The model backing the 'ApplicationDbContext' context has changed since the database was created
First of all, I have not seen this error anywhere else and I guess it's not a replicate so please read the whole situation first.
Everything was working just fine then I tried to update one of my ...
89
votes
21
answers
89k
views
IntelliSense in Razor files (.cshtml) stopped working
Intellisense does not work in razor files:
In my web.conifg file (in the Views folder) is apparently correct:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<...
89
votes
5
answers
68k
views
What / why is Roslyn "needed" in /bin folder of Asp.Net
There are a bunch of related questions on this, though most of the answers define Roslyn and/or provide a "fix" to some issue (exe, with hosting providers, etc.)
What I can't seem to track down is ...
88
votes
9
answers
60k
views
ASP.NET Identity with EF Database First MVC5
Is it possible to use the new Asp.net Identity with Database First and EDMX? Or only with code first?
Here's what I did:
1) I made a new MVC5 Project and had the new Identity create the new User and ...
85
votes
24
answers
91k
views
Asp.NET Identity 2 giving "Invalid Token" error
I'm using Asp.Net-Identity-2 and I'm trying to verify email verification code using the below method. But I am getting an "Invalid Token" error message.
My Application's User Manager is like this:
...
83
votes
2
answers
14k
views
Post an HTML Table to ADO.NET DataTable
I have a HTML table as below in my View:
<table id="tblCurrentYear">
<tr>
<td>Leave Type</td>
<td>Leave Taken</td>
<td>Leave ...
82
votes
6
answers
113k
views
How can I implement a theme from bootswatch or wrapbootstrap in an MVC 5 project?
I am about to create a new ASP.Net MVC5 web application. I would like to use a theme from bootswatch or wrapbootstrap in the application, but cannot find a set of instructions on how to do this.
80
votes
5
answers
55k
views
MVC5 Claims version of the Authorize attribute
I'm trying out some of the new stuff in VS2013 RC with MVC5 and the new OWIN authentication middleware.
So, I'm used to using the [Authorize] attribute to limit actions by role but I'm trying to use ...
79
votes
7
answers
40k
views
Error renaming ASP.NET MVC project
I have copied a previous project and renamed it. Once I had successfully renamed all the name spaces and it build correctly. I got the following error when I ran the application:
The following errors ...
78
votes
12
answers
115k
views
Updating user data - ASP.NET Identity
I've added custom fields to the ApplicationUser class
I've also created a form through which the user can enter/edit the fields.
However for some reason I'm not able to update the fields in the ...
78
votes
21
answers
50k
views
New Asp.Net MVC5 project produces an infinite loop to login page
I am creating a brand new projet with Visual Studio 2013, I choose Asp.Net MVC and the framework 4.5.1 The project is created, then, I do nothing else than F5 to start the default web page. ...
76
votes
11
answers
66k
views
Object reference not set to an instance of an object in _Layout.cshtml after updated packages
The project was running fine until I updated all NuGet packages via
NuGet Manager (I was trying to get the latest OWIN packages).
This error is in the _Layout.cshtml and I have not touched it at all.
...
74
votes
9
answers
49k
views
No OWIN authentication manager is associated with the request
After trying to enable owin & AspNet Identity to my Web Api project (in VS 2013 + .Net 4.5.1) I get the following error in each valid or unvalid(request to none exist controller) requests :
<...
74
votes
1
answer
51k
views
SignInManager,what it is and how,when to use?
I am exploring SignInManager class. But the information given on MSDN is very useless. It only tells what are the methods and properties provided.
What I am looking for is,
What is SignInManager?
How ...
74
votes
1
answer
2k
views
ASP.NET MVC OutputCacheAttribute with external cache providers
After switching an ASP.NET MVC 5 application to Azure Redis (Microsoft.Web.RedisOutputCacheProvider Nuget package) I was surprised to see that OutputCacheAttribute when set to use either ...
72
votes
8
answers
53k
views
MVC5, Web API 2 and Ninject
I have created a new MVC5 project with Web API 2, I then added the Ninject.MVC3 package from NuGet.
Constructor injection is working fine for the MVC5 controllers, but i am getting an error when ...
69
votes
9
answers
63k
views
How to create dependency injection for ASP.NET MVC 5?
Creating Dependency Injection with ASP.NET Core is fairly easy. The documentation explains it very well here and this guy has a killer video to explain it.
However, I want to do the same thing with ...
69
votes
5
answers
50k
views
How to change type of id in Microsoft.AspNet.Identity.EntityFramework.IdentityUser
(ASP.NET MVC 5, EF6, VS2013)
I'm trying to figure out how to change the type of the "Id" field from string to int in the type:
Microsoft.AspNet.Identity.EntityFramework.IdentityUser
in order to ...
68
votes
5
answers
37k
views
Is ASP.NET MVC 5 incompatible with the WebMatrix SimpleMembershipProvider?
We have an existing application that was build on ASP.NET MVC 4 & Web API. The admin parts of the site use Simple Membership. I'm interested in upgrading the application to MVC 5 / Web API 2, to ...
67
votes
7
answers
63k
views
Getting controller name from razor
I seem to be having a difficult getting something that should be easy. From within my view, using Razor, I'd like to get the name of the current controller. For example, if I'm here:
http://www....
67
votes
11
answers
25k
views
ASP.NET MVC5 OWIN Facebook authentication suddenly not working
Update 2017!
The issue I had when I posted the original question has got nothing to do with the recent changes Facebook made when they forced everyone to version 2.3 of their API. For a solution to ...
67
votes
4
answers
109k
views
How to add claims in ASP.NET Identity
I am trying to find a document or example of how you would add custom claims to the user identity in MVC 5 using ASP.NET Identity. The example should show where to insert the claims in the OWIN ...
65
votes
2
answers
50k
views
How to add claims in a mock ClaimsPrincipal
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() {
...