小编Sal*_*goz的帖子

Windows操作系统中无法访问的IP套接字关闭时间

这些代码通过用户数据报协议提供发送数据.下面有两个代码.当我使用第一个代码来获取无法访问的IP地址时,我得到了三秒钟的延迟.


请查看新结果标题


刚刚打开新的C#CONSOLE APP并将这些代码粘贴在其中.(第一个代码)

using System;
using System.Net;
using System.Net.Sockets;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] data = { 1, 20, 60, 44, 244 };
            while (true)
            {
                Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt"));
                try
                {
                    using (var client = new UdpClient())
                    {
                        // Please check IP Address, It must be unreachable...
                       // IPEndPoint ep = new IPEndPoint(IPAddress.Parse("192.168.1.141"), 55600);
                      //  client.Connect(ep);
                        client.Send(data, data.Length, "192.168.1.141" , 55600);
                    }
                    Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt"));
                    Console.WriteLine("    ");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                } …
Run Code Online (Sandbox Code Playgroud)

c# python sockets ubuntu udp

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

如何使用 webapi 2 将数据从 AuthorizeAttribute 传递到控制器?

我创建了一个custom AuthorizeAttribute验证一些OAuth credentials of user.

一旦我获得有效的用户,我想将响应数据返回到控制器,如何在 web api .net 中实现此目的。

public class CustomAttribute : AuthorizeAttribute
{
    protected override bool IsAuthorized(HttpActionContext actionContext)
    {
        var response = mydata.Result.Content.ReadAsStringAsync();
        if (mydata.Result.StatusCode == HttpStatusCode.OK)
        {
            // return response data to controller
            return true;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我搜了一下我得到in mvccan be done like below

public class CustomAttribute : AuthorizeAttribute
{
   public string BlackListedUsers { get; set; }
   protected override bool AuthorizeCore(AuthorizationContext filterContext)
   {
     filterContext.HttpContext.Items["test"] = "foo";
     return true; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-web-api

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

C#Func <object> getObject的目的是什么?

我找到了以下代码片段,并想知道该Func<object> getObject属性的目的是什么:

public void InsertCacheItem(string key, Func<object> getObject, TimeSpan duration)
{
    try
    {
        var value = getObject();
        if (value == null)
            return;

        key = GetCacheKey(key);

        _cache.Insert(
            key,
            value,
            null,
            System.Web.Caching.Cache.NoAbsoluteExpiration,
            duration,
            System.Web.Caching.CacheItemPriority.Normal,
            null);
    }
    catch { }
}
Run Code Online (Sandbox Code Playgroud)

如何通过传递Func属性来调用此特定函数?

c# func

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

标签 统计

c# ×3

asp.net-web-api ×1

func ×1

python ×1

sockets ×1

ubuntu ×1

udp ×1