2016-11-03 126 views
0

据我所知,当你想认证用户,你需要添加以下内容到webconfig。现在允许注册页面的用户尚未注册

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

,我把所有的代码以注册用户,其中插入他们顺利进入我的数据库以及用于检查并允许浏览器,只要正确的凭据被插入到用户名和登录页面密码字段。

我现在想要做的是按下“注册”按钮重定向到我的注册页面,但这与上面关于授权的代码相冲突,我研究并发现需要做的是创建一个文件夹并在里面有registrarion.aspx页面,并使用以下参数为所述文件夹创建一个web.config文件。

<authorization> 
     <allow users = "*" /> 
     </authorization> 

我的按钮都有一个重定向一旦用户被授权即如下的所有其他网页,其工作代码:

Response.Redirect("Register.aspx", true); 

按钮但是,不会重定向到注册页面,什么允许用户注册的其他方法会起作用吗?

经进一步调查,我发现下面的代码可以与我想要做的

<td>Username:</td> 
<td><input id="txtUserName" type="text" runat="server"></td> 
     <td><ASP:RequiredFieldValidator ControlToValidate="txtUserName" 
      Display="Static" ErrorMessage="*" runat="server" 
      ID="vUserName" /></td> 

同时需要用户名和密码进入,会因此受到影响重定向按钮,即使webconfig允许非冲突用户进入注册页面?

+0

那么你的问题是什么?你提出了一个问题,然后谈论你如何解决问题,但没有说明它是否有效,或者你目前面临什么问题。 – mason

+0

谢谢,我编辑了这个问题。 – Marcus

回答

0

我认为你正在寻找这个。第一个<system.web>节点是每个Web.Config中的默认节点。在那里,你拒绝匿名用户使用<deny users="?"/>访问该网站。 但是,这也会阻止用户访问注册页面,并在重定向循环中发送浏览器。 但是,您可以将<location>节点添加到Web.Config,并允许匿名用户访问注册页面<allow users="?"/>

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <globalization uiCulture="nl" culture="nl-NL" /> 
    <compilation targetFramework="4.5.1" /> 
    <httpRuntime targetFramework="4.5" executionTimeout="120" maxRequestLength="1024000" /> 
    <authentication mode="Forms"> 
     <forms cookieless="UseCookies" timeout="43200" loginUrl="/Register.aspx" defaultUrl="/Default.aspx" /> 
    </authentication> 
    <authorization> 
     <deny users="?"/> 
    </authorization> 
    </system.web> 
    <location path="Register.aspx"> 
    <system.web> 
     <authorization> 
     <allow users="?"/> 
     </authorization> 
    </system.web> 
    </location> 
</configuration> 
+0

你好,我试过这个,它没有工作,我认为这可能是由于在表单中需要输入用户名和密码字段,将这个ifnormation添加到问题中。 – Marcus

+0

定义“没有工作”?上面的代码片段只允许匿名用户访问登录页面。它与表单中的必填字段无关。 – VDWWD