Пример #1
0
		internal static void ExecuteAction(HttpContext context, InvokeInfo vkInfo)
		{
			if( context == null )
				throw new ArgumentNullException("context");
			if( vkInfo == null )
				throw new ArgumentNullException("vkInfo");

			// 验证请求是否允许访问(身份验证)
			AuthorizeAttribute authorize = vkInfo.GetAuthorize();
			if( authorize != null ) {
				if( authorize.AuthenticateRequest(context) == false )
					ExceptionHelper.Throw403Exception(context);
			}

			// 调用方法
			object result = ExecuteActionInternal(context, vkInfo);

			// 设置OutputCache
			OutputCacheAttribute outputCache = vkInfo.GetOutputCacheSetting();
			if( outputCache != null )
				outputCache.SetResponseCache(context);

			// 处理方法的返回结果
			IActionResult executeResult = result as IActionResult;
			if( executeResult != null ) {
				executeResult.Ouput(context);
			}
			else {
				if( result != null ) {
					// 普通类型结果
					context.Response.ContentType = "text/plain";
					context.Response.Write(result.ToString());
				}
			}
		}