private void InvokeClass() { Type t = null; #region 处理Ajax请求 //从Url来源页找 if (context.Request.UrlReferrer == null) { WriteError("Illegal request!"); return; } else if (!IsExistsSafeKey() && WebHelper.IsCheckToken())// 仅检测需要登陆的页面 { string path = context.Request.UrlReferrer.PathAndQuery; if (path == "/") { path = "/index.html"; } WriteError(path);//"Page timeout,please reflesh page!" return; } //AjaxController是由页面的后两个路径决定了。 string[] items = context.Request.UrlReferrer.LocalPath.TrimStart('/').Split('/'); string className = Path.GetFileNameWithoutExtension(items[items.Length - 1].ToLower()); //从来源页获取className 可能是/aaa/bbb.shtml 先找aaa.bbb看看有木有,如果没有再找bbb if (items.Length > 1) { t = InvokeLogic.GetType(items[items.Length - 2].ToLower() + "." + className); } if (t == null) { t = InvokeLogic.GetDefaultType(); if (t == null) { WriteError("You need to create a controller for coding !"); return; } } #endregion try { object o = Activator.CreateInstance(t);//实例化 t.GetMethod("ProcessRequest").Invoke(o, new object[] { context }); } catch (ThreadAbortException e) { //ASP.NET 的机制就是通过异常退出线程(不要觉的奇怪) } catch (Exception err) { WriteError(err.Message); } }
private void InvokeClass() { string localPath = context.Request.Url.LocalPath; Type t = null; bool needInvoke = false; if (localPath.EndsWith("/ajax.html")) // 反射Url启动 { #region 处理Ajax请求 //从Url来源页找 if (context.Request.UrlReferrer == null) { WriteError("Illegal request!"); } else if (!IsExistsSafeKey()) { WriteError("Page timeout,please reflesh page!"); } //AjaxController是由页面的后两个路径决定了。 string[] items = context.Request.UrlReferrer.LocalPath.Split('/'); string className = Path.GetFileNameWithoutExtension(items[items.Length - 1].ToLower()); //从来源页获取className 可能是/aaa/bbb.shtml 先找aaa.bbb看看有木有,如果没有再找bbb if (items.Length > 1) { t = InvokeLogic.GetType(items[items.Length - 2].ToLower() + "." + className, 0); } else { t = InvokeLogic.GetDefaultType(0); } needInvoke = true; #endregion } else if (localPath.IndexOf(".") == -1) // 处理Mvc请求 { needInvoke = true; string[] items = localPath.Trim('/').Split('/'); string className = items[0]; if (RouteConfig.RouteMode == 2) { className = items.Length > 1 ? items[1] : ""; } t = InvokeLogic.GetType(className, 1); } if (needInvoke) { if (t == null) { WriteError("You need a controller for coding if you want to use Taurus.MVC! else go to <a href='/login.html'>login.html</a>"); } try { object o = Activator.CreateInstance(t);//实例化 t.GetMethod("ProcessRequest").Invoke(o, new object[] { context }); } catch (ThreadAbortException e) { //ASP.NET 的机制就是通过异常退出线程(不要觉的奇怪) } catch (Exception err) { WriteError(err.Message); } } }