小编MaK*_*MKo的帖子

如何在asp.net core rc2中获取控制器的自定义属性

我创建了一个自定义属性:

[AttributeUsage(AttributeTargets.Method| AttributeTargets.Class)]
public class ActionAttribute : ActionFilterAttribute
{
    public int Id { get; set; }
    public string Work { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我的控制器:

[Area("Administrator")]
[Action(Id = 100, Work = "Test")]
public class HomeController : Controller
{
    public IActionResult Index()
    {
        return View();
    }
}
Run Code Online (Sandbox Code Playgroud)

我的代码:我使用反射来查找当前程序集中的所有控制器

 Assembly.GetEntryAssembly()
         .GetTypes()
         .AsEnumerable()
         .Where(type => typeof(Controller).IsAssignableFrom(type))
         .ToList()
         .ForEach(d =>
         {
             // how to get ActionAttribute ?
         });
Run Code Online (Sandbox Code Playgroud)

有可能以ActionAttribute实用的方式阅读所有内容吗?

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

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

在每次webservice调用之前调用某个方法

这是情况.我有一个webservice(C#2.0),它主要由一个继承自System.Web.Services.WebService的类组成.它包含一些方法,所有方法都需要调用一个方法来检查它们是否被授权.

基本上是这样的(原谅架构,这纯粹是一个例子):

public class ProductService : WebService
{
    public AuthHeader AuthenticationHeader;

    [WebMethod(Description="Returns true")]
    [SoapHeader("AuthenticationHeader")]        
    public bool MethodWhichReturnsTrue()
    {
        if(Validate(AuthenticationHeader))
        {
            throw new SecurityException("Access Denied");
        }
        return true;
    }

    [WebMethod(Description="Returns false")]
    [SoapHeader("AuthenticationHeader")]        
    public bool MethodWhichReturnsFalse()
    {
        if(Validate(AuthenticationHeader))
        {
            throw new SecurityException("Access Denied");
        }
        return false;
    }

    private bool Validate(AuthHeader authHeader)
    {
        return authHeader.Username == "gooduser" && authHeader.Password == "goodpassword";
    }
}
Run Code Online (Sandbox Code Playgroud)

如您所见,Validate必须在每种方法中调用该方法.我正在寻找一种能够调用该方法的方法,同时仍然能够以理智的方式访问soap标头.我看过那里的事件global.asax,但我认为我不能访问该课程中的标题......我可以吗?

.net c# web-services

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

如果+可空类型(C#)的简写

以下返回

无法确定条件表达式的类型,因为"double"和"<null>"之间没有隐式转换

aNullableDouble = (double.TryParse(aString, out aDouble) ? aDouble : null)
Run Code Online (Sandbox Code Playgroud)

之所以我不能只使用aNullableBool而不是使用aDouble的往返是因为aNullableDouble是生成的EntityFramework类的一个属性,它不能用作超标.

c# conditional-operator

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

MVVM c#如何将异步数据加载到属性中?

我想知道是否有更好的方法将异步数据加载到属性中.现在我创建一个异步函数并在属性的Get部分中引发一个Task,如下所示:

private ObservableCollection<CProyecto> prope;

public ObservableCollection<CProyecto> Prope
{
    get 
    {
        if (prope == null)
        {
            Task.Run(()=> LoadData()).Wait();
        }

        return proyectos;
    }
    set 
    { 
        prope = value; 
        RaisePropertyChanged(); 
    }
}

async private Task LoadData() 
{
    Prope = await clsStaticClassDataLoader.GetDataFromWebService();
}
Run Code Online (Sandbox Code Playgroud)

这种方法有效,但我不喜欢使用.Wait,因为如果服务没有快速响应,它可以冻结屏幕.

你能指导我这件事吗?

提前致谢

c# wpf mvvm

4
推荐指数
2
解决办法
5978
查看次数

C#:为什么设置PropertyValues有0项?

假设设置文件(MySetting1to MySetting5)中有5个项目,为什么PropertyValues有0个项目而Properties有正确的数字?

Console.WriteLine( Properties.Settings.Default.PropertyValues.Count); // Displays 0
Console.WriteLine( Properties.Settings.Default.Properties.Count);     // Displays 5
Run Code Online (Sandbox Code Playgroud)

c# visual-studio-2005 visual-studio

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

Web场中的并发登录

我真的是通过代理问这个问题,另一个工作团队已经收到了我们客户的变更请求.

问题是我们的客户不希望他们的员工同时向一个用户登录多个用户.他们被锁定并共享登录.

由于这是在Web场上,解决此问题的最佳方法是什么?

不缓存到数据库会导致性能问题吗?

asp.net authentication

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