小编Mar*_*ouk的帖子

使用Azure Power Shell将应用程序设置添加到现有Azure Web应用程序

我想编写一个使用azure power shell运行的脚本来自动添加Web应用程序配置

Azure> MyWebApp>应用程序设置>应用程序设置

它看起来像key ="value"

我写这个脚本

###########################
# MyApp Config Automation #
###########################

#Begin

$subscriptionName="MySubscriptionName"
$webSiteName="MyWebAppName"
$storageAccountName="StorageAccountName"
########################################
$userName = "myaccount@outlook.com"
$securePassword = ConvertTo-SecureString -String "mypass" -AsPlainText -Force
#####################################
$cred = New-Object System.Management.Automation.PSCredential($userName, $securePassword)
#####################################
Add-AzureAccount -Credential $cred 
Select-AzureSubscription -SubscriptionName $subscriptionName -Default
#####################################
Get-AzureWebsite -Name $webSiteName

#End
Run Code Online (Sandbox Code Playgroud)

但我知道上面的脚本只是获取我的Web应用程序,现在我需要访问MyWebApp>应用程序设置>应用程序设置并给出我的新应用程序设置的脚本文件/数组,并检查脚本是否有任何新的应用程序设置键它会将它添加到App Settings,如果有任何现有的键,它将覆盖它的值.什么是步骤或APIS或我能用天蓝色电源壳做到这一点?

编辑:此脚本可以自动创建新的Web应用程序并向其添加应用程序设置:

##############################################
# Creating website and Adding Configs Script #
##############################################

$webSiteName="mywebsite"
$storageAccountName="storageaccount"
$subscriptionName="mysubsc"
$userName = "myaccount"
$securePassword = ConvertTo-SecureString -String "mypass" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($userName, $securePassword) …
Run Code Online (Sandbox Code Playgroud)

powershell azure azure-powershell

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

我需要编写只返回整数的幂的方法

我需要在java中编写一个方法来返回只有整数的幂,我希望这个方法返回-1或者如果数字超过Integer.MAX_VALUE则触发异常:

我尝试了第一个简单的步骤:

