小编Jia*_*nYA的帖子

扩展Roles表后,实体类型IdentityRole不是当前上下文的模型的一部分

我将由实体框架创建的AspNetRoles扩展为如下所示:

public class AspNetRoles:IdentityRole
{
        public AspNetRoles() : base() { }
        public String Label { get; set; }
        public String ApplicationId { get; set; }
        public AspNetApplications Application { get; set; }

        public static readonly String SystemAdministrator = "SystemAdministrator";
}
Run Code Online (Sandbox Code Playgroud)

我知道,因为我已经扩展了identityrole表,所以必须对usermanager进行更改。这是我所做的:

public class ApplicationUserManager : UserManager<ApplicationUser>
{
    public ApplicationUserManager(IUserStore<ApplicationUser> store)
        : base(store)
    {
    }

    public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) 
    {
        var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
        // Configure validation logic for usernames
        manager.UserValidator = new UserValidator<ApplicationUser>(manager)
        {
            AllowOnlyAlphanumericUserNames …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc entity-framework

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

.net core 重定向到路由结果将 %2f 添加到 url

这是我的路由项目:

context.Result = new RedirectToRouteResult(new RouteValueDictionary(new {area="Identity", controller = "Account / Login", action = "Index" }));
Run Code Online (Sandbox Code Playgroud)

当应用程序启动时,这就是我在 url 中得到的内容:

http://localhost:62527/Identity/Account%2FLogin

如何从我的网址中删除 %2f?

c# asp.net-core-mvc asp.net-core

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

jquery .show()立即隐藏

这可能是一个简单的解决方案的问题,但我现在已经坚持了一段时间.我有一个按钮,一旦文本框被填充,将使用Jquery加载pdf.但是,在我的测试中,只要单击按钮,模态就会出现并消失.我已经把它剃掉了以使div首先出现并且同样的事情发生了.它可能是我的代码的东西,或者它是多少脚本被调用?

HTML

<form>
    <p>Key number : <input type="text" name="keynumber" /></p>
    <p><button id="submit" class="retrievedoc" type="submit" >Submit</button></p>
</form>
<div id="pdf-dialog">
    <p>TEST</p>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

.pdf-dialog{display:none;}
Run Code Online (Sandbox Code Playgroud)

JQuery的

$('.retrievedoc').on('click', function() {
    $("#pdf-dialog").show();
    /**$(".pdf-dialog").dialog({
            title: 'Document',
            width: 500,
            height: 800,
            draggable: false,
            modal: true,
            dialogClass: "readpdf-dialog",
            buttons: [{
                text: 'Close',
                click: function() {
                    $(this).dialog('close');
                }
            }] 
        });
    **/
});
Run Code Online (Sandbox Code Playgroud)

这就是我在页面底部安排脚本的方法

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/bootstrap.min.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<!-- Include all compiled plugins (below), or include individual …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

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

ASP.NET Core 2.1区域路由无法正常工作

我的新区域有这个文件夹结构

在此输入图像描述

这是我在启动时设置它的方式:

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");

    routes.MapRoute(
      name: "areas",
      template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
    );
});
Run Code Online (Sandbox Code Playgroud)

这就是我创建basecontroller的方法

