如何限制用户仅查看联系我们的网站页面,并允许管理员查看所有内容页面 [英] How to restrict the users to view only contact us page of a website and allow admin to view all the content pages

查看:73
本文介绍了如何限制用户仅查看联系我们的网站页面,并允许管理员查看所有内容页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b我是asp.net的新手,我想限制用户只查看联系我们页面并允许ADMIN查看该网站的所有页面。



我尝试了什么:



 <   pre  >   <   body  >  
< 表格 id = form1 runat = server >
< di v class = menu >
< ul >

< li class = navigation_first_item > < span class =code-keyword>< a href = Default.aspx > 主页< / a > < / li >
< li class = navigation_s > < a href = 添加User.aspx > 添加用户< / a > < / li >
< li > < a href = Registrationpage.aspx > 注册员工< / a > < / li > ;
< li > < a href = Contact.aspx > 联系< / a > < / li >
< / ul >


< div class = logoutLblPos > ;

< label class = logoutLblPos >
< ; / label >
< br / >
< div >
< span class = auto-style1 > 时间 < / span > < span class = auto-style2 > < / span >
< asp:标签 ID = lbltime 文字 = runat = server 样式 = 颜色:黑色 > < / asp:标签 >
< / div >

< span class = auto-style3 > < span class = a uto-style4 > 用户 < / span > < / span > < asp:Label ID = lblusername 文字 = runat = server 样式 = 颜色:黑色 > < / asp:Label >
< < span class =code-leadattribute> br / >
< asp:按钮 ID = btnlogout 文字 = logout runat = server OnClick = btnlogout_Click 样式 = < span class =code-keyword> height:26px > < < span class =code-leadattribute> / asp:Button >
< / div >

< div class = left > < / div >
< div class = 正确 > < / div >


< div class = clear > < / div >
< div class = content > < / div >


< div class = 内容 >

< asp:ContentPlaceHolder ID = ContentBody runat = server >
< / asp:ContentPlaceHolder >

解决方案

Quote:

有时您希望允许公共访问您的注册页面,并希望限制访问该站点的其余部分仅限于记录/经过身份验证的用户.ie不允许匿名访问。假设您的注册页面在您站点的根文件夹中名为register.aspx。在您网站的根文件夹的web.config中,您需要进行以下设置。



< configuration>

< system.web> ;



< authentication mode =Forms/>



< authorization> < deny users =?/> //这将限制匿名用户访问







< location path =register.aspx > //这里的路径是register.aspx页面的路径,例如它可能是〜/ publicpages / register.aspx

< system.web>

< authorization>

< allow users = */> //这将允许所有人访问register.aspx











到目前为止,我们只看到了允许用户或经过身份验证的用户。但是可能存在这样的情况:我们希望允许特定用户访问某些页面但拒绝其他所有人(已验证以及匿名)。


Hi I am New to asp.net,I want to restrict the users to view only the contact us page and allow ADMIN to view all the pages of the website.

What I have tried:

<pre><body>
    <form id="form1" runat="server">
        <div class="menu">
            <ul>

                <li class="navigation_first_item"><a href="Default.aspx">Home</a></li>
                <li class="navigation_s"><a href="Add User.aspx">Add User</a></li>
                <li><a href="Registrationpage.aspx">Register Employee</a></li>
                <li><a href="Contact.aspx">Contact</a></li>
            </ul>


            <div class="logoutLblPos">

                <label class="logoutLblPos">
                </label>
                <br />
                <div>
                    <span class="auto-style1">Time</span> <span class="auto-style2">:</span>
            <asp:Label ID="lbltime" Text="" runat="server" Style="color: black"></asp:Label>
                </div>

                <span class="auto-style3"><span class="auto-style4">User </span> :</span><asp:Label ID="lblusername" Text="" runat="server" Style="color: black"></asp:Label>
                <br />
                <asp:Button ID="btnlogout" Text="logout" runat="server" OnClick="btnlogout_Click" Style="height: 26px"></asp:Button>
            </div>

            <div class="left"></div>
            <div class="right"></div>


            <div class="clear"></div>
            <div class="content"></div>


            <div class="Content">

                <asp:ContentPlaceHolder ID="ContentBody" runat="server">
                </asp:ContentPlaceHolder>

解决方案

Quote:

Sometimes you want to allow public access to your registeration page and want to restrict access to rest of the site only to logged / authenticated users .i.e. do not allow anonymous access. Say your registration page is called register.aspx in your site's root folder. In the web.config of your website's root folder you need to have following setup.

<configuration>
<system.web>

<authentication mode="Forms"/>

<authorization> <deny users="?"/> //this will restrict anonymous user access



<location path="register.aspx"> //path here is path to your register.aspx page e.g. it could be ~/publicpages/register.aspx
<system.web>
<authorization>
<allow users="*"/> // this will allow access to everyone to register.aspx





Till now we saw either allow users or to authenticated users only. But there could be cases where we want to allow particular user to certain pages but deny everyone else (authenticated as well as anonymous).


这篇关于如何限制用户仅查看联系我们的网站页面,并允许管理员查看所有内容页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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