public static int GetPower(int base, int power)
{
    int result = 1;

    for(int i = 1; i<=power; i++)
    {
        result *= base;
        if (result <  0 ) {
            break; // not very acurate
        }
    }
    if (result < 0 ) {
        return -1;
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

上面的方法是否准确,因为在调试后我发现当结果超过Integer.MAX_VALUE时它会转到负数,还是有另一种方法来处理这个?

java

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

在不使用IdentityServer的情况下,我想要一种方法来使用具有用户数据库的另一个ASP.NET MVC应用程序来验证WebApi应用程序

我有Asp.Net MVC项目有用户(我使用Asp.Net Identity 2),我有另一个Asp.Net WebApi服务.

我想保证对WebApi进行身份验证,只允许Asp.Net MVC用户访问端点,我不想将IdentityServer3用于此目的.

Asp.Net MVC Startup.Auth.cs:

public void ConfigureAuth(IAppBuilder app)
{
    // Configure the db context, user manager and signin manager to use a single instance per request
    app.CreatePerOwinContext(ApplicationDbContext.Create);
    app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
    app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);


    // Enable the application to use a cookie to store information for the signed in user
    // and to use a cookie to temporarily store information about a user logging in with a third party login provider
    // Configure the sign in cookie
    app.UseCookieAuthentication(new CookieAuthenticationOptions …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc oauth-2.0 asp.net-web-api asp.net-identity-2

6
推荐指数
0
解决办法
414
查看次数

检查共享目录权限 - C#

我想编写一个检查共享目录权限的代码,我检查多个解决方案但是在尝试获取本地目录权限时它运行良好但是当我为共享目录创建测试用例时它失败了.

我在这个问题中尝试了一些例子: SOF:check-for-directory-and-file-write-permissions-in-net

但它只适用于本地目录.

例如,我使用了这个类:

 public class CurrentUserSecurity
{
    WindowsIdentity _currentUser;
    WindowsPrincipal _currentPrincipal;

    public CurrentUserSecurity()
    {
        _currentUser = WindowsIdentity.GetCurrent();
        _currentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
    }

    public bool HasAccess(DirectoryInfo directory, FileSystemRights right)
    {
        // Get the collection of authorization rules that apply to the directory.
        AuthorizationRuleCollection acl = directory.GetAccessControl()
            .GetAccessRules(true, true, typeof(SecurityIdentifier));
        return HasFileOrDirectoryAccess(right, acl);
    }

    public bool HasAccess(FileInfo file, FileSystemRights right)
    {
        // Get the collection of authorization rules that apply to the file.
        AuthorizationRuleCollection acl = file.GetAccessControl()
            .GetAccessRules(true, true, typeof(SecurityIdentifier)); …
Run Code Online (Sandbox Code Playgroud)

.net c# acl access-control winforms

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

ASP.NET Core IOC:ASP0000 从应用程序代码调用“BuildServiceProvider”会导致创建单例服务的附加副本

我正在开发 .Net Core Web 应用程序,并在 Startup.cs 上安装并配置了 IdentityServer4,这里我从已在 IOC 中注册的服务加载令牌签名证书:

        builder.AddSigningCredential(services.BuildServiceProvider().
        GetService<ISecretStoreService>().
        TokenSigningCertificate().Result);
Run Code Online (Sandbox Code Playgroud)

完整代码如下:

public void ConfigureServices(IServiceCollection services)
{
    //....

        var builder = services.AddIdentityServer(options =>
            {
                options.IssuerUri = Configuration.GetValue<string>("IdSrv:IssuerUri"); ;
                options.PublicOrigin = Configuration.GetValue<string>("IdSrv:PublicOrigin"); ;
                options.Events.RaiseErrorEvents = true;
                options.Events.RaiseInformationEvents = true;
                options.Events.RaiseFailureEvents = true;
                options.Events.RaiseSuccessEvents = true;
                options.UserInteraction.LoginUrl = "/Account/Login";
                options.UserInteraction.LogoutUrl = "/Account/Logout";
                options.Authentication = new AuthenticationOptions()
                {
                    CookieLifetime = TimeSpan.FromHours(10),
                    CookieSlidingExpiration = true
                };
            })
        .AddConfigurationStore(options =>
        {
            options.ConfigureDbContext = b => b.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
        })
        .AddOperationalStore(options =>
        { …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection .net-core asp.net-core identityserver4

5
推荐指数
0
解决办法
1944
查看次数

如何通过特定用户的 Bearer 令牌访问与 S3 Bucket 连接的 AWS CloudFront(JWT 自定义身份验证)

我正在使用无服务器框架将无服务器堆栈部署到 AWS。我的堆栈由一些 lambda 函数、DynamoDB 表和 API 网关组成。

我使用所谓的lambda Authorizer来保护 API 网关。另外,我有一个可以生成令牌的自定义独立自托管身份验证服务。

因此,场景是用户可以从此服务(托管在 Azure 上的 IdentityServer4)请求令牌,然后用户可以使用不记名令牌向 API 网关发送请求,这样 API 网关将要求 lambda 授权者生成 iam 角色,如果令牌是正确的。所有这些都是有效的并且按预期工作。

以下是我的 serverless.yml 中 lambda 授权者定义的示例,以及我如何使用它来保护其他 API 网关端点:(您可以看到 addUserInfo 函数具有使用自定义授权者保护的 API)


functions:
    # =================================================================
    # API Gateway event handlers
    # ================================================================
  auth:
    handler: api/auth/mda-auth-server.handler

  addUserInfo:
     handler: api/user/create-replace-user-info.handler
     description: Create Or Replace user section
     events:
       - http:
           path: user
           method: post
           authorizer: 
             name: auth
             resultTtlInSeconds: ${self:custom.resultTtlInSeconds}
             identitySource: method.request.header.Authorization
             type: token
           cors:
             origin: '*'
             headers: ${self:custom.allowedHeaders}
Run Code Online (Sandbox Code Playgroud)

现在我想扩展我的 API,以便允许用户添加图像,所以我遵循了这种 …

amazon-s3 amazon-web-services oauth-2.0 amazon-cloudfront aws-lambda

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

在Android中如何知道当前通知ID以清除通知

现在在android中我把这个代码放在一个活动中,以便在按下按钮时显示通知.

static int notificationCount = 0;
Run Code Online (Sandbox Code Playgroud)

然后

 btnNotification.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Intent notificationIntent = new Intent(AlertsActivity.this,NotificationActivitty.class);
                    PendingIntent pIntent = PendingIntent.getActivity(AlertsActivity.this,notificationCount,notificationIntent,Intent.FLAG_ACTIVITY_NEW_TASK);

                    // Construct the notification
                    Notification.Builder nBuilder = new Notification.Builder(AlertsActivity.this);
                    nBuilder.setContentTitle("You Have a notification!");
                    nBuilder.setContentText("See Your Notification");
                    nBuilder.setSmallIcon(android.R.drawable.btn_star);
                    nBuilder.setContentIntent(pIntent);
                   nBuilder.addAction(android.R.drawable.stat_notify_call_mute, "go to", pIntent); // from icecream sandwatch - required api 16

                    // Build the notification
                    Notification noti = nBuilder.build(); // required api 16

                    //Send it to manager
                        NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
                        manager.notify(notificationCount++,noti);
                }
            }
    ); …
Run Code Online (Sandbox Code Playgroud)

notifications android android-intent notificationmanager android-notifications

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

在这种情况下,为什么处理DisposableObserver很重要

我正在使用干净的架构开发android项目.我有以下课程:

    public abstract class RxBaseInteractor<T, Params> {

  private final CompositeDisposable disposables;

  public RxBaseInteractor() {
    this.disposables = new CompositeDisposable();
  }

  abstract public Observable<T> buildUseCaseObservable(Params params);

  public void execute(DisposableObserver<T> observer, Params params) {
    Preconditions.checkNotNull(observer);
    final Observable<T> observable = this.buildUseCaseObservable(params)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread());
    addDisposable(observable.subscribeWith(observer));
  }

  public void dispose() {
    if (!disposables.isDisposed()) {
      disposables.dispose();
    }
  }

  protected void addDisposable(Disposable disposable) {
    Preconditions.checkNotNull(disposable);
    Preconditions.checkNotNull(disposables);
    disposables.add(disposable);
  }
}
Run Code Online (Sandbox Code Playgroud)

所以执行(..)获取DisposableObserver然后有一个dispose()方法被调用来处理这个observable.

在我的例子中,observable可能来自WebApi使用Realm进行改造或缓存.

现在在演示者onDestroy()中,我调用了interactor.dispose(),如:

 @Override public void destroy() {
        super.destroy();
        myInteractor.dispose();
    }
Run Code Online (Sandbox Code Playgroud)

从视图中调用之后调用:

    @Override public void onDestroy() {
    super.onDestroy();
    if …
Run Code Online (Sandbox Code Playgroud)

android dispose observable rx-java clean-architecture

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

如何使用Azure Function V2管理签名证书

我正在使用消费计划上的Azure Functions应用程序。Func App需要加载特定的签名证书。

在本地计算机上,我将证书设置为个人证书,并且一切正常。

在azure上发布后,出现此错误:

LocalMachine中有0个主题名称为cert.name的证书,MyUse脚本/ certificates /可以生成此证书

SO或什至在Azure Func文档中没有关于如何将证书与天蓝色函数一起使用都没有帮助。

任何人都有经验吗?

ssl certificate azure azure-functions

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

什么是 Android 中的 ART 和 DART

简单来说,Android 中的 ART(Android 运行时)和 DART 是什么,我在这里读到了它但我并不真正了解它的重要性和用法。

在我询问之前,我还在 Stackoverflow 中搜索了任何相关问题。

android dalvik android-runtime

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

使用 Azure DevOps 将 Azure Function(隔离进程)部署到 Azure 不起作用

目前,Microsoft 引入了一种处理 Azure 函数的新方法,称为隔离进程,它是在 .NET5 上运行 Azure 函数的唯一方法。

我正在尝试通过 Azure DevOps 将已在本地计算机上正确运行的函数应用程序部署到 Azure Func 应用程序。部署成功,但是功能不起作用。

首先在部署任务中我看不到 .NET 5,如下所示:

但我可以在此处的链接中看到支持 .NET 5 作为预览版:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-versions#languages

部署后,我可以看到以下错误:

但我将配置更改为:

该函数还显示了此错误:

我还可以从这里看到该函数已在 .NET 5 上运行:

所以不确定如何正确部署它。我知道隔离的进程功能只需要 azure 功能工具 + 运行命令行,所以不确定如何部署它,而且 Microsoft 没有任何关于如何部署它的教程或文档?

azure azure-devops azure-functions azure-function-app .net-5

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