namespace App.Areas.Applications.Controllers
{
    [Area("Applications")]
    [Authorize]
    public abstract class ApplicationsBaseController : Controller
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

我的ApplicationsController然后继承BaseController

但是,当我设置这样的链接时

<li class="nav-item"><a asp-area="Applications" asp-controller="Applications" asp-action="Index" class="nav-link">Applications</a></li>
Run Code Online (Sandbox Code Playgroud)

这是我的网址https:// localhost:44338/Applications?area = Applications中显示的链接,我找不到页面.

在设置我的区域时我错过了什么?

编辑:

当我在[区域("应用程序")]之后添加[路径("应用程序/ [控制器]")]时,出现此错误

处理请求时发生未处理的异常.AmbiguousActionException:匹配多个动作.以下操作匹配路由数据并满足所有约束:

App.Areas.Applications.Controllers.ApplicationsController.Index(App)App.Areas.Applications.Controllers.ApplicationsController.Create(App)App.Areas.Applications.Controllers.ApplicationsController.NewRole(App)

c# asp.net .net-core asp.net-core

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

Jwt无法提供给有效的发行人或受众

这是我的令牌解码器。当我尝试对其进行解码时,我的主体最终为空,从而导致此错误:

'IDX10208:无法验证受众。validationParameters.ValidAudience为null或空白,validationParameters.ValidAudiences为null。

当我解码令牌以进行检查时

“ nbf”:1539167980,“ exp”:1539168580,“ iat”:1539167980,“ iss”:“ http:// localhost:55260 ”,“ aud”:“ http:// localhost:55260

这也是我的令牌生成器在其上运行的主机。为什么委托人引起问题?

public class DecodeToken
{
    private IConfiguration configuration;
    public DecodeToken(IConfiguration configuration)
    {
        this.configuration = configuration;
    }

