Search code examples
asp.netasp.net-mvcaction-filter

How to redirect user to account page until he complete his personal info in ASP.net MVC


I am working on a ASP.net MVC project. In this project users personal information is crucial so we want to not allow user to see his panel after his first log in unless he has completed his resume and personal information exactly like Facebook users experience after registration for the first time.

I am looking for the best practice to accomplish this workflow. I have thought about customizing authorization in MVC framework so that it consider wethear the user has a complete data in database in OnAuthorization method. I also have hesitated to write a parent controller class and make all controllers to inherit from it and in this class i would be able to check users data status and redirect to account page whenever users data is imperfect or even use action filters in order to do that.

Does anyone have a good idea or suggestion for me? i would really appreciate any guidance.


Solution

  • You may want to take a look at MVC action filters. Action filters can host logic that would trigger prior calling to controllers and actions. You can define your logic to check whether the user has completed the profile and if not, redirect to a different location in a filter.

    Once you have your action filter, you can register it globally, so all requests are send through it, or on controllers/actions that you want to protect.

    A good example http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/understanding-action-filters-cs