且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何限制未经登录进入网站的用户

更新时间:2023-12-03 18:41:52

修改您的web.config文件,请注意授权"部分

http://www.developerfusion.com/article/5385/highperformance-net -application-development-architecture/5/ [
Amend your web.config file, pay attention to the ''Authorisation'' section

http://www.developerfusion.com/article/5385/highperformance-net-application-development-architecture/5/[^]

<authorization>
   <!-- General application authorization -->
   <allow verbs="POST" users="Jimmy" roles="Administrators" />
   <allow verbs="GET" users="Peter" roles="Debugger Users" />
   <!-- URL Authorization -->
   <allow users="domain1\user, domain2\group" />
   <!--Deny anonymous or All Users-->
   <deny users="? | *" />
 </authorization>



在此部分,您可以允许\根据凭据,组成员身份等拒绝用户



This is the section where you can allow \ deny users based on credentials, group membership etc


<pre lang="xml">&lt;authentication mode=&quot;Forms&quot;&gt;
            &lt;forms defaultUrl=&quot;Secured/Default.aspx&quot; loginUrl=&quot;Login.aspx&quot;&gt;
      &lt;/forms&gt;
        &lt;/authentication&gt;</pre>

<pre lang="xml">&lt;system.web&gt;
            &lt;authorization&gt;
                &lt;deny users=&quot;?&quot;/&gt;
            &lt;/authorization&gt;
        &lt;/system.web&gt;</pre>
in the code behind
<pre lang="cs">protected void btn_Submit_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text == &quot;UserName&quot;)
            {
                if (TextBox2.Text == &quot;Password&quot;)
                {
                   // Response.Redirect(&quot;~/Secured/Secured2.aspx&quot;);
                    FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
                }
                else
                {
                    Label1.Text = &quot;Enter Correct Password&quot;;
                }
            }
            else
            {
                Label1.Text = &quot;Enter Correct User Name&quot;;
            }
        }</pre>
<pre lang="sql">Use Forms Authentication for that
try this link
Link [^]</pre>


我认为您需要阅读一些有关身份验证及其在IIS环境中如何工作的信息.您所要求的内容不应仅在代码和SQL Server中处理.您应该合并内置的IIS身份验证过程以实现您的目标.
查看一些
I think you need to read up a bit on authentication and how it works in an IIS environment. What you are asking for should not be handled only in code and SQL Server. You should incorporate built in IIS authentication processes to achieve your goal.
Check out some of these links.