小编ldp*_*615的帖子

如何使用out参数调用方法?

我想暴露WebClient.DownloadDataInternal方法,如下所示:

[ComVisible(true)]
public class MyWebClient : WebClient
{
    private MethodInfo _DownloadDataInternal;

    public MyWebClient()
    {
        _DownloadDataInternal = typeof(WebClient).GetMethod("DownloadDataInternal", BindingFlags.NonPublic | BindingFlags.Instance);
    }

    public byte[] DownloadDataInternal(Uri address, out WebRequest request)
    {
        _DownloadDataInternal.Invoke(this, new object[] { address, out request });
    }

}
Run Code Online (Sandbox Code Playgroud)

WebClient.DownloadDataInternal有一个out参数,我不知道如何调用它.救命!

c# reflection out-parameters

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

NHibernate SchemaExport:如何生成有意义的唯一键名?

当我将SchemaExport与SQL Server 2005一起使用时,它会生成唯一的密钥名称,如:

UQ__Employees__03317E3D

如何生成如下名称:UQ__Employees__Name?即使在SQL Server中!

nhibernate schemaexport

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

如何在ASP.NET MVC中为HttpContext.User赋值?

我写了一个如下控制器:

public class AccountController : Controller
{
    public ActionResult Login(/*---*/)
    {
        GenericIdentity identity = new GenericIdentity("userName");
        GenericPrincipal principal = new GenericPrincipal(identity, new string[] { "role1", "role2" });
        this.HttpContext.User = principal;
        /*---*/;
    }
}
Run Code Online (Sandbox Code Playgroud)

登录后,我可以通过其他控制器中的User.Identity.Name获取用户名.但User.IsInRole("role1")始终返回false.

如何为User分配值,我不想使用Membership ...

asp.net-mvc authorize genericprincipal

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