我试图将我的所有ASP MVC HTTP响应标头更改为默认情况下具有另一个值,以便在我的博客应用程序中实现Pingback自动发现.
默认标头(在Cassini上)是:
Cache-Control private
Connection Close
Content-Length 20901
Content-Type text/html; charset=utf-8
Date Fri, 20 Apr 2012 22:46:11 GMT
Server ASP.NET Development Server/10.0.0.0
X-AspNet-Version 4.0.30319
X-AspNetMvc-Version 3.0
Run Code Online (Sandbox Code Playgroud)
我想要一个额外的增值:
X-Pingback: http://localhost:4912/pingback/xmlrpcserver
Run Code Online (Sandbox Code Playgroud)
我已经google了一下,找到了一个neet解决方案: - 从ActionFilterAttribute派生并覆盖OnResultExecuted方法:
public class HttpHeaderAttribute : ActionFilterAttribute
{
public string Name { get; set; }
public string Value { get; set; }
public HttpHeaderAttribute(string name, string value)
{
Name = name;
Value = value;
}
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
filterContext.HttpContext.Request.Headers.Add(Name, Value);
base.OnResultExecuted(filterContext); …Run Code Online (Sandbox Code Playgroud) 我博客的模型:
namespace AlexPeta_2.Models
{
public class Article
{
public int ArticleId { get; set; }
public string Title { get; set; }
public string Text { get; set; }
public char Published { get; set; }
public DateTime CreatedDate { get; set; }
public char AllowComment { get; set; }
public virtual ICollection<Tag> Tags { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
}
}
namespace AlexPeta_2.Models
{
public class Comment
{
public int CommentId { get; …Run Code Online (Sandbox Code Playgroud) 我正在使用LINQ填充"类别"下拉列表.(Northwind数据库)
var Category = (from cat in _db.Categories.ToList()
select new SelectListItem
{
Text = cat.CategoryName,
Value = cat.CategoryID.ToString()
}).ToList();
Run Code Online (Sandbox Code Playgroud)
我希望在此列表的开头添加一个额外的值作为过滤器重置,类似于"全部",所以我希望下拉列表类似于: