ActionExecutingContext.Result

ActionExecutingContext.HttpContext.Response.Redirect();

ESB全称为Enterprise Service Bus,即企业服务总线。它是传统中间件技术与XML、Web服务等技术结合的产物

正向代理, 用户手动指定的代理服务器, 用户是清楚代理服务器的。 Forward Proxy; 反向代理, 服务器端配置的, 对用户透明。 Reverse Proxy;

Html.ValidationMessage

Controller.ModelState ==> ModelStateDictionary

ModelState.IsValid

// ModelStateDictionary.cs
public bool IsValid 
{
    get {
        // Determines whether all elements of a sequence satisfy a condition.
        return Values.All(modelState => modelState.Errors.Count == 0);
    }
}

public void AddModelError(string key, Exception exception) 
{
    GetModelStateForKey(key).Errors.Add(exception);
}

//
// Summary:
//     Gets the value associated with the specified key.
//
// Parameters:
//   key:
//     The key whose value to get.
//
//   value:
//     When this method returns, the value associated with the specified key, if the
//     key is found; otherwise, the default value for the type of the value parameter.
//     This parameter is passed uninitialized.
//
// Returns:
//     true if the object that implements System.Collections.Generic.IDictionary`2 contains
//     an element with the specified key; otherwise, false.
//
// Exceptions:
//   T:System.ArgumentNullException:
//     key is null.
bool TryGetValue(TKey key, out TValue value);

Asp.net mvc

  • 2009-03-17 ASP.NET MVC 1.0
  • 2010-03-11 ASP.NET MVC 2.0 RTM
  • 2011-01-13 ASP.NET MVC 3.0 RTM
  • 2012-08-15 ASP.NET MVC 4.0
  • 2013-10-17 ASP.NET MVC 5.0
  • 2014-01-17 ASP.NET MVC 5.1
  • 2014-12-25 ASP.NET MVC 5.2
//ActionResult
ContentResult,          Content(string content)
FilePathResult,         File(string fileName, string contentType)
FileStreamResult,       File(Stream fileName, string contentType, string fileDownloadName)
FileContentResult,      File(byte[] fileContents, string contentType)
HttpNotFoundResult,     HttpNotFound()
JavaScriptResult,       JavaScript(string script)
JsonResult,             Json(object data, string contentType)
PartialViewResult,      PartialView(string viewName)
RedirectResult,         Redirect(string url)
RedirectToRouteResult,  RedirectToAction(string actionName, controllerName)
ViewResult,             View(string viewName)

常用MVC Filter

  1. AcceptVerbs 规定页面的访问形式,如
[AcceptVerbs(HttpVerbs.Post)]
//或[HttpPost]
public ActionResult Example()
{return View();}

页面只能以Post形式访问,即表单提交。

  1. ActionName 规定Action的名称。

应用场景:如果不想用方法名做为Action名,或Action名为关键字的话,如

[ActionName("class")]
public ActionResult Example()
{return View();}
  1. NonAction 当前方法仅是普通方法不解析为Action

  2. OutputCache 为Action添加缓存

[OutputCache(Duration = 60, VaryByParam = "*")]
public ActionResult Example()
{return View();}
  1. ValidateInput 该Action可以接受Html等危险代码(ASP.NET MVC在aspx中设置<%@ Page 的属性无法完成等同任务)
    [ValidateInput(false)]
    public ActionResult Example()
    {return View();}
    
  2. ValidateAntiForgeryTokenAttribute 用于验证服务器篡改。
[ValidateAntiForgeryToken]
public ActionResult Example()
{return View();}

asp.net core mvc

  1. ConfigurationBuilder
  2. IWebHostBuilder
  3. IApplicationBuilder
  4. IRouteBuilder

"{controller=Home}/{action=Index}/{id?}" can match the URL path / and will produce the route values { controller = Home, action = Index }.

MVC would use these route values to select the HomeController and Index action

asp.net current directory

System.Web.HttpRuntime.AppDomainAppPath

System.Web.HttpContext.Current.Server.MapPath("~")

System.Web.Hosting.HostingEnvironment.MapPath("~");