小编Fer*_*ndo的帖子

使用 Owin + OAuth + Google 在 ExternalLogin 上从 HTTP 重定向到 HTTPS

我的应用程序托管使用ARR将所有页面重定向到 HTTPS。

问题在于它的配置方式,ASP.Net MVC 理解请求是 HTTP,甚至是 HTTPS。

当我检查转到 google 身份验证的 URL 时,它是这样的:

&redirect_uri=http%3A%2F%mydomain.com\signing-google

我正在尝试重定向到谷歌,将“手动”更改为 HTTPS。

我试过这个:

public class ChallengeResult : HttpUnauthorizedResult
{
   ...

    public override void ExecuteResult(ControllerContext context)
    {
        var properties = new AuthenticationProperties { RedirectUri = RedirectUri };
        if (UserId != null)
            properties.Dictionary[XsrfKey] = UserId;

        var owin = context.HttpContext.GetOwinContext();

        owin.Request.Scheme = "https"; //hotfix

        owin.Authentication.Challenge(properties, LoginProvider);
    }
}
Run Code Online (Sandbox Code Playgroud)

和这个:

 app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId = Secrets.GoogleClientId,
                ClientSecret = Secrets.GoogleClientSecret,
                Provider = new GoogleOAuth2AuthenticationProvider()
                {
                    OnApplyRedirect = async context => …
Run Code Online (Sandbox Code Playgroud)

c# google-authentication owin asp.net-mvc-5

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

有限状态机和封闭

最近在我的工作中我“被迫”学习正确编程。我正在阅读很多 terns、DDD、TDD 等。推荐书籍“Clean Code”和“Refactoring to Patterns”,因为它们非常好。

最后,这让我拿起了一些我按时实现的游戏原型,并尝试在正确应用 OOP 的情况下重做,只是按照我的直觉(没有研究任何东西)。

在尝试为这些游戏实现有限状态机时,我遇到了几个问题。

public class StateMachine
{
    private IState _globalState;
    private IState _currentState;
    private readonly List<IState> _previousStates;

   public StateMachine(IState globalState, IState currentState)
    {
       _globalState = globalState;
       _currentState = currentState;
       _previousStates = new List<IState>();
    }

    public void Execute()
    {
        if (_globalState != null)
            _globalState.Update();
        if (_currentState != null)
            _currentState.Update();
    }

    public void ChangeState(IState state)
    {
        _previousStates.Add(_currentState);
        _currentState.Exit();
        _currentState = state;
        _currentState.Enter();
    }

    public void BackToPreviousStates()
    {
        _currentState.Exit();
        _currentState = _previousStates[_previousStates.Count-1];
        _previousStates.Remove(_currentState);
        _currentState.Enter();
    }

    public …
Run Code Online (Sandbox Code Playgroud)

c# state design-patterns

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