When a controller loads an instance of an API controller, the User and Request properties are null.
This is a regression from MVC 4.
Repro steps:
1. Create a new MVC 4 WebApi project
2. Add the following method to ValuesController:
```
public string GetUserName()
{
return User.Identity.Name;
}
```
3. Add the following line to the beginning of HomeController.Index
```
string userName = new ValuesController().GetUserName();
```
4. Run the project. (everything is fine)
5. Update all the nuget packages for MVC5 RC1
6. Run the project. Get a NullReferenceException because User is null;
I believe this worked properly in Beta 1.
Let me know if you need any additional information,
Michael.
Comments: Fair enough. I worked around it by replacing the call to .User with Thread.CurrentPrincipal (which is what the ApiController used to do, i believe).
This is a regression from MVC 4.
Repro steps:
1. Create a new MVC 4 WebApi project
2. Add the following method to ValuesController:
```
public string GetUserName()
{
return User.Identity.Name;
}
```
3. Add the following line to the beginning of HomeController.Index
```
string userName = new ValuesController().GetUserName();
```
4. Run the project. (everything is fine)
5. Update all the nuget packages for MVC5 RC1
6. Run the project. Get a NullReferenceException because User is null;
I believe this worked properly in Beta 1.
Let me know if you need any additional information,
Michael.
Comments: Fair enough. I worked around it by replacing the call to .User with Thread.CurrentPrincipal (which is what the ApiController used to do, i believe).