小编Sco*_*son的帖子

ASP.NET Identity AuthenticationManager与SignInManager和cookie过期

使用AuthenticationManager SignIn而不是使用SignInManager PasswordSignIn/SignIn有什么区别?我有一个使用SignInManager的实现,并将我的cookie过期设置为30天,但似乎我的网络应用程序将在30天之前随机过期我的cookie.使用SignInManager实现会导致这种情况吗?我应该使用AuthenticationManager实现吗?

开箱即用的示例代码显示了这样的登录,但我也看到了其他使用AuthenticationManager实现的示例.

var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
Run Code Online (Sandbox Code Playgroud)

这是我的启动配置.

            app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            ExpireTimeSpan = TimeSpan.FromDays(30),
            LoginPath = new PathString("/signin"),
            Provider = new CookieAuthenticationProvider
            {
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<AppUserManager, AppUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            }
        });
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
        app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
        app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
Run Code Online (Sandbox Code Playgroud)

asp.net cookies asp.net-identity

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

FileResult缓冲到内存

我试图通过控制器ActionResult返回大文件,并实现了如下自定义FileResult类.

    public class StreamedFileResult : FileResult
{
    private string _FilePath;

    public StreamedFileResult(string filePath, string contentType)
        : base(contentType)
    {
        _FilePath = filePath;
    }

    protected override void WriteFile(System.Web.HttpResponseBase response)
    {
        using (FileStream fs = new FileStream(_FilePath, FileMode.Open, FileAccess.Read))
        {
            int bufferLength = 65536;
            byte[] buffer = new byte[bufferLength];
            int bytesRead = 0;

            while (true)
            {
                bytesRead = fs.Read(buffer, 0, bufferLength);

                if (bytesRead == 0)
                {
                    break;
                }

                response.OutputStream.Write(buffer, 0, bytesRead);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我遇到的问题是整个文件似乎被缓冲到内存中.我需要做些什么来防止这种情况发生?

c# asp.net-mvc fileresult

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

忽略 AJAX 请求的 ASP.NET URL 重写规则

我将如何创建强制小写 URL 的 URL 重写规则,除非请求是 AJAX 请求,即标头 X-Requested-With 具有 XMLHttpRequest 的值?

asp.net iis ajax url-rewriting

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