Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Unassigned: MVC 5 RC-1 Regression: User/Request are null when calling an api controller from another controller [1256]

$
0
0
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).

Viewing all articles
Browse latest Browse all 7215

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>