【问题标题】:Set a ServerVariable in a IIS 7.0 httpmodule在 IIS 7.0 httpmodule 中设置 ServerVariable
【发布时间】:2012-06-21 16:54:24
【问题描述】:

我正在尝试在 IIS 7.0 的 http 模块中设置一个服务器变量(“LOGON_USER”),但我没有归档它。

到目前为止,我的 BeginRequest 函数...

        BindingFlags temp = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;


        MethodInfo addStatic = null;
        MethodInfo makeReadOnly = null;
        MethodInfo makeReadWrite = null;


        Type type = application.Request.ServerVariables.GetType();
        MethodInfo[] methods = type.GetMethods(temp);
        foreach (MethodInfo method in methods)
        {
            switch (method.Name)
            {
                case "MakeReadWrite": makeReadWrite = method;
                    break;
                case "MakeReadOnly": makeReadOnly = method;
                    break;
                case "AddStatic": addStatic = method;
                    break;
            }
        }

        makeReadWrite.Invoke(application.Request.ServerVariables, null);
        string[] values = { "LOGON_USER", "test" };
        addStatic.Invoke(application.Request.ServerVariables, values);
        makeReadOnly.Invoke(application.Request.ServerVariables, null);

在我的搜索过程中,我了解到该解决方案适用于较旧的 IIS,但不适用于 IIS 7.0 或 7.5。

知道如何在 IIS 7.0 中完成它吗?

谢谢

【问题讨论】:

    标签: iis iis-7 iis-7.5 httpmodule server-variables


    【解决方案1】:

    已解决:

        HttpApplication application = (HttpApplication)source;
        HttpContext context = application.Context;
    
        context.User = new GenericPrincipal(new GenericIdentity("test"), null);
    

    new GenericPrincipal(new GenericIdentity("test"), null) 会将“test”放在 LOGON_USER 变量中

    更多信息在这里:http://learn.iis.net/page.aspx/170/developing-a-module-using-net/

    【讨论】:

      【解决方案2】:

      使用 IIS 的 URL 重写模块设置服务器变量时,您必须明确指定允许设置的服务器变量。这对于您自己的代码也可能是必需的。请参阅:http://learn.iis.net/page.aspx/686/setting-http-request-headers-and-iis-server-variables/(并搜索“允许更改服务器变量”)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-10
        相关资源
        最近更新 更多