简单表单经过身份验证的网站在登录后不会重定向

时间:2013-02-22 18:07:58

标签: c# asp.net forms-authentication

我有一个基于简单身份验证模型的网站。它在本地和本地IIS上运行良好,但在输入正确的凭据后,它不会重定向到默认页面,所有这些都在测试服务器中。

代码如下。

的Web.config

<compilation targetFramework="4.0" />
        <httpRuntime maxRequestLength="50000" />
        <customErrors mode="On" defaultRedirect="exc/exc.aspx?e=1">
            <error statusCode="404" redirect="exc/404.aspx?e=404"/>
        </customErrors>
        <authentication mode="Forms">
            <forms loginUrl="admin/login.aspx" defaultUrl="admin/main.aspx" />
        </authentication>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
    <location path="admin">
        <system.web>
            <authorization>
                <deny users="?"/>
            </authorization>
        </system.web>
    </location>
    <location path="admin/css/cms.css">
        <system.web>
            <authorization>
                <allow users="?"/>
            </authorization>
        </system.web>
    </location>
    <location path="admin/css/styles.css">
        <system.web>
            <authorization>
                <allow users="?"/>
            </authorization>
        </system.web>
    </location>
    <location path="admin/images">
        <system.web>
            <authorization>
                <allow users="?"/>
            </authorization>
        </system.web>
    </location>
    <location path="exc/exc.aspx">
        <system.web>
            <authorization>
                <allow users="?"/>
            </authorization>
        </system.web>
    </location>

login.aspx的

  

表单操作属性为空,AutoEventWireup为true。

login.aspx.cs

protected void btnAuth_Click1(object sender, EventArgs e)
{
        //Some code not shown...

        //User Validation
            ValidateUserResponse response = new ValidateUserResponse();
            response = service.ValidateUser(request);

            if (response.State == true)
                FormsAuthentication.RedirectFromLoginPage(request.Alias, False);            
}

SignOut

protected void Page_Load(object sender, EventArgs e)
{           
            FormsAuthentication.SignOut();
            Response.Redirect(FormsAuthentication.LoginUrl);            
}

在测试服务器上,URL看起来像这样:

http://192.168.1.58/TestSite/admin/login.aspx

在VS2010上发布时,我的本地IIS运行良好,但不明白为什么在TestServer上发布登录后不会重定向到默认页面。显示网站需要登录并出现403禁止错误

本地我已经用URL表单和作品测试了它(虚拟文件夹名称不同):

http://192.168.1.58/TestSite1/admin/login.aspx

http://localhost/TestSite1/admin/login.aspx

我很欣赏有关此事的任何建议,以使其发挥作用。

谢谢。

---------- -----------更新

我用这种方式解决了问题:

  1. 右键单击包含WebApp的虚拟目录
  2. 转到“目录安全性”选项卡
  3. 点击修改
  4. 未经检查的集成Windows身份验证
  5. 还必须检查匿名访问
  6. 这使Web.Config上的WebForms身份验证设置开始对WebApp产生影响。

    谢谢。

1 个答案:

答案 0 :(得分:1)

确保在Web服务器上的IIS中启用了表单身份验证。