使用.NET身份验证防止不登录直接访问页面 .
在Web.config中加入配置节:
<authentication mode="Forms">
<forms defaultUrl="Login.aspx" loginUrl="Login.aspx" timeout="30" />
</authentication>
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
写在<system.web>后
这样,就可以做到非登录用户禁止访问页面,但有一个问题,可能造成登录页的图片显示不出来。这是因为这样配置会把项目所在的所有文件夹都保护起来,为了显示图片,还要单独配置图片文件夹,允许访问。
加入以下配置节:
<location path="App_Themes/Default">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
这样,在保证了所有页面在不登录禁止访问的情况下,也保证了图片文件夹的正确显示。
联系邮箱:liqiyu2014@qq.com