开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