小编Cra*_*erz的帖子

GoogleOauth2问题导致内部服务器500错误

我决定尝试新的Google Oauth2中间件,它几乎打破了一切.这是来自startup.auth.cs的我的提供程序配置.启用后,所有提供商(包括Google提供商)都会在Challenge上获得500内部服务器.但是,内部服务器错误的详细信息不可用,我无法弄清楚如何打开Katana中间件的任何调试或跟踪.在我看来,他们急于将谷歌Oauth中间件推出门外.

  //// GOOGLE
        var googleOptions = new GoogleOAuth2AuthenticationOptions
        {
            ClientId = "228",
            ClientSecret = "k",
            CallbackPath = new PathString("/users/epsignin")
            SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
            Provider = new GoogleOAuth2AuthenticationProvider
            {
                OnAuthenticated = context =>
                {
                    foreach (var x in context.User)
                    {
                        string claimType = string.Format("urn:google:{0}", x.Key);
                        string claimValue = x.Value.ToString();
                        if (!context.Identity.HasClaim(claimType, claimValue))
                            context.Identity.AddClaim(new Claim(claimType, claimValue, XmlSchemaString, "Google"));
                    }
                    return Task.FromResult(0);
                }
            }
        };

        app.UseGoogleAuthentication(googleOptions);
Run Code Online (Sandbox Code Playgroud)

