如何控制在asp.net权限 [英] how to control the permission in asp.net

查看:131
本文介绍了如何控制在asp.net权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜:
在我的应用程序,网站中的所有内容只开放登录用户,这是说,如果我有以下页面:

Hi: In my application,all the content in the site is only open for login user,that's to say if I have the following pages:

Default.aspx
Document.aspx
xxx.aspx
....
SysConfig.aspx

当然有一个登录页面:的login.aspx

所有的页面排除的login.aspx 被保护,只有登录用户可以看到他们,并在 SysConfig.aspx 只是开放其类型用户为admin。

All the pages exclude the "login.aspx" are protected,only login user can see them,and the SysConfig.aspx is just open for the user whose type is "admin".

因此​​,如何控制呢?

So how to control this?

例如,当从login.aspx的用户登录,我可以将相关的信息保存到会话,然后在Default.aspx.cs我可以使用:

For example,when a user login from the login.aspx,I can save the related information to the "Session",then in the "Default.aspx.cs" I can use:

if(Session["user"]==null).....

但如果是这样,我必须写在同一codeS中的每个受保护的页面(在Document.aspx.cs / xxx.aspx.cs),我不知道是否有一个简单的方法?

But if so ,I have to write the same codes in each protected page(the Document.aspx.cs/xxx.aspx.cs),I wonder if there is a easy way?

在Java中,我可以把它简单地使用Struts2的拦截器,但我不知道如何使它在asp.net中。

In java,I can make it simply use the struts2's interceptor,but I have no idea how to make it in asp.net.

感谢。

推荐答案

的System.Web 部分web.config文件中添加这样的:

Add this in your web.config file in the system.web section:

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

这将prevent任何未授权的用户访问您的文件。

This will prevent any unauthenticated users from to access your files.

和您的Admin用户组访问 SYSCONFIG

And for your Admin user set access to SysConfig

<location path="SysConfig.aspx">
    <system.web>
        <authorization>
            <deny users="?"/>
            <allow roles="Admin"/>
        </authorization>
    </system.web>
</location>

编辑::要允许访问的Login.aspx一个匿名用户,补充一点:

To allow access to login.aspx to an anonymous user, add this:

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

这篇关于如何控制在asp.net权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