云星空登录index.aspx页面自动转向统一认证页面原创
金蝶云社区-yaojunsong
yaojunsong
21人赞赏了该文章 8,389次浏览 未经作者许可,禁止转载编辑于2021年09月18日 12:01:53
summary-icon摘要由AI智能服务提供

本文档介绍了在云星空系统中,通过编写IIS处理程序Html5IndexAspxHttpModule,实现当访问index.aspx页面时自动重定向到统一认证页面的方法。包括创建类库工程、编写并部署HTTP模块代码、配置Web.Config以及模拟统一认证页面的编写。同时提供了应用程序池在不同模式下配置HTTP模块的方法,并解答了关于多路转向和F5刷新重入的问题,给出了解决方案和示例代码链接。

云星空登录index.aspx页面自动转向统一认证页面

【推荐私有云和单租户使用,不支持多租户】


1、编写iis的处理程序Html5IndexAspxHttpModule ,新建类库工程 TXSLoginModule,引用System.Web组件,编写 如下demo。

(注意编译dll后,拷贝到WebSite/Bin下,然后配置web.config, 然后重启iis站点)


(重现贴下代码,总有人有问题 (-:<:))


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Web;


namespace TXSLoginModule

{

    public class Html5IndexAspxHttpModule : System.Web.IHttpModule

    {

        public void Init(HttpApplication context)

        {

            // Demo代码不做错误保护,请在业务代码中做好错误保护和日志处理

            context.BeginRequest += context_BeginRequest;

        }

        void context_BeginRequest(object sender, EventArgs e)

        {

            // Demo代码不做错误保护,请在业务代码中做好错误保护和日志处理

            var ctx = sender as HttpApplication;

            if (ctx != null)

            {

                if (ctx.Request.Url.AbsolutePath.ToLowerInvariant().Contains("html5/index.aspx") &&

                    string.IsNullOrWhiteSpace(ctx.Request.QueryString.Get("ud")))

                {

                    //  这里转向统一认证界面地址  ,

                    //  website/html5目录下编写singlelogin.html和连接实现统一认证模拟,

                    //  正式登出地址请咨询第三方sso供应商

                    //  参考下面 3的内容                     

                        var rurl = System.Web.VirtualPathUtility.Combine(ctx.Request.Url.AbsolutePath, "singlelogin.html");  //singlelogin.html 为模拟sso登陆地址,具体请按真实登出地址修改

                        // 应用程序池集成模式

                        ctx.Response.Redirect(rurl);

                        // 应用程序池经典模式

                        //ctx.Server.Transfer(rurl);

                }

            }

        }

        public void Dispose()

        {

            

        }

    }

}


2、在WebSite目录下的Web.Config的modules节点下增加处理程序,如下:

(配置后,需要重启站点)


2.1、 应用程序池经典模式 web.config,写在system.web/httpModules节点下

  <system.web>

    <httpModules>

      <add name="Html5IndexAspxHttpModule" type="TXSLoginModule.Html5IndexAspxHttpModule,TXSLoginModule"/>


2.2、 应用程序池集成模式 web.config,写在system.webServer/modules节点下

  <system.webServer>

    <modules runAllManagedModulesForAllRequests="true">

      <add name="Html5IndexAspxHttpModule" type="TXSLoginModule.Html5IndexAspxHttpModule,TXSLoginModule"/>



3、仅用于模拟统一认证页面,在website/html5目录下编写singlelogin.html和连接实现统一认证模拟。


4、效果动画:

8.gif


5、配置好站点Web.config后,记得要重启 iis站点。(结束)


6、上面demo代码


  https://pan.kingdee.com/s/MTEyNTU3Niw5NTJl#/   



7、答疑:

疑问1】:存在多路转向,如何实现不同的目标地址转向?

【答】:两个方案实现,利用session写入参数,或者利用request的url参数。

    方案1:如果有配置入口角色entryrole参数,可以依据角色,利用request的UrlReferrer属性读取url中的entryrole参数来判断不同入口角色,再依据业务需求进行转向。

image.png

    方案2:可以在进入主控表单后,在主控表单插件中判断后写入session参数,然后在跳转的moduler中判断session参数进行路由跳转。


疑问2】:需要做F5刷新重入,怎么实现刷新后再次进入主控

【答】:建议做一个xx.aspx页面做桥,然后入口调用 xx.aspx?ud=##,在xx.aspx中把生成好的ud参数用session存起来后再跳转 k3cloud/html5/index.aspx。 下次进来发现url没有ud参数,但session有ud参数,就直接用ud参数进去(如果担心超时,可以重新生成ud),如果发现url有ud参数,就直接用url的ud参数,同时覆盖session的ud参数。




--附录---------------- 参考帖子区 ----------------------

星空第三方免登资料参考链接

https://vip.kingdee.com/article/221201966503051264 


------------------------------------------------------

编辑于2021年2月22日 10:41:35

赞 21