What clever things have you done with an ASP.NET MVC Action method

后端 未结 5 1761
借酒劲吻你
借酒劲吻你 2020-12-12 11:59

The ASP.NET MVC controller action methods are primarily used for handling \'business\' operations but it can be used for lots more.

I thought it would be fun to see

5条回答
  •  一个人的身影
    2020-12-12 12:57

    Does a HTTP 301 Redirect count as clever?

    public class PermanentRedirectResult : ActionResult
    {
        public string Url { get; set; }
    
        public PermanentRedirectResult(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentException("url is null or empty", "url");
            }
            this.Url = url;
        } 
    
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            context.HttpContext.Response.StatusCode = 301;
            context.HttpContext.Response.RedirectLocation = Url;
        }
    }
    

提交回复
热议问题