ActionMethod代码:

 [AllowAnonymous]
    public ActionResult ExternalProviderSignIn(string provider, string returnUrl)
    {
       var ctx = Request.GetOwinContext();
        ctx.Authentication.Challenge(
            new AuthenticationProperties
            { …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-4 katana asp.net-mvc-5

17
推荐指数
2
解决办法
7213
查看次数

nHibernate连接多个表并使用AliasToBean Transformer

我非常需要从数据库中获取一些数据并返回DTO.我发现使用nHibernate连接多个表并"投射",所以说,DTO是相当多的代码.看了几个例子,大多数没有用的东西给我留下了一个带有空值的DTO,我想到了以下内容并且想知道你是否nHibernate ninja可以告诉我是否有更好的方法.

public IOpenIdUser GetOpenIdUser(string claimedIdentifier, IOpenIdUser openIdUserDto)
    {
        User user = null;
        OpenIdUser openIdUser = null;
        Profile profile = null;
        UserType userType = null;


        return
            SessionWrapper.Session.QueryOver(() => user).JoinAlias(() => user.Profiles, () => profile).
                JoinAlias(() => user.OpenIdUsers, () => openIdUser).JoinAlias(() => user.UserType, () => userType)
                .Where(() => user.UserName == claimedIdentifier)
                .SelectList(l => l
                                     .Select(x => openIdUser.OpenIdUserId).WithAlias(() => openIdUser.OpenIdUserId)
                                     .Select(x => user.UserId).WithAlias(() => openIdUserDto.UserId)
                                     .Select(x => openIdUser.OpenIdClaimedIdentifier).WithAlias(
                                         () => openIdUserDto.ClaimedIdentifier)
                                     .Select(x => openIdUser.OpenIdFriendlyIdentifier).WithAlias(
                                         () => openIdUserDto.FriendlyIdentifier)
                                     .Select(x => openIdUser.OpenIdEndPoint).WithAlias(
                                         () => …
Run Code Online (Sandbox Code Playgroud)

nhibernate

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

在ajax发布之前使用不引人注目的验证

所以我一直在玩Anti Forgery Token,感谢你们的进步.

我已经想出了一个合并表单值的解决方案,以及让我的ActionMethods不要反击AntiForgery令牌......我遗憾地在这个过程中破坏了验证.在忽略客户端验证/客户端验证之前,将触发AJAX帖子.服务器端工作,但我会在帖子之前挖掘一些验证..这是我正在使用的代码.

$(document).ready(function () {
 $('input[type=submit]').live("click", function (event) {
     event.preventDefault();

     // Form with the AntiForgeryToken in it
     var _tokenForm = $(this).parents().find("#__AjaxAntiForgeryForm");

     // Current Form we are using
     var _currentForm = $(this).closest('form');

     // Element to update passed in from AjaxOptions
     var _updateElement = $(_currentForm).attr("data-ajax-update");

     // Serialize the array
     var arr = $(_currentForm).serializeArray();

     //Merge TokenForm with the CurrentForm
     $.merge(arr, $(_tokenForm).serializeArray());


     // The AJAX Form Post stuff
     $.ajax({
         type: "POST",
         url: $(_currentForm).attr('action'),
         data: arr,
         success: function (data) {
             $(_updateElement).html(data); …
Run Code Online (Sandbox Code Playgroud)

jquery asp.net-mvc-3

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

NH 3.3 Composite-ID 通过代码映射

图表

我在这里拉我的头发试图弄清楚如何映射下面列出的 UsersRoles 表。我不好看秃头所以请帮忙:)

//这里是实体

public class UsersRole
{
    public UsersRole() { }
    public virtual User User { get; set; }
    public virtual Role Role { get; set; }
    public virtual System.Guid UserId { get; set; }
    public virtual System.Guid RoleId { get; set; }


}
Run Code Online (Sandbox Code Playgroud)

//这是到目前为止的映射

public class UsersRoleMap : ClassMapping<UsersRole>
{
    public UsersRoleMap()
    {
        Table("UsersRoles");
        Lazy(true);

       // ComponentAsId(); How does this work??


        Property(x => x.UserId, map => map.Column(c =>
            {
                c.Name("UserId");
                c.NotNullable(true);
                c.Length(30);
                c.SqlType("uniqueidentifier");
            }));
        Property(x => x.RoleId, map …
Run Code Online (Sandbox Code Playgroud)

nhibernate nhibernate-mapping

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

用于Nhibernate事务管理的ActionFilter是一个不错的方法

我有以下包装器:

 public interface ITransactionScopeWrapper : IDisposable
{
    void Complete();
}

public class TransactionScopeWrapper : ITransactionScopeWrapper
{
    private readonly TransactionScope _scope;
    private readonly ISession _session;
    private readonly ITransaction _transaction;

    public TransactionScopeWrapper(ISession session)
    {
        _session = session;
        _scope = new TransactionScope(TransactionScopeOption.Required,
                                      new TransactionOptions {IsolationLevel = IsolationLevel.ReadCommitted});
        _transaction = session.BeginTransaction();
    }

    #region ITransactionScopeWrapper Members

    public void Dispose()
    {
        try
        {
            _transaction.Dispose();
        }
        finally
        {
            _scope.Dispose();
        }
    }

    public void Complete()
    {
        _session.Flush();
        _transaction.Commit();
        _scope.Complete();
    }

    #endregion
}
Run Code Online (Sandbox Code Playgroud)

在我的ActionFilter中,我有以下内容:

 public class NhibernateTransactionAttribute : ActionFilterAttribute …
Run Code Online (Sandbox Code Playgroud)

nhibernate asp.net-mvc-3

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

疯狂查询需要一些反馈

        var query =context.Categories.Include("ChildHierarchy")
             .Where(c =>
                 context.CategoryHierarchy.Where(ch => ch.ParentCategoryID == ch.ParentCategoryID)
                 .Select(ch => ch.ChildCategoryID).Contains(c.CategoryID));
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 我需要包含来自另一个Navigation Propery的一些数据(".Include("otherprop")")
  2. 在所有这些之后是否可以选择新的?

谢谢

c# linq linq-to-entities

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

任何人都知道如何在DotNetOpenAuth中关闭调试/登录

我只是使用Log4net设置了一个日志记录提供程序,并在测试时注意到DotNetOpenAuth也在记录消息.他们也必须使用log4net,很棒我每次有人使用openID登录时都不需要50次插入.

无论如何要把它关掉?

dotnetopenauth

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

设计发送电子邮件通知的问题

我有一个非常基本的问题,但解决方案可能有点复杂.

  1. 网站开发者如何发送电子邮件,例如忘记密码链接,注册消息和/或任何其他需要发送的通知.
  2. 开发人员是否将消息存储在SQL服务器中,这是一个单独的类,XML?

我正在使用Onion模型,我的SMTP接口在app.core中,但我发送邮件的基类位于infrastructure.backends中.我不希望我的应用程序服务依赖于后端,不确定这是错误的还是我是强迫症.

我使用Ninject作为我的IOC/DI.

c# asp.net asp.net-mvc-3

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

如何处理动作过滤器?

我有以下全局过滤器,ISiteValidation和ICacheService通过Windsor容器注入并设置为Transient,因此容器不会自动处理依赖项.当站点投入生产时,这将导致资源问题.那么人们正在做什么来正确处理注入过滤器的资源?两个接口都是IDisposable,但是当Action Filter超出范围并且容器将继续保持实现时,Dispose永远不会被调用.

public class SiteValidationAttribute : ActionFilterAttribute
{
    public ISiteValidation SiteValidation { get; set; }
    public ICacheService CacheService { get; set; }

    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        if (filterContext.RequestContext.HttpContext.Request.Url != null)
        {
            string host = filterContext.RequestContext.HttpContext.Request.Url.Host;
            try
            {
                string siteId = CacheService.Get("SiteId",
                                                 () =>
                                                 SiteValidation.GetSiteId(
                                                     host));
                var siteIdCookie = new HttpCookie("_site") {Value = siteId};
                filterContext.RequestContext.HttpContext.Response.Cookies.Add(siteIdCookie);
            }
            catch (Exception)
            {
                throw new HttpException(404, String.Format("This site'{0}' was not found", host));
            }
        }

        base.OnActionExecuted(filterContext);
    }
}
Run Code Online (Sandbox Code Playgroud)

dependency-injection castle-windsor asp.net-mvc-3 asp.net-mvc-4

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