小编M R*_*ker的帖子

如何在Linq GroupBy中选择前N行

希望你能在这里帮助我.我有一个预订列表,我想在每组TourOperator中获得前两行.

这是一个数据样本:

List<Booking> list = new List<Booking>();
        list.Add(new Booking() { BookingNo = "31111111", DepDate = new DateTime(2011, 5, 1), TourOperator = "SPI" });
        list.Add(new Booking() { BookingNo = "32222222", DepDate = new DateTime(2011, 5, 2), TourOperator = "SPI" });
        list.Add(new Booking() { BookingNo = "33333333", DepDate = new DateTime(2011, 5, 3), TourOperator = "SPI" });
        list.Add(new Booking() { BookingNo = "34444444", DepDate = new DateTime(2011, 5, 4), TourOperator = "SPI" });
        list.Add(new Booking() { BookingNo = "35555555", DepDate = new …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

HttpContext.Current.Session为null

我在类库中有一个带有自定义Cache对象的WebSite.所有项目都运行.NET 3.5.我想将此类转换为使用会话状态而不是缓存,以便在我的应用程序回收时保留状态服务器中的状态.但是,当我从Global.asax文件访问方法时,此代码抛出"HttpContext.Current.Session为null"的异常.我这样叫这个班:

Customer customer = CustomerCache.Instance.GetCustomer(authTicket.UserData);
Run Code Online (Sandbox Code Playgroud)

为什么对象总是为空?

public class CustomerCache: System.Web.SessionState.IRequiresSessionState
{
    private static CustomerCache m_instance;

    private static Cache m_cache = HttpContext.Current.Cache;

    private CustomerCache()
    {
    }

    public static CustomerCache Instance
    {
        get
        {
            if ( m_instance == null )
                m_instance = new CustomerCache();

            return m_instance;
        }
    }

    public void AddCustomer( string key, Customer customer )
    {
        HttpContext.Current.Session[key] = customer;

        m_cache.Insert( key, customer, null, Cache.NoAbsoluteExpiration, new TimeSpan( 0, 20, 0 ), CacheItemPriority.NotRemovable, null );
    }

    public Customer GetCustomer( string key ) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net

12
推荐指数
1
解决办法
3万
查看次数

如何在 ASP.NET Core 2.1 网站上启用 HttpOnly cookie

我在 Visual Studio 中使用“文件”->“新建项目”使用 Core 2.1 创建了一个标准 ASP.NET Core MVC 网站。

Startup.cs 中是样板代码

 public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });


        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error"); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc .net-core asp.net-core

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

HTTP Slow Post和IIS设置以防止

因此,我们从一家安全公司获得这份报告称,我们在IIS 8.0上运行的MVC网站容易受到HTTP后DoS攻击速度缓慢的影响.报告指出我们应该

  • 限制请求属性是通过<RequestLimits>元素,特别是maxAllowedContentLength,maxQueryString和maxUrl属性.
  • 设置<headerLimits>为配置Web服务器将接受的标头的类型和大小.
  • 调整 和元素的connectionTimeout,
    headerWaitTimeout和minBytesPerSecond属性,以最大限度地减少慢速HTTP攻击的影响.<limits>
    <WebLimits>

麻烦的是我很难找到关于如何设置这些值的任何建议.例如.minBytesPerSecond默认为240,但是应该如何防止SlowHTTPPost攻击呢?

干杯Jens

security iis web iis-8

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

如何在Visual Studio 2013中的源代码管理下复制和重命名解决方案

我有一个名为ShoppingService.sln的VS2013解决方案,在TFS源代码控制下有7个项目.现在我想制作解决方案的副本,将其重命名为'BasketService.sln'并再次将其置于源代码管理之下.我不想做原始解决方案的分支,因为两个解决方案应该彼此分开共存.

什么是最快或最好的方法?

tfs visual-studio

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