    public AuthenticationDto Decode(String Input)
    {
        var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JwtAuthentication:SecurityKey"]));
        var handler = new JwtSecurityTokenHandler();
        var tokenSecure = handler.ReadToken(Input) as SecurityToken;
        var validations = new TokenValidationParameters
        {
            ValidateIssuerSigningKey = true,
            IssuerSigningKey = key,
            ValidateIssuer = true,
            ValidateAudience = true,
            ValidateLifetime = false
        };
        SecurityToken securityToken;
        var principal = handler.ValidateToken(Input, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net jwt asp.net-core-mvc asp.net-core

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

ASP.NET Core 2.1 如何将变量传递给 TypeFilter

我创建了这个类型过滤器,它应该采用 2 个变量,以便将其发送到链接到过滤器的方法。但是,我无法附加两个变量以使其运行。

public class RolesFilterAttribute : TypeFilterAttribute
{
    public RolesFilterAttribute() : base(typeof(RolesFilterAttributeImpl))
    {

    }

    private class RolesFilterAttributeImpl : IActionFilter
    {
        private readonly ValidateRoleClient validateRoleClient;
        private string Role;
        private string SecretKey;
        public RolesFilterAttributeImpl(string Role, string SecretKey, ValidateRoleClient validateRoleClient)
        {
            this.validateRoleClient = validateRoleClient;
            this.Role = Role;
            this.SecretKey = SecretKey;
        }

        public void OnActionExecuted(ActionExecutedContext context)
        {
            if (context.HttpContext.Request.Cookies["Token"] != null || context.HttpContext.Request.Cookies["RefreshToken"] != null)
            {
                TokenViewModel tvm = new TokenViewModel
                {
                    Token = context.HttpContext.Request.Cookies["Token"],
                    RefreshToken = context.HttpContext.Request.Cookies["RefreshToken"]
                };
                ValidateRoleViewModel vrvm = new …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc asp.net-core-mvc asp.net-core

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

NLog在应用程序设置中使用连接字符串名称

我有一个如下所示的NLog数据库目标:

<target xsi:type="Database" name="database"
      connectionString="Server=.\SQLEXPRESS;Database=ApplicationOne;Trusted_Connection=True;MultipleActiveResultSets=true;User Id=User0101;Password=PW0101"   
      commandText="INSERT INTO [SchemaOne].[EventLogs](Id, Message, Level, Logger )VALUES(NewID(), @Message, @Level, @Logger)">
  <parameter name="@Message" layout="${message}" />
  <parameter name="@Level" layout="${level}" />
  <parameter name="@Logger" layout="${logger}" />
</target>
Run Code Online (Sandbox Code Playgroud)

是否可以从我的appsettings中更改connectionString以使用connectionStringName?

我的appsettings称为dssettings.json,它包含此处的连接详细信息:

"DatabaseConfiguration": {
    "DatabaseName": "ApplicationOne",
    "ConnectionName": "DefaultConnection",
    "ConnectionString": "Server=.\\SQLEXPRESS;Database=ApplicationOne;Trusted_Connection=True;MultipleActiveResultSets=true;User Id=User0101;Password=PW0101" 
  },
Run Code Online (Sandbox Code Playgroud)

asp.net logging nlog asp.net-core

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

EF Core 2.2 新迁移不断删除和重新创建种子数据

每当我创建新的迁移时,由于某种原因,我的种子数据总是被删除并重新创建。我怎样才能防止这种情况发生?

这似乎是 EF Core 2.1 中的一个错误,但据称已在 2.2 中修复,但该问题仍然存在。

这是我的 OnModelCreating:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
    Application application = new Application
    {
        Id = Guid.NewGuid().ToString(),
        Name = "APPONE",
        Description = "APPONE",
        TagColor = "#fb3640",
        IsActive = true,
        CreatedOn = DateTime.Now,
        UpdatedOn = DateTime.Now
    };

    User user = new User
    {
        Id = "223862af-978e-41a9-90ca-fda4b0f49c77",
        UserName = "system@managementstudio.com",
        NormalizedUserName = "SYSTEM@MANAGEMENTSTUDIO.COM",
        Email = "system@managementstudio.com",
        NormalizedEmail = "SYSTEM@MANAGEMENTSTUDIO.COM",
        SecurityStamp = "42032b8b-4581-46cf-8c56-a53e155176a3",
        PhoneNumber = "1234567890",
        FirstName = "System",
        LastName = "Administrator",
        ConcurrencyStamp = …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework entity-framework-core .net-core asp.net-core

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

CodeIgniter REST API 基本身份验证不起作用

我正在尝试在我的网站上集成 REST 服务。我正在使用这个https://github.com/chriskacerguis/codeigniter-restserver示例。到目前为止,我能够成功调用所需的数据。但是,当我想为其添加授权并尝试从 Postman 访问它时,我收到此错误:

{
  "status": false,
  "error": "Unauthorized"
}
Run Code Online (Sandbox Code Playgroud)

如果我删除身份验证,它会再次工作。有谁知道这是一个错误还是我遗漏了什么?这是我的配置:

-------------------------------------------------------------------------
| REST Login
|--------------------------------------------------------------------------
|
| Set to specify the REST API requires to be logged in
|
| FALSE     No login required
| 'basic'   Unsecured login
| 'digest'  More secured login
| 'session' Check for a PHP session variable. See 'auth_source' to set the
|           authorization key
|
*/
$config['rest_auth'] = 'basic';

|--------------------------------------------------------------------------
| REST Login Usernames
|--------------------------------------------------------------------------
|
| Array of usernames and …
Run Code Online (Sandbox Code Playgroud)

php rest codeigniter

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

如果modelstate无效,则Action Filter不会运行

我正在尝试构建一个自定义动作过滤器,它应该拦截模型状态并根据当前状态(有效或无效)执行某些操作.但是,在做了一些检查之后,我意识到只有当modelstate已经有效时才会运行动作过滤器.如果存在输入视图模型的所有条目.

一个例子是我的身份验证json.它有用户名,密码和密钥.

{
    "Email": "user@apppp.com",
    "Password": "password",
    "SecretKey":""
}
Run Code Online (Sandbox Code Playgroud)

上面的那个是模型状态无效,因为需要密钥.因此,动作过滤器不会运行

{
    "Email": "user@apppp.com",
    "Password": "password",
    "SecretKey":"abc"
}
Run Code Online (Sandbox Code Playgroud)

第二个是modelstate有效,因此动作过滤器运行.但是,我想要做的是触发我的动作过滤器,即使它无效.我怎么能覆盖那个?

ActionFilter

public class ModelValidationAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext context)
    {
        if (!context.ModelState.IsValid)
        {
            //context.Result = new ValidationFailedResult(context.ModelState);
            context.Result = new OkObjectResult("Hello");
        }
        else
        {
            context.Result = new OkObjectResult("Bye");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

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