/// <summary> /// 代理信息获取 /// </summary> /// <param name="request"></param> /// <returns></returns> protected ClientProxyExType ProxyEx(HttpRequestBase request) { ClientProxyExType cpet = Session[ConstStr_Session.CurrentProxyExType] as ClientProxyExType; if (cpet == null || cpet.UserID == "admin") { //TODO:用户登录后需要修改为用户信息,同时给applicationcontext赋值用户信息看在多用户登录情况下服务中是否生效,否则如写日志等操作需要在客户端将用户id传递过去 cpet = new ClientProxyExType(); cpet.UserID = CurrentUser.UserId.ToString(); cpet.IP_Client = GetHostAddress(); cpet.IP_WebServer = hc.Plat.Common.Global.NetTools.GetLocalMachineIP4(); cpet.CurrentUser = CurrentUser; Session[ConstStr_Session.CurrentProxyExType] = cpet; } else { var userId = cpet.UserID.ToLong(); if (!userId.HasValue) { cpet = new ClientProxyExType(); cpet.UserID = CurrentUser.UserId.ToString(); cpet.IP_Client = GetHostAddress(); cpet.IP_WebServer = hc.Plat.Common.Global.NetTools.GetLocalMachineIP4(); cpet.CurrentUser = CurrentUser; Session[ConstStr_Session.CurrentProxyExType] = cpet; } } return(cpet); }
protected ClientProxyExType ProxyEx(string userId = "") { ClientProxyExType cpet = new ClientProxyExType(); cpet.UserID = userId; cpet.IP_Client = HttpContext.Current.Request.UserHostAddress; //request.UserHostAddress; cpet.IP_WebServer = hc.Plat.Common.Global.NetTools.GetLocalMachineIP4(); return(cpet); }
/// <summary> /// Token校验 /// </summary> /// <returns></returns> //private bool ValidateToken(string ticket, string sys) //{ // bool result = false; // int type = 0; // int.TryParse(sys, out type); // try // { // using (ClientSiteClientProxy proxy = new ClientSiteClientProxy(ProxyEx(ticket))) // { // Result<Base_User> login = proxy.GetBaseUserByToken(ticket, type); // if (login.Flag == 0 && ((type == 1 && login.Data.AndroidTokenTime.HasValue) || (type == 2 && login.Data.IosTokenTime.HasValue))) // { // DateTime expiryTime = type == 1 ? login.Data.AndroidTokenTime.Value : login.Data.IosTokenTime.Value; // if (DateTime.Now <= expiryTime) // { // //user = login.Data; // result = true; // } // } // } // } // catch (Exception e) // { // throw e; // } // return result; //} ///// <summary> ///// 权限校验(判断用户登录时,已经获取了当前登录用户的所有权限) ///// </summary> ///// <returns></returns> //private bool ValidateRight() //{ // string module = (Module ?? "").ToString(); // string action = (Action ?? "").ToString(); // if (CheckRight) // { // if (string.IsNullOrWhiteSpace(module) || string.IsNullOrWhiteSpace(action)) // { // return false; // } // if (user == null) // { // return false; // } // return true; // } // return true; //} protected ClientProxyExType ProxyEx(string token = "") { ClientProxyExType cpet = null; if (cpet == null) { cpet = new ClientProxyExType(); cpet.Token = token; cpet.IP_WebServer = NetTools.GetLocalMachineIP4(); } return(cpet); }
protected ClientProxyExType ProxyEx(HttpRequestBase request, string userName = "******") { ClientProxyExType cpet = Session[ConstStr_Session.CurrentProxyExType] as ClientProxyExType; if (cpet == null) { cpet = new ClientProxyExType(); cpet.UserID = userName; cpet.IP_Client = request.UserHostAddress; cpet.IP_WebServer = NetTools.GetLocalMachineIP4(); } return(cpet); }
/// <summary> /// 代理信息获取 /// </summary> /// <param name="request"></param> /// <returns></returns> private ClientProxyExType ProxyEx(HttpRequestBase request) { ClientProxyExType cpet = Session[ConstStr_Session.CurrentProxyExType] as ClientProxyExType; if (cpet == null) { cpet = new ClientProxyExType(); cpet.UserID = "admin"; cpet.IP_Client = request.UserHostAddress; cpet.IP_WebServer = hc.Plat.Common.Global.NetTools.GetLocalMachineIP4(); Session[ConstStr_Session.CurrentProxyExType] = cpet; } return(cpet); }
protected ClientProxyExType ProxyExNoLogin(HttpRequestBase request, string userName = "******") { ClientProxyExType cpet = Session[ConstStr_Session.CurrentProxyExType] as ClientProxyExType; if (cpet == null) { //TODO:用户登录后需要修改为用户信息,同时给applicationcontext赋值用户信息看在多用户登录情况下服务中是否生效,否则如写日志等操作需要在客户端将用户id传递过去 cpet = new ClientProxyExType(); cpet.UserID = userName; cpet.IP_Client = request.UserHostAddress; cpet.IP_WebServer = hc.Plat.Common.Global.NetTools.GetLocalMachineIP4(); Session[ConstStr_Session.CurrentProxyExType] = cpet; } return(cpet); }
/// <summary> /// 获取初始化代理要传递的信息对象 /// </summary> /// <param name="userId"> /// 用户标识。 /// 1.pc端为用户Id,如此时无需登录,此参数留空; /// 2.移动端为用户token,如此时无需登录,此参数留空; /// </param> /// <param name="request">当前webapi 的HttpRequest,移动端必传,pc端一定不要传入</param> /// <returns></returns> protected ClientProxyExType ProxyEx(UserView user) { ClientProxyExType cpet = MemoryNETCache.Get <ClientProxyExType>(user.UserId.ToString()); if (cpet == null) { //用户登录后需要修改为用户信息 cpet = new ClientProxyExType(); cpet.CurrentUser = user; cpet.UserID = user.UserId.ToString(); cpet.IP_Client = HttpContext.Current.Request.UserHostAddress; //request.UserHostAddress; cpet.IP_WebServer = hc.Plat.Common.Global.NetTools.GetLocalMachineIP4(); MemoryNETCache.Set(user.UserId.ToString(), cpet, 60000); } return(cpet); }
/// <summary> /// 代理信息获取 /// </summary> /// <param name="request"></param> /// <returns></returns> protected static ClientProxyExType ProxyEx(HttpContextBase httpContext, UserView user) { if (user == null) { httpContext.Response.Redirect("/Currency/Login"); httpContext.Response.End(); } ClientProxyExType cpet = httpContext.Session[ConstStr_Session.CurrentProxyExType] as ClientProxyExType; if (cpet == null) { //TODO:用户登录后需要修改为用户信息,同时给applicationcontext赋值用户信息看在多用户登录情况下服务中是否生效,否则如写日志等操作需要在客户端将用户id传递过去 cpet = new ClientProxyExType(); cpet.UserID = user.UserId.ToString(); cpet.IP_Client = httpContext.Request.UserHostAddress; cpet.IP_WebServer = hc.Plat.Common.Global.NetTools.GetLocalMachineIP4(); httpContext.Session[ConstStr_Session.CurrentProxyExType] = cpet; } return(cpet); }
/// <summary> /// 代理信息获取 /// </summary> /// <param name="request"></param> /// <returns></returns> protected virtual ClientProxyExType ProxyEx(HttpRequestBase request) { ClientProxyExType cpet = Session[ConstStr_Session.CurrentProxyExType] as ClientProxyExType; if (cpet == null || cpet.UserID == "youke") { if (CurrentUser == null) { CurrentUser = new UserView() { UserId = 897711908373794816 }; } //TODO:用户登录后需要修改为用户信息,同时给applicationcontext赋值用户信息看在多用户登录情况下服务中是否生效,否则如写日志等操作需要在客户端将用户id传递过去 cpet = new ClientProxyExType(); cpet.UserID = CurrentUser.UserId.ToString(); cpet.IP_Client = request.UserHostAddress; cpet.IP_WebServer = hc.Plat.Common.Global.NetTools.GetLocalMachineIP4(); cpet.CurrentUser = CurrentUser; Session[ConstStr_Session.CurrentProxyExType] = cpet; } return(cpet); }
public override void Process() { byte[] uploadFileBytes = null; string uploadFileName = null; if (UploadConfig.Base64) { uploadFileName = UploadConfig.Base64Filename; uploadFileBytes = Convert.FromBase64String(Request[UploadConfig.UploadFieldName]); } else { var file = Request.Files[UploadConfig.UploadFieldName]; uploadFileName = file.FileName; if (!CheckFileType(uploadFileName)) { Result.State = UploadState.TypeNotAllow; WriteResult(); return; } if (!CheckFileSize(file.ContentLength)) { Result.State = UploadState.SizeLimitExceed; WriteResult(); return; } uploadFileBytes = new byte[file.ContentLength]; try { file.InputStream.Read(uploadFileBytes, 0, file.ContentLength); } catch (Exception) { Result.State = UploadState.NetworkError; WriteResult(); } } Result.OriginFileName = uploadFileName; var savePath = PathFormatter.Format(uploadFileName, UploadConfig.PathFormat); //var localPath = Server.MapPath(savePath); try { //if (!Directory.Exists(Path.GetDirectoryName(localPath))) //{ // Directory.CreateDirectory(Path.GetDirectoryName(localPath)); //} //File.WriteAllBytes(localPath, uploadFileBytes); //Result.Url = savePath; //Result.State = UploadState.Success; // 修改原有百度富文本编辑器上传附件的存储方式。 // 将富文本编辑器中的附件上传到资源服务器, ClientProxyExType cpxy = new ClientProxyExType("NoLogin", Context.Request.UserHostAddress); using (ClientProxyResource proxy = new ClientProxyResource(cpxy)) { var attachResult = proxy.SaveToResourceServer(Guid.NewGuid().ToString(), uploadFileBytes, savePath); if (attachResult.Flag == EResultFlag.Success) { savePath = attachResult.Data; using (ClientProxySite securityProxy = new ClientProxySite(cpxy)) { var securityResult = securityProxy.ServerIpGetDefault(); if (securityResult.Flag == EResultFlag.Success && securityResult.Data != null) { string serverUrl = securityResult.Data.WebIp; if (string.IsNullOrWhiteSpace(serverUrl)) { Result.ErrorMessage = attachResult.Exception.Decription; } else { if (!serverUrl.StartsWith("http://") && !serverUrl.StartsWith("https://")) { serverUrl = "http://" + serverUrl; } if (!serverUrl.EndsWith("/")) { serverUrl += "/"; } Result.Url = serverUrl + savePath; Result.State = UploadState.Success; } } else { Result.ErrorMessage = attachResult.Exception.Decription; } } } else { Result.ErrorMessage = attachResult.Exception.Decription; } } } catch (Exception e) { Result.State = UploadState.FileAccessError; Result.ErrorMessage = e.Message; } finally { WriteResult(); } }
/// <summary> /// 走,登录去。。。 /// </summary> /// <returns></returns> public ActionResult GoToLogin() { if ("1".Equals(IsOpenSxLogin)) { if (User.Identity.IsAuthenticated) { string userAccount = CasAuthentication.CurrentPrincipal.Identity.Name; using (ClientSiteClientProxy proxy = new ClientSiteClientProxy(ProxyEx(Request, userAccount))) { Result <UserView> loginResult = proxy.LoginByCas(userAccount); if (loginResult.Flag == 0) { Session[ConstStr_Session.CurrentUserEntity] = loginResult.Data; LoadUserRight(loginResult.Data.RoleType.ToString(), loginResult.Data.UserId); Result <List <Base_Right> > result = proxy.LoadRightList(loginResult.Data.RoleType.ToString(), loginResult.Data.UserId); if (result.Flag == EResultFlag.Success) { var list = result.Data.Where(i => i.ParentId == 0 && i.IsMenu).ToList(); List <WebRightNode> rightNodesList = list.Select(p => new WebRightNode() { Id = p.Id, Name = p.DisplayName, Url = p.URL, Target = p.Target }).ToList(); foreach (var rightNode in rightNodesList) { rightNode.ChildNode = GetChildNode(rightNode.Id, result.Data); } Session[ConstStr_Session.CurrUserRight] = rightNodesList; ClientProxyExType cpet = new ClientProxyExType(); cpet = new ClientProxyExType(); cpet.UserID = loginResult.Data.UserId.ToString(); cpet.IP_Client = Request.UserHostAddress; cpet.IP_WebServer = NetTools.GetLocalMachineIP4(); cpet.CurrentUser = loginResult.Data; Session[ConstStr_Session.CurrentProxyExType] = cpet; } } } string url = "Home/SignIndex"; if (Request.QueryString.AllKeys.Contains("returnUrl")) { url = Request.QueryString["returnUrl"]; } return(Redirect(url)); } else { CasAuthentication.RedirectToLoginPage(); Response.Write("你不登录?"); Response.End(); } } else { return(RedirectToAction("Login")); } return(View()); }
public void DownloadXTFile(string fileId, string type) { try { if (string.IsNullOrWhiteSpace(fileId) || string.IsNullOrWhiteSpace(type)) { Response.Write("请选择要下载的附件!"); Response.End(); return; } long fileIdValue; if (long.TryParse(fileId, out fileIdValue)) { ClientProxyExType cpet = new ClientProxyExType("xt"); cpet.IP_Client = Request.UserHostAddress; cpet.IP_WebServer = NetTools.GetLocalMachineIP4(); using (ClientSiteClientProxy proxy = new ClientSiteClientProxy(cpet)) { Result <Epm_TzAttachs> result = new Result <Epm_TzAttachs>(); result = proxy.GetFileByTzAttachsId(fileIdValue); if (result.Flag == EResultFlag.Success && result.Data != null) { var data = result.Data; if (data != null) { FileInfo file = new FileInfo(data.FilePath);//创建一个文件对象 FileStream stream = file.OpenRead(); var bufferLength = stream.Length; byte[] bytes = new byte[bufferLength]; stream.Read(bytes, 0, Convert.ToInt32(bufferLength)); stream.Flush(); stream.Close(); Response.Clear(); // 设置缓冲输出为true,后台编辑的文件写到内存流中了 Response.Buffer = true; // 设置编码格式 ContentEncoding是管字节流到文本的,而Charset是管在浏览器中显示的 //Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); Response.Charset = "GBK"; // 将HTTP头添加到输出流,指定默认名 Response.AddHeader("Content-Disposition", string.Format(@"attachment;filename=""{0}""", HttpUtility.UrlEncode(data.Name))); Response.ContentEncoding = System.Text.Encoding.UTF8; // 设置输出流的HTTP MIME类型 Response.ContentType = "application/octet-stream;charset=gbk"; Response.AddHeader("Content-Length", bytes.Length.ToString()); // 将指定的文件写入HTTP内容输出流 //Response.OutputStream.Write(bytes, 0, bytes.Length); //防止文件名含中文出现乱码而进行编码 //Response.BinaryWrite(bytes); System.IO.Stream fs = this.Response.OutputStream; fs.Write(bytes, 0, bytes.Length); fs.Close(); // 向客户端发送当前所有缓冲的输出 Response.Flush(); // 将当前所有缓冲的输出关闭 Response.Close(); } else { throw new Exception(result.Exception.Decription); } } else { throw new Exception("附件不存在或已被删除!"); } } } else { Response.Write("请选择要下载的附件!"); Response.End(); return; } } catch (Exception ex) { Response.Write(ex.Message); Response.End(); return; } }