public void SaveSettings()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay();

            AppConfig appConfig = (AppConfig)Globals.CurrentAppConfig.Clone();

            PassportClientConfig config = appConfig.PassportClient;

            config.EnablePassport = _Request.Get <bool>("EnablePassport", Method.Post, false);
            accessKey             = config.AccessKey;
            if (config.EnablePassport)
            {
                string passportOwnerUsername = _Request.Get("passportOwnerUsername", Method.Post);
                string passportOwnerPassword = _Request.Get("passportOwnerPassword", Method.Post);
                config.PassportRoot = _Request.Get("passportRoot", Method.Post);

                if (!config.TestPassportService(config.PassportRoot, 5000))
                {
                    msgDisplay.AddError("无法连接服务器“" + config.PassportRoot + "”,可能的原因:<br />1、 服务器地址不正确<br />2、 服务器未开放Passport接口<br />3、 请检查服务器和本地防火墙设置<br />4、请检查服务器和本地网站的.asmx后缀处理程序是否正确");
                    return;
                }

                registerClient = _Request.Get <bool>("registerClient", Method.Post, false);

                if (registerClient)
                {
                    APIResult result = null;
                    try
                    {
                        result = config.RegisterPassportClient(passportOwnerUsername, passportOwnerPassword, out newClientID);
                        if (result.IsSuccess == false)
                        {
                            foreach (string s in result.Messages)
                            {
                                msgDisplay.AddError(s);
                                return;
                            }
                        }
                        else
                        {
                            config.ClientID = newClientID;
                        }
                    }
                    catch (Exception ex)
                    {
                        msgDisplay.AddError(ex.Message);
                        return;
                    }
                }
            }

            Globals.SaveAppConfig(appConfig);
            //SaveSetting<PassportClientConfig>("savesetting");

            if (registerClient)
            {
                HttpRuntime.UnloadAppDomain();
            }
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string passportRoot = _Request.Get("passportroot", Method.Post);

            if (string.IsNullOrEmpty(passportRoot))
            {
                ShowError("请填写Passport服务器地址");
                return;
            }

            bool   success;
            string errMsg = string.Empty;

            using (ErrorScope es = new ErrorScope())
            {
                PassportClientConfig setting = new PassportClientConfig();

                success = setting.TestPassportService(passportRoot, 5000);

                if (es.HasUnCatchedError)
                {
                    CatchError <ErrorInfo>(delegate(ErrorInfo error)
                    {
                        ShowError(error);
                        return;
                        //errMsg += error.Message;
                    });
                }
            }

            if (success)
            {
                ShowSuccess("Passport服务器通讯正常!");
            }
            else
            {
                ShowError("无法连接" + passportRoot + "上的Passport服务!");
            }
        }