C# 重定向到链接OnActionExecuting(ActionExecutingContext)
萨拉蒙·阿勒库姆 我想撤销 在这个方法中,我想重定向到网页链接,如何使之成为可能 例如:C# 重定向到链接OnActionExecuting(ActionExecutingContext),c#,asp.net,.net,asp.net-mvc,sharepoint,C#,Asp.net,.net,Asp.net Mvc,Sharepoint,萨拉蒙·阿勒库姆 我想撤销 在这个方法中,我想重定向到网页链接,如何使之成为可能 例如: public class LicenseFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { ///Some Code Here Redirect("http://webp
public class LicenseFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
///Some Code Here
Redirect("http://webpage.com"); ///Redirect to This Page
///Rest Of The Code
谢谢。如果您需要更多详细信息,请告诉我。您已接近成功,但请不要尝试重定向
filterContext.Result = new RedirectResult("http://www.webpage.com");
不管怎么说,我就是这么用的。通常它会重定向到我的登录页面,该页面将位于同一个项目中,因此我会执行以下操作
filterContext.Result = new RedirectResult(Url.Action("Index", "Login"));
编辑:删除了返回语句,它是一个空的,您只需设置重定向结果而不返回它查看本文中的答案:[[1]: