c# - ASP.NET redirecting certain pages to login page -


i'm new asp.net , i'm trying create simple crud application, want have pages redirect login page if user not logged in. don't want site wide redirect login pages not home page. have been messing around controllers , have found using code in controllers redirect login page if user not logged in:

public actionresult index() {     if (user.identity.isauthenticated)     {         return view(db.events.tolist());     }     else     {         response.redirect("account/login",true);         return null;     } } 

i have feeling not in best practices of asp.net. if explain why or point me in right direction great.

you can use [authorize] attribute , redirect login page if user not authorized.

[authorize] public actionresult index() {     return view(); } 

which login page need configure in web.config


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -