以编程方式确定身份验证模式 [英] Programmatically determine authentication mode

查看:49
本文介绍了以编程方式确定身份验证模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法以编程方式确定 SharePoint 2007 Web 应用程序是否使用表单身份验证?我想一种方法可能是从 web.config 中读取它,但我想知道 API 中是否公开了一些属性.

Is there a way to programmatically determine if a SharePoint 2007 web application is using Forms authentication? I guess one way might be to read it from the web.config but I was wondering if there is some property exposed in the API.

推荐答案

看看/_admin/Authentication.aspx 在 Central Admin 中是如何做到的:

Take a look at how /_admin/Authentication.aspx does it in Central Admin:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    string g = base.Request.QueryString["WebAppId"];
    this.webApp = (SPWebApplication) SPConfigurationDatabase.Local.GetObject(new Guid(g));
    this.zone = (SPUrlZone) Enum.Parse(typeof(SPUrlZone), base.Request.QueryString["Zone"]);
    this.lb_Zone.Text = SPHttpUtility.HtmlEncode(SPAlternateUrl.GetZoneName(this.zone));
    SPIisSettings iisSettings = this.webApp.IisSettings[this.zone];

    // CODE ELIDED

        if (AuthenticationMode.Windows != iisSettings.AuthenticationMode)
        {
            if (AuthenticationMode.Forms != iisSettings.AuthenticationMode)
            {
                // CODE ELIDED
            }
            else
            {
                this.rdo_authForms.Checked = true;
            }

            // CODE ELIDED
       }
}

您感兴趣的部分是它使用 iisSettings.AuthenticationMode 来确定它是否是 Forms Auth 的地方.因此,诀窍是正确获取对与您的 web 应用程序和区域相关的 SPIisSettings 的引用.到达这一点是所有工作都需要完成的地方.

The part you are interested in is where it uses iisSettings.AuthenticationMode to determine if it is Forms Auth or not. So the trick is to correctly obtain a reference to SPIisSettings that is relevant to your webapp and zone. Getting to that point is where all the work needs to be done.

您需要对此代码的部分进行参数化,以便传入用于识别和获取对 webApp 和 Zone 的引用的信息.

You'll need to parameterize parts of this code so that information to identify and obtain references to the webApp and Zone are passed in.

看看它在哪里分配 his.rdo_authForms.Checked?这就是您如何知道它是否使用表单身份验证.

See where it assigns his.rdo_authForms.Checked? that's how you know if it's using forms auth.

此外,这意味着您需要知道您正在查看的 Web 应用程序的哪个区域,以查看是否启用了表单身份验证

Also, this implies that you need to know which Zone of the web application you are looking at to see if Forms Authentication is enabled

这篇关于以编程方式确定身份验证模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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