且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Web应用程序中的母版页之前登录

更新时间:2023-12-06 10:45:40

使用FormsAuthentication并将LoginUrl设置为Login.aspx页面。类似于:



Use FormsAuthentication and set the LoginUrl to your Login.aspx page. Something like:

<authentication mode="Forms">
    <forms loginUrl="~/Login.aspx" protection="All" timeout="600" slidingExpiration="true" domain=""/>
  </authentication>





然后,他们登录后使用FormsAuthentication.RedirectFromLoginPage()设置身份验证cookie。



这样任何对您网站的请求如果未经过身份验证,都会自动发送到Login.aspx。



Then after they login set the authentication cookies using FormsAuthentication.RedirectFromLoginPage().

This way any request to your site if they have not been authenticated they will be sent automatically to Login.aspx.