小编Ale*_*eta的帖子

更改默认的ASP MVC请求标头以添加您自己的值

我试图将我的所有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)

c# asp.net-mvc http-headers

9
推荐指数
2
解决办法
1万
查看次数

实体框架代码第一个数据库文件未在APP_DATA中创建,但查询工作

我博客的模型:

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)

asp.net-mvc code-first ef-code-first entity-framework-4.1

2
推荐指数
1
解决办法
1932
查看次数

LINQ查询在选择后添加额外值

我正在使用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)

我希望在此列表的开头添加一个额外的值作为过滤器重置,类似于"全部",所以我希望下拉列表类似于:

  • 全部//添加
  • 饮料//来自查询
  • 调味品//来自查询

c# linq drop-down-menu

1
推荐指数
1
解决办法
4089
查看次数