小编bar*_*e.m的帖子

动态添加角色以授权控制器的属性

我需要启用我的管理员用户即时更改用户的访问权限,以便他们可以创建新角色并为这些角色添加权限.

我希望能够创建一个Authorize属性,以便在我的控制器类之上,我可以从数据库添加角色,这样我就不必在开发过程中"设置"角色,如[Authorize(Roles="Role1, Role2")]等.

所以像 [Authorize(Roles = GetListOfRoles()]

我发现了这个问题 - ASP.NET MVC授权用户有很多角色,它做了类似的事情,但也许有一种方法可以改变它,以便从数据库中获取权限/角色列表?

c# asp.net asp.net-mvc authorize-attribute asp.net-identity

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

由于缺少定义,在.net Core应用程序上构建失败

我正在尝试使用CLI构建我的.NET Core应用程序dotnet build,但每次我都会收到此错误:

'IConfigurationBuilder'不包含'AddEnvironmentVariables'的定义,并且没有可以找到接受类型'IConfigurationBuilder'的第一个参数的扩展方法'AddEnvironmentVariables'(你是否缺少using指令或汇编引用?)

这是我发生问题的ConfigureServices方法Startup.cs:

    public void ConfigureServices(IServiceCollection services)
    {
        var builder = new ConfigurationBuilder()
            .AddJsonFile("config.json")
            .AddEnvironmentVariables()
            .Build();

        services.AddEntityFrameworkSqlServer()
             .AddDbContext<MyContext>(options =>
                 options.UseSqlServer(builder["Data:MyContext:ConnectionString"]));

        services.AddIdentity<ApplicationUser, ApplicationRole>()
            .AddEntityFrameworkStores<MyContext>()
            .AddDefaultTokenProviders()
            .AddOpenIddictCore<Application>(config => config.UseEntityFramework());

        services.AddMvc();

        services.AddScoped<OpenIddictManager<ApplicationUser, Application>, CustomOpenIddictManager>();
    }
Run Code Online (Sandbox Code Playgroud)

看看这个例子,我发现我没有明显的错误Startup.cs.

更新 我的project.json文件:

{
  "compilationOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "dependencies": {
    "AspNet.Security.OAuth.Validation": "1.0.0-alpha1-*",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Hosting": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.StaticFiles": …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-core

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

在达到 JobScheduler 限制 100 后,WorkManager 将如何处理作业?

我在互联网上搜索了有关此主题的信息,但似乎没有人再遇到此问题。

还记得这个有趣的错误吗?

java.lang.IllegalStateException:超出 JobScheduler 100 作业限制。我们在 JobScheduler 中统计了 101 个 WorkManager 作业;我们的数据库中有 50 个跟踪的作业;我们的配置限制是 50。

原因:java.lang.IllegalStateException:应用程序可能无法安排超过 100 个不同的作业

好吧,尽管换了很多工作要做enqueueUniqueWork,但我的一些用户似乎仍然达到了这个限制。我的用例是供那些贫穷且没有网络连接的人离线做很多事情,从而创造大量工作来更新远程服务器上的资源。我在使用 FirebaseJobDispatcher 时从未遇到过这个问题(至少我没有意识到),有些人可能几天都没有信号,如果有人几周无法连接会发生什么?它将轻松创造数百个就业岗位。因此,出现了这个错误。

我的问题是,当达到限制时,这些工作会发生什么?它们只是被调度程序丢弃了吗?当我输入此内容时,我现在会丢失人们的数据吗?

更新

Android 版本:已确认 7.0、8.0、8.1,可能还有更多

工作管理器版本:2.3.0

java android android-jetpack android-workmanager

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

使用Unity.Mvc5注入依赖项时的多个控制器构造函数

我对依赖注入非常陌生,我刚刚设置了Unity.Mvc5,并且取得了一些成功.但是现在我遇到了控制器类中多个构造函数的问题.我已经有了处理我UserManager和以下教程的构造函数,我理解我需要另一个构造函数来实例化我的接口.但是当我这样做时,我收到以下错误:

OrganisationController类型有多个长度为1的构造函数.无法消除歧义.

来自我的控制器的片段:

    private IPush _pushMessage;

    // Here is the problem!
    public OrganisationController(IPush pushMessage)
    {
        _pushMessage = pushMessage;
    }

    public OrganisationController()
        : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
    {
    }

    public OrganisationController(UserManager<ApplicationUser> userManager)
    {
        UserManager = userManager;
        var provider = new DpapiDataProtectionProvider("MyApp");
        UserManager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(provider.Create("PasswordReset"));
    }

    public UserManager<ApplicationUser> UserManager { get; private set; }
Run Code Online (Sandbox Code Playgroud)

我的UnityConfig.cs如下:

public static class UnityConfig
{
    public static void RegisterComponents()
    {
        var container = new UnityContainer();

        container.RegisterType<IPush, PushMessage>();
        container.RegisterType<IController, OrganisationController>();
        container.RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>();
        container.RegisterType<DbContext, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc dependency-injection unity-container

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

连接到Heroku Postgres数据库时出现CertificateUnknown错误

所以,我在从SQL Server迁移到PostgreSQL的中间,我建设迁移期间的临时解决方案,让我的ASP.NET应用程序连接到我的Heroku Postgres数据库,并利用实体框架等.

到目前为止,我已经设法从pgAdmin III连接到数据库的Windows没有问题,但是当从ASP.NET应用程序连接时,我收到此错误:

CertificateUnknown:不接受服务器证书.链状态:已处理证书链,但终止于信任提供程序不信任的根证书..证书中不存在指定的主机名.

我仍然是heroku的新手,但是为什么我可以使用与我的ASP.NET应用程序相同的设置从pgAdmin连接它没有意义,但它在应用程序本身中不起作用.

完整堆栈跟踪:

[ClientAlertException:CertificateUnknown:不接受服务器证书.链状态:已处理证书链,但终止于信任提供程序不信任的根证书..证书中不存在指定的主机名.]
TlsClientStream.TlsClientStream.SendAlertFatal(AlertDescription description,String message)+44
TlsClientStream.TlsClientStream.ParseCertificateMessage(Byte [] buf,Int32&pos)+1359
TlsClientStream.TlsClientStream.TraverseHandshakeMessages()+ 415
TlsClientStream.TlsClientStream.GetInitialHandshakeMessages(Boolean allowApplicationData)+336
TlsClientStream.TlsClientStream.PerformInitialHandshake(String hostName,X509CertificateCollection clientCertificates,RemoteCertificateValidationCallback remoteCertificateValidationCallback,Boolean checkCertificateRevocation)+198

[IOException:TlsClientStream.ClientAlertException:CertificateUnknown:不接受服务器证书.链状态:已处理证书链,但终止于信任提供程序不信任的根证书..证书中不存在指定的主机名.在TlsClientStream.TlsClientStream.SendAlertFatal(AlertDescription描述,字符串消息)在TlsClientStream.TlsClientStream.ParseCertificateMessage(字节[] buf中,的Int32&POS)在TlsClientStream.TlsClientStream.TraverseHandshakeMessages()在TlsClientStream.TlsClientStream.GetInitialHandshakeMessages(布尔allowApplicationData)在TlsClientStream.TlsClientStream .PerformInitialHandshake(字符串主机名,X509CertificateCollection clientCertificates,RemoteCertificateValidationCallback remoteCertificateValidationCallback,布尔checkCertificateRevocation)]
TlsClientStream.TlsClientStream.PerformInitialHandshake(字符串主机名,X509CertificateCollection clientCertificates,RemoteCertificateValidationCallback remoteCertificateValidationCallback,布尔checkCertificateRevocation)289
Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout超时)1372
Npgsql.NpgsqlConnector .开(NpgsqlTimeout超时)314
Npgsql.NpgsqlConnection.OpenInternal()461
Npgsql.NpgsqlConnection.Open()4
Npgsql的 .NpgsqlServices.UsingPostgresDBConnection(NpgsqlConnection连接,Action`1动作)+162
Npgsql.NpgsqlServices.GetDbProviderManifestToken(DbConnection连接)+99
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection连接)+87

[ProviderIncompatibleException:提供程序未返回ProviderManifestToken字符串.]
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)+271
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices,DbConnection connection) +27

[ProviderIncompatibleException:访问数据库时出错.这通常意味着与数据库的连接失败.检查连接字符串是否正确,以及是否使用了相应的DbContext构造函数来指定它或在应用程序的配置文件中找到它.有关DbContext和连接的信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=386386.有关失败的详细信息,请参阅内部异常.]
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices,DbConnection connection)+89
System.Data.Entity.Infrastructure.<> c__DisplayClass1.b__0(Tuple 2.GetOrAdd( TKey键,Func 2.GetValue(TInput输入)+123 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()+ 627 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)+18 System.Data.Entity .Internal.Linq.InternalSet 1.get_InternalContext()15 System.Data.Entity.Infrastructure.DbQuery 1源,表达1.CallBeginDelegate(AsyncCallback的回调,对象callbackState)14个 System.Web.Mvc.Async.WrappedAsyncResultBase 1个过滤器, ActionDescriptor actionDescriptor,IDictionary的1.CallBeginDelegate(AsyncCallback的回调,对象callbackState)+14 System.Web.Mvc.Async.WrappedAsyncResultBase 1.CallBeginDelegate(AsyncCallback的回调,对象callbackState)+30 的System.Web .Mvc.Async.WrappedAsyncResultBase 1.CallBeginDelegate(AsyncCallback callback,Object callbackState)+20 System.Web.Mvc.Async.WrappedAsyncResultBase …

asp.net postgresql ssl heroku heroku-postgres

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

Rails 范围与方法值比较

所以我对 Rails 还很陌生,ActiveRecord我需要一个范围来在Client实体之间进行过滤。基本上范围应该返回Client客户端当前状态等于某个状态对象的所有记录。

这是通过获取客户端的上一次计算state_change,然后拉着那个state_changefrom_state是一个State对象。

我已经定义了一个方法来current_state在 Rails 控制台中返回然而,当我测试它时出现Client.current_state(Client.last)此错误:

NameError: undefined local variable or method 'state_changes for #<Class:0x0000000685eb88>但是Client.last.state_changes在控制台中运行时它工作正常。

我的客户.rb

class Client < ActiveRecord::Base
  has_and_belongs_to_many               :users
  belongs_to                            :industry
  belongs_to                            :account
  has_many                              :contacts
  has_many                              :state_changes
  belongs_to                            :head,          class_name: "Client"
  has_many                              :branches,      class_name: "Client", foreign_key: "head_id"
  has_many                              :meetings,      through: :contacts
  has_many                              :sales,         through: :meetings

  scope :prospects, -> (client) { where(Client.current_state(client): State.PROSPECT_STATE) }

  def self.has_at_least_one_sale? …
Run Code Online (Sandbox Code Playgroud)

ruby activerecord scope ruby-on-rails

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

如何编写MVC Web Api Post方法进行文件上传

我正在按照教程从android上传文件到服务器,但我似乎无法在服务器端获得正确的代码.有人可以帮我编写可以使用android java上传器的Web Api post方法吗?我当前的web api控制器类看起来像这样:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;

namespace WSISWebService.Controllers
{
    public class FilesController : ApiController
    {
        // GET api/files
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/files/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/files
        public string Post([FromBody]string value)
        {
            var task = this.Request.Content.ReadAsStreamAsync();
            task.Wait();
            Stream requestStream = task.Result;

            try
            {
                Stream …
Run Code Online (Sandbox Code Playgroud)

java asp.net-mvc android http-post httprequest

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

无法发布.NET Core应用程序(不支持的运行时)

我正在使用.net核心构建API,我在发布期间遇到了这个问题:

The project being published does not support the runtime 'dnx-clr-win-x86.1.0.0-rc2-20221'
Run Code Online (Sandbox Code Playgroud)

我看到了这个问题的GitHub以及这一个,我没有接近的解决方案.这是我的更新 project.json文件:

  {
  "compilationOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "dependencies": {
    "AspNet.Security.OAuth.Validation": "1.0.0-alpha1-*",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Hosting": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-*",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-*",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-*",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-*",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-*",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-*",
    "OpenIddict.Core": "1.0.0-*",
    "OpenIddict.EF": "1.0.0-*"
  },

  "frameworks": {
    "net451": {
      "frameworkAssemblies": {
        "System.ComponentModel": { "type": "build" }
      }
    },

    "netcoreapp1.0": {
      "dependencies": …
Run Code Online (Sandbox Code Playgroud)

c# asp.net dnx asp.net-core dotnet-cli

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

无法从visual studio(或任何实际位置)连接到AWS EC2

我有一台AWS服务器(带有IIS的MS SQL SERVER EXPRESS 2008 R2),弹性IP为54.214.8.111,安全组配置了HTTP,MS SQL和FTP,我可以使用rdp文件连接到远程虚拟机亚马逊在控制台给你.

然而,当我尝试通过visual studio连接来测试数据库是否正常工作时,它给了我"登录失败的用户'dbuser'错误.我的SQL Server上有一个名为dbuser的用户(当然在服务器端)完全访问权限等.我也无法连接到服务器上的ftp,尽管所有指南和帮助文档.似乎只是阻止我的连接.我在多台计算机上尝试过同样的事情.

似乎所有东西都配置正确,除了我怀疑服务器实例.

有人可以帮忙吗?PS我是Web开发的新手,这是我的第一台AWS EC2服务器.

[更新]我刚尝试在不同的位置创建一个新实例,同样的错误,也许我不知道如何在EC2上配置SQL Server?

connection amazon-ec2 sql-server-2008 amazon-web-services visual-studio

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

无法将ASP.NET Core应用程序部署到IIS - Bad Gateway

一直在努力让这个工作,我有一个标准的.NET Core API,我想在远程IIS服务器上托管,问题是大多数教程是针对ASP.NET 5/vNext并且不解释会发生什么一旦你运行你的dotnet publish.我的绑定是正确的,但我不确定我是否指向正确的文件夹.

在我的输出文件夹中,我有发布wwwroot以及config.json一些其他json文件.当我将IIS指向wwwroot文件夹时,我得到:

502 - Web服务器在充当网关或代理服务器时收到无效响应.

如果我尝试将其指向任何其他文件夹,我会得到404s.我安装了HttpPlatformHandler 1.2.我的project.json情况如下:

  {
  "compilationOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot"
    ]
  },

  "dependencies": {
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-*",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0-*",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-*",
    "Microsoft.AspNetCore.Hosting": "1.0.0-*",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-*",
    "Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-*",
    "Microsoft.AspNetCore.Mvc": "1.0.0-*",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-*",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-*",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*",
    "Microsoft.Extensions.Logging.Console": "1.0.0-*",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-*",
    "OpenIddict.Core": "1.0.0-*",
    "OpenIddict.EF": "1.0.0-*",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002700" …
Run Code Online (Sandbox Code Playgroud)

asp.net iis asp.net-core dotnet-cli

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

Android锁定线程中的CountDownLatch

我刚开始玩CountDownLatch我的Android应用程序.目前我正在尝试向Volley我的api 发出两个请求,并等待数据被检索并存储,然后再继续执行线程.

这是我的代码示例:

    // new CountDownLatch for 2 requests
    final CountDownLatch allDoneSignal = new CountDownLatch(2);

    transactions.getResourcesForRealm(Contact.class, "", new ICallBack<Contact>() {
        @Override
        public void onSuccess(ArrayList<Contact> resources, String resourceId) {
            transactions.createRealmObject(resources, Contact.class);

            allDoneSignal.countDown();
        }

        @Override
        public void onFail(ArrayList<Contact> resources) {

        }
    });

    transactions.getResourcesForRealm(Meeting.class, "", new ICallBack<Meeting>() {
        @Override
        public void onSuccess(ArrayList<Meeting> resources, String resourceId) {
            transactions.createRealmObject(resources, Meeting.class);

            allDoneSignal.countDown();
        }

        @Override
        public void onFail(ArrayList<Meeting> resources) {

        }
    });

    try {
        allDoneSignal.await();
        // continue executing code
        // ...
    } catch …
Run Code Online (Sandbox Code Playgroud)

java multithreading android countdownlatch android-volley

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

带计数的SQL Server查询返回null或无结果

我有以下查询:

SELECT Centre.Centre_Name, Count(Shop_No) AS shopcount FROM Centre INNER JOIN Space ON Centre.Centre_Name = Space.Centre_Name GROUP BY Centre.Centre_Name
Run Code Online (Sandbox Code Playgroud)

我需要它从中心表返回中心列表以及从空间表返回每个中心的商店数量.因此,它计算Space表中shop_no的数量,并返回中心名称加上每个中心的商店数量.但是,如果某个中心在Space表中尚未分配任何商店,则它不会从Center表中返回中心名称.如果空间表中不存在中心,我需要它返回0.

请指教 :)

sql sql-server

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

使用 Razor C# 将对象动态添加到 javascript 数组

好的,所以我在 C# 中使用 MVC4,我必须用视图模型中的元素填充 javascript 数组。我正在尝试动态填充 Chart.js 饼图。这是我的示例代码:

<script src="~/Scripts/Chart.js"></script>
<script type="text/javascript">

    var data = [
        {
            value: 30,
            color: "#F38630"
        },
        {
            value: 50,
            color: "#E0E4CC"
        },
        {
            value: 100,
            color: "#69D2E7"
        }
        ]
    //Get the context of the canvas element we want to select
    var ctx = document.getElementById("myChart").getContext("2d");
    var myNewChart = new Chart(ctx).Pie(data);
    //Get context with jQuery - using jQuery's .get() method.
    var ctx = $("#myChart").get(0).getContext("2d");
    //This will get the first returned node in the jQuery collection.
    var …
Run Code Online (Sandbox Code Playgroud)

javascript c# arrays razor asp.net-mvc-4

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