在本系列的最后一篇,我们来讨论最后三个ActionResult:HttpStatusCodeResult、RedirectResult和RedirectToRouteResult 。...中] 目录 一、HttpStatusCodeResult 二、RedirectResult 三、RedirectToRouteResult 四、“302重定向...二、RedirectResult RedirectResult帮助我们实现针对某个地址的重定向,其作用与调用HttpResonse的Redirect/RedirectPermanent方法完全一致。...1: public class RedirectResult : ActionResult 2: { 3: public RedirectResult(string url)...创建的RedirectResult/RedirectToRouteResult对象是针对注册的某个路由的。
)); var rr = result as RedirectResult; Assert.AreEqual("login_success", rr.Url...)); rr = result as RedirectResult; Assert.AreEqual("login_fail", rr.Url);...await ctrl.Login(); Assert.IsNotNull(act); Assert.IsInstanceOfType(act, typeof(RedirectResult...)); var rd = act as RedirectResult; Assert.AreEqual("/home", rd.Url);...)); rd = act as RedirectResult; Assert.AreEqual("/login", rd.Url); }
=0) { context.Result = new RedirectResult("/Home/Index"); }...; item.Content = "没得权限"; filterContext.Result = new RedirectResult
; if (session["user"] == null) { filterContext.Result = new RedirectResult...filterContext.Result = result; } else { filterContext.Result = new RedirectResult
RedirectResult - 使用Controller中提供的Redirect()方法返回一个RedirectResult用来发起一个 HTTP 301 或 302 到指定URL的跳转。
RedirectResult:使用Redirect(string url)将结果转到其他的Action JsonResult:使用Json(object data) 将data序列化为json数据并返回
filterContext.HttpContext.Response.StatusCode == 403) { filterContext.Result = new RedirectResult
context.ExceptionHandled = true; } else { context.Result = new RedirectResult
filterContext.HttpContext.Response.StatusCode == 401) { filterContext.Result = new RedirectResult
代表为登录,调整至登录页面 // 只有设置了Result才会终结操作 filterContext.Result = new RedirectResult...case 2: // 代表无访问权限,调整至无权限提示页面 filterContext.Result = new RedirectResult...if (statusCode>=400 && statusCode<500) { filterContext.Result = new RedirectResult...404.html"); } else { filterContext.Result = new RedirectResult
filterContext.HttpContext.Response.StatusCode == 401) { //跳转到登录界面 filterContext.Result = new RedirectResult
//跳转页面,使用Result,而不是使用Response.Redirect() 因为它会继续执行Action //filterContext.Result = new RedirectResult...filterContext); //记录日志 //直接跳转到异常处理页面 filterContext.Result= new RedirectResult
out encryptValue); if (encryptValue == null) { filterContext.Result = new RedirectResult...ApplicationKey.User_Cookie_Encryption_Key); if (string.IsNullOrEmpty(userName)) { filterContext.Result = new RedirectResult
filterContext.Exception; //2.记录异常日志 //3.重定向友好页面 filterContext.Result = new RedirectResult
const string loginUrl = "~/Main/Login"; filterContext.Result = new RedirectResult
ActionResult的本质:JavaScriptResult & JsonResult 了解ASP.NET MVC几种ActionResult的本质:HttpStatusCodeResult & RedirectResult
uri = String.Format(uri, redirectUri, clientId, scope); 30: context.Result = new RedirectResult...如果这样的Access Token不存在,我们通过为HttpAuthenticationChallengeContext的Result属性设置一个RedirectResult对象实现针对Windows
JsonResult 提供对象和Json字符串的序列化与返序列化 HttpStatusCodeResult 方便返回Http状态码 RedirectResult RedirectToRouteResult
var authenticationUrl = context.GetAuthorizationUrl(state, scope); return new RedirectResult
.; filterContext.Result = new RedirectResult(strUrl); } }
领取专属 10元无门槛券
手把手带您无忧上云