0

在 ASP.net WebForms 项目中,我们目前使用表单身份验证,但客户端希望使用 Windows 身份验证。所以我更改了 web.config 以使用 Windows 身份验证。但是,应用程序需要一些用户输入并放入会话中,然后才能访问任何网页。我们目前在登录页面的回发中执行此操作。

由于 Windows 身份验证没有“登录”页面,如何实现?如果会话设置正确,我是否应该检查每个页面的 On_Init 事件..?

4

2 回答 2

1

如果您需要在每个页面中都提供会话中的特定数据,最简单的方法是使用专用模块来检查会话可用的早期管道事件之一中的条件(获取请求状态事件听起来最合适)。

public class CustomConditionCheckModule : IHttpModule
{
    public void Init( HttpApplication context )
    {
        context.AcquireRequestState += new EventHandler( acq_req_state );
    }        

    public void acq_req_state( object sender, EventArgs e )
    {
        // check your condition there - the data is in session
        var session = HttpContext.Current.Session;
        if ( ... the condition ... )
           Response.Redirect( "~/anonymous.page.aspx" ); 
    }
}

然后你还需要一个可以匿名访问的页面(web.config为此你需要一个部分):

<location path="anonymous.page.aspx">
  <system.web>
    <authorization>
      <allow users="*" />  
    </authorization>
  </system.web>
</location>
于 2013-10-23T14:04:52.697 回答
-1

我认为您可以在 web.config 中使用带有 windows 身份验证的LDAP (Active Directory 身份验证),但如果它的 Intranet Web 应用程序或其他方式,即使用 windows 身份验证的基于角色的安全性。

于 2013-10-23T13:49:41.077 回答