Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom user in ASP.NET MVC 2

I'm trying to implement a custom user object in ASP.NET MVC 2. I've seen a solution where you can do some magic in Global.asax to turn Controller.User into another type, say CustomUser. But Controller.User is still an IPrincipal, which means I have to cast it to CustomUser every time I want to use it, and I don't like that at all.

Would it be considered wrong, or bad practice, to have a a base controller with a GetUser() method, where GetUser() calls a user repository, and uses Controller.User to fetch our own custom user object?

What I'm trying to do is just add a couple of properties to the user object.

like image 817
Anders Ekdahl Avatar asked Jan 19 '26 08:01

Anders Ekdahl


1 Answers

Would it be considered wrong, or bad practice, to have a a base controller with a GetUser() method, where GetUser() calls a user repository, and uses Controller.User to fetch our own custom user object?

I don't think so. This is the way I do it. ;)

like image 128
John Farrell Avatar answered Jan 22 '26 01:01

John Farrell