开发者

How can I redirect an unauthorized user to a login page?

开发者 https://www.devze.com 2022-12-23 05:06 出处:网络
I have my own login page. If any us开发者_开发知识库er access any page directly (without login), I want to redirect unauthorized user to a login page. How is it possible? Using Generic Handler, is the

I have my own login page. If any us开发者_开发知识库er access any page directly (without login), I want to redirect unauthorized user to a login page. How is it possible? Using Generic Handler, is there a chance? Or how can I do it?


You can set this behaviour in the web.config

Example: (this enables authentication)

<authentication mode="Forms">
   <forms cookieless="AutoDetect" protection="All" slidingExpiration="true" loginUrl="~/login.aspx"/>
</authentication>
<authorization>
   <deny users="?"/>
</authorization>

(the specified path is excluded from authentication. meaning you can access the file/directory without authentication. useful for image, scripts, styles directories)

<location path="login.aspx">
   <system.web>
     <authorization>
        <allow users="*" />
     </authorization>
    </system.web>
</location>
0

精彩评论

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