开发者

How to do Authorization and Authentication in ASP.NET?

I was wondering how do I make it so when a user goes to a page its only displayed if he is logged in and secure, but if he is not logged in he is redirect开发者_如何学Ced to the login page? Thanks guys.


Use Forms Authentication


You can deny all un-authenticated users access in Web.config. When used with Forms Authentication denied users will be redirected to the login page specified:

<authentication mode="Forms">
  <forms loginUrl="~/account/login" timeout="2880" />
</authentication>

<authorization>
  <deny users="?"/>
</authorization>


FormsAuthentication will provide you with the redirect and subsequent Authorisation cookie but you'll need a Member store such as ASP.NET Membership to keep track of passwords and possibly Roles.


when user get loggedin store the user values in Session and on page load event of the page check the the session variable values.

So you can get the user id authenticate or not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