Windows身份验证初始化ASP.net [英] Windows Authentication Initialization ASP.net

查看:96
本文介绍了Windows身份验证初始化ASP.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个ASP.net的WebForms项目,我们目前使用窗体身份验证,但客户端希望使用Windows身份验证来代替。所以,我已经改变了使用Windows身份验证的Web.config。然而,应用程序需要某些用户输入,并放入到会话可被访问的任何网页之前。目前,我们这样做的loginpage的回发。

In a ASP.net WebForms project, we currently use Forms Authentication, but the client wishes to use Windows Authentication instead. So I've changed the web.config to use Windows authentication. However, the application needs some user input and put in into a session before any webpage can be accessed. We currently do this in the postback of the loginpage.

由于Windows身份验证没有一个登录页面,如何才能实现这一目标?我应该在每一页上检查它的On_Init事件,如果会话已正确设置..?

Since Windows authentication does not have a 'Login' page, how can this be achieved? Should I check on every page it's On_Init event if the session has been set correctly..?

推荐答案

如果您需要在会议上,在每一个页面提供一个具体的数据,最简单的办法是有一个专门的模块支票早在管道事件,其中会话可用的一个条件(获取请求状态事件声音最适合的)。

If you need a specific data in session available in every single page, the easiest approach would be to have a dedicated module that checks the condition in one of early pipeline events where the session is available (the acquire request state event sounds most suitable).

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" ); 
    }
}

然后,你还需要一个可匿名访问的网页(你需要在 A部分的web.config 此):

<location path="anonymous.page.aspx">
  <system.web>
    <authorization>
      <allow users="*" />  
    </authorization>
  </system.web>
</location>

这篇关于Windows身份验证初始化ASP.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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