我使用Asp.Net Identity来控制我的应用程序的授权.现在,我需要这样做:如果用户在30分钟内没有运行,请跳转到登录页面,当他登录时不选择"isPersistent"复选框.并且,如果他选择"isPersistent"复选框,请将Cookie的到期日期设置为14天.我尝试通过像这样更改Startup.Auth.cs来做到这一点:
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
SlidingExpiration = true,
CookieName = WebHelpers.ConstStrings.AUTHCOOKIESNAME
});
}
Run Code Online (Sandbox Code Playgroud)
和SignIn代码如下:
private async Task SignInAsync(User user, bool isPersistent)
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
if (isPersistent)
{
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
}
else
{
AuthenticationManager.SignIn(new AuthenticationProperties() { ExpiresUtc = new DateTimeOffset(DateTime.UtcNow.AddMinutes(30)) }, identity);
}
}
Run Code Online (Sandbox Code Playgroud)
但是我发现当用户没有选择isPersistent复选框时,cookies的到期日期已经是"会话",而不是当前时间加上30分钟.
使用像之后的代码时的cookie状态,所以'记住我'复选框无法正常工作.:(.
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
ExpireTimeSpan = …Run Code Online (Sandbox Code Playgroud) 我发布了一个应用程序,其中一个基本功能是允许用户拍照,然后将该照片保存在其外部存储的特定文件夹中.
一切似乎都运行正常,但我现在有两个报告声称在拍照后,点击"完成"退出相机(并返回活动),应用程序被强制关闭,带来用户回到主屏幕.
这发生在Samsung Nexus S和Galaxy Tab上.下面我发布了我的代码,以显示我设置我的意图以及如何在onActivityResult()中处理保存和显示照片.任何关于在点击"完成"退出相机应用程序后可能导致崩溃的指导,将不胜感激!
同样,这似乎在大多数设备上都能正常工作,但我想知道它们是否是一种更有效,更通用的方法.谢谢
我如何解雇相机意图
case ACTION_BAR_CAMERA:
// numbered image name
fileName = "image_" + String.valueOf(numImages) + ".jpg";
output = new File(direct + File.separator + fileName); // create
// output
while (output.exists()) { // while the file exists
numImages++; // increment number of images
fileName = "image_" + String.valueOf(numImages) + ".jpg";
output = new File(outputFolder, fileName);
}
camera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
uriSavedImage = Uri.fromFile(output); // get Uri of the output
camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); //pass in Uri to camera …Run Code Online (Sandbox Code Playgroud) 是什么之间的差异nuget包HangFire.AspNetCore和迟发型和HangFire.core?
似乎我可以将 hangfire 与 ASP .NET MVC Core 项目一起使用,仅包含HangFire1.6.21 包。请参阅我的项目中使用的以下包:
那这个包HangFire.AspNetCore有什么用呢?
我正在 Ubuntu 上使用 Visual Studio Code,并使用以下命令添加了软件包:
dotnet add package Hangfire
dotnet add package Hangfire.AspNetCore
Run Code Online (Sandbox Code Playgroud) 如何将 SignalR 集线器上下文传递给 ASP .NET Core 2.1 上的 Hangfire 作业?
似乎由于将参数传递给 Hangfire 是通过序列化/反序列化完成的,因此 Hangfire 似乎很难重建 SignalR 集线器上下文。
我使用以下方法安排工作(在我的控制器中):
BackgroundJob.Schedule(() => _hubContext.Clients.All.SendAsync(
"MyMessage",
"MyMessageContent",
System.Threading.CancellationToken.None),
TimeSpan.FromMinutes(2));
Run Code Online (Sandbox Code Playgroud)
然后 2 分钟后,当作业尝试执行时,出现错误:
Newtonsoft.Json.JsonSerializationException:无法创建 Microsoft.AspNetCore.SignalR.IClientProxy 类型的实例。类型是接口或抽象类,不能被实例化。
任何的想法?
更新 1
我最终使用了 Startup.cs 中定义的静态上下文,并从 Configure() 分配
hbctx = app.ApplicationServices.GetRequiredService<IHubContext<MySignalRHub>>();
Run Code Online (Sandbox Code Playgroud)
所以现在 Hangfire 安排了一个使用静态上下文的集线器助手:
BackgroundJob.Schedule(() => new MyHubHelper().Send(), TimeSpan.FromMinutes(2));
Run Code Online (Sandbox Code Playgroud)
并且集线器助手获取上下文 Startup.hbctx
即使这有效,它也有点臭
更新 2
我也尝试在没有构造函数注入的情况下使用Access SignalR Hub 中的方法:
我的后台作业调度变成了:
BackgroundJob.Schedule(() => Startup.GetService().SendOutAlert(2), TimeSpan.FromMinutes(2));
但是这一次,当我到达上述行时,我有一个例外:
执行请求 System.ObjectDisposedException 时发生未处理的异常:无法访问已处理的对象。对象名称:'IServiceProvider'。
更新 3
谢谢大家。解决方案是创建一个助手,通过其构造函数通过 DI 获取集线器上下文,然后使用 hangfire 将助手方法 Send …
在更改密码页面中,我们有这个代码,所以如果我们想要将密码策略更改为"StrongPolicy",我们有办法还是默认情况下?
我们还可以将其改为弱政策吗?
我读过MSDN但找不到它.
Membership mu ;
mu=Membership.GetUser(txtUserName.Text);
mu.UnlockUser();
var newPass= mu.ResetPassword();
mu.ChangePassword(newPass,TxtPassword.Text);
Run Code Online (Sandbox Code Playgroud) 我能够使用TestServer进行集成测试,并且我可以通过在ConfigureTestServices类中替换为模拟类来手动模拟任何 DI 注入类中的方法,如下所示:
var webHostBuilder =
new WebHostBuilder()
.UseEnvironment("Testing")
.UseContentRoot(projectDir)
.ConfigureTestServices(s =>
{
s.TryAddTransient(IMyClass, MyMockMyClass);
})
.UseStartup<Startup>();
Run Code Online (Sandbox Code Playgroud)
哪里MyMockMyClass是 的替换MyClass,目的是替换方法(例如:)Method1。
是否可以选择使用最小起订量Mock.Of<MyClass>快速替换 my Method1,而无需创建新类MyMockMyClass?就像是 :
var mymock = Mock.Of<IMyClass>();
Mock.Get(mymock ).Setup(m => m.Method1(It.IsAny<string>()).Returns(value: whatever);
Run Code Online (Sandbox Code Playgroud)
然后以某种方式使用这种mymock与线s.TryAddTransient(IMyClass, ...在ConfigureTestServices上面的代码?
解决方案应该很简单,但仍然在苦苦挣扎.如何反转分组符号,如括号,括号,大括号,...
我的字符串是这样的: Lorem ipsum dolor )sit amet(, consectetur ]adipiscing[ elit
我希望输出为 Lorem ipsum dolor (sit amet), consectetur [adipiscing] elit
关键是如果我在多次传递中逐个符号地转换符号,它会被转换两次:
text = text.Replace('[', ']');
text = text.Replace(']', '[');
text = text.Replace('(', ')');
text = text.Replace(')', '(');
Run Code Online (Sandbox Code Playgroud)
结果是 Lorem ipsum dolor (sit amet(, consectetur [adipiscing[ elit
如何一次转换文本?