小编Sam*_*Sam的帖子

ASP.Net Identity Core中的AllowOnlyAlphanumericUserNames和UserValidator属性在哪里?

我正在尝试在我的项目中设置ASP.Net Identity Core.问题是我们将使用Windows身份验证而不是表单身份验证.通过在iisSettings的launch.settings中设置这些属性,我可以让Authorize标签在home控制器上工作:

"windowsAuthentication": true,
"anonymousAuthentication": false,
Run Code Online (Sandbox Code Playgroud)

所以现在在我的标题中,我通过我的布局文件看到我的用户名:

@User.Identity.Name
Run Code Online (Sandbox Code Playgroud)

所以我在标题右上角的用户名如下所示:

[domain\username\]
Run Code Online (Sandbox Code Playgroud)

所以现在授权标签工作.如果我关闭Windows身份验证并返回匿名身份验证,我将获得该页面的未授权状态.如果回到Windows身份验证,我可以再次看到主页/索引页面.尚未与身份有多大关系.

现在我尝试创建一个创建用户页面,最终真正成为Active Directory页面的"添加用户".所以我试图以这种格式存储UserName:

domain\username
Run Code Online (Sandbox Code Playgroud)

这是我的创建代码:

[HttpPost]
public async Task<IActionResult> CreateUser(CreateUserViewModel createUserModel)
    {
        if (ModelState.IsValid)
        {
            AppUser user = new AppUser
            {
                UserName = createUserModel.Name,
                Email = createUserModel.Email
            };
            IdentityResult result 
                = await _userManager.CreateAsync(user, createUserModel.Password);

            if (result.Succeeded)
            {
                return RedirectToAction("Index");
            }
            else
            {
                foreach (IdentityError error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
        }
        return View(createUserModel);
    }
Run Code Online (Sandbox Code Playgroud)

但是我收到了这条消息:

User name 'domain\username' is invalid, can only contain letters or digits.
Run Code Online (Sandbox Code Playgroud)

所以通过阅读我一直看到你可以使用UserManager的这些属性来处理这个: …

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

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

为什么.Net Core中没有可以重写的Dispose方法?

我正在尝试从我的通用服务中处理我的 GenericRep 中的 DbContext。

我的通用存储库正在实现此处描述的模式: https://learn.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/在 asp-net-mvc 应用程序中实现存储库和工作单元模式

我已经在我的仓库中设置了第一部分:

public class GenericRepository<T> : IGenericRepository<T>, IDisposable
    where T: BaseEntity
{
    protected readonly ApplicationDbContext _context;
    protected DbSet<T> _dbSet;
    .
    .
    .
    private bool disposed = false;

    protected virtual void Dispose(bool disposing)
    {
        if (!this.disposed)
        {
            if (disposing)
            {
                _context.Dispose();
            }
        }
        this.disposed = true;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }
Run Code Online (Sandbox Code Playgroud)

现在在文章中,他们在 StudentController 中有这样的内容:

  protected override void Dispose(bool disposing)
  {
     studentRepository.Dispose();
     base.Dispose(disposing);
  }
Run Code Online (Sandbox Code Playgroud)

他们没有 StudentController 实现 IDisposable 或任何东西。我猜他们似乎能够重写 Dispose 作为对象上的标准可重写方法。

所以我需要将其放入我的通用服务中。 …

c# dispose asp.net-core-mvc

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

无法获取 Novell.Directory.Ldap.NETStandard 库进行查询

我需要让用户在 Active Directory 中查询 .Net Core 中的名称。所以我正在构建一个 Active Directory 搜索 Web API 服务。

我能够使用绑定语句进行连接。但尽管没有错误,但我无法通过查询返回任何结果。

另一位程序员向我发送了一些他在其他应用程序中使用的代码。但它使用了 .Net Core 中不可用的 DirectoryEntry 对象。

所以我尝试使用 Novell.Directory.Ldap.NetStandard 库。

这是其他开发人员发送给我的代码:

public static List<UserProfileModel> GetADUsers(string alias)
    {
        List<UserProfileModel> users = new List<UserProfileModel>();

        if (alias == null || alias.Trim().Equals(""))
        {
            return users;
        }

        try
        {
            // Ad path LDAP://ourOrg.gov/CN=Users,DC=ourOrg,DC=gov
            DirectoryEntry de2 = new DirectoryEntry(ConfigurationManager.AppSettings["AD_Path"], ConfigurationManager.AppSettings["AD_User"], ConfigurationManager.AppSettings["AD_Password"]);
            de2.Path = ConfigurationManager.AppSettings["AD_Path"];

            de2.AuthenticationType = AuthenticationTypes.Secure;

            DirectorySearcher deSearch = new DirectorySearcher();

            deSearch.SearchRoot = de2;
            deSearch.Filter = "(samaccountname=*" + alias + "*)";

            LOGGER.Debug(String.Format("Active …
Run Code Online (Sandbox Code Playgroud)

active-directory asp.net-core-mvc

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

如何将自定义属性添加到 .Net Core 中的角色声明中?

我正在使用 Cookie 身份验证而不是 Identity Core。我正在循环遍历自定义表中用户应具有的角色并添加角色声明,如下所示:

if (aartsUser != null)
{
    #region Create Claims
    // UserName claim and StaffId claim.  Will need StaffId to write to tables such as UploadStaffId for FacUpload.
    var claims = new List<Claim>
    {
        new Claim(ClaimTypes.Name, loginModel.UserName),
        new Claim("StaffId", aartsUser.StaffID.ToString())
    };
    // Role Claims
    foreach(Position p in aartsUser.Positions)
    {
        claims.Add(new Claim(ClaimTypes.Role, p.Role.RoleCd));
    }
    #endregion

    var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
    await HttpContext.SignInAsync(new ClaimsPrincipal(claimsIdentity));

    return Redirect(loginModel?.ReturnUrl ?? "/");
}
Run Code Online (Sandbox Code Playgroud)

这一行中的 RoleCd:

claims.Add(new Claim(ClaimTypes.Role, p.Role.RoleCd));
Run Code Online (Sandbox Code Playgroud)

来自我拥有的角色实体:

[Table("role")]
public class …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

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

当我尝试在Oracle 12c中显示时,为什么会得到ORA-39001:无效的参数值?

当我在Oracle 12c SE2中运行此命令时:

impdp system/Oracle_1@pdborcl directory=DATA_PUMP_DIR dumpfile=mydb.dmp nologfile=Y
Run Code Online (Sandbox Code Playgroud)

我得到这个:

ORA-39001:无效的参数值

ORA-39000:错误的转储文件规范

ORA-39088:目录名称DATA_PUMP_DIR无效

我们过去一直将其导入11g。

我该如何解决这些错误?

oracle import datapump oracle12c

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

Visual Studio 2013更新了3个问题

安装VS 2013升级3后,加载一堆软件包时出错.1)VS包2)PowerShellToolsPackage 3)Microsoft.Lightswitch.VSIntegration.Project .ProjectUpdateDelegatorPackage

现在我正在处理#1,VS Package.它说"'VSPackage'包没有正确加载.

Activity Log says:
    <entry>
        <record>315</record>
        <time>2014/09/15 17:32:43.190</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>CreateInstance failed for package [VSPackage]</description>
    <guid>{1A4EFADE-F6B2-4490-A2EF-21D5F3D1C8E0}</guid>
    <hr>80070002</hr>
    <errorinfo>Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft   Visual    Studio 12.0\Common7\IDE\Extensions\hjkzccc5.cqc\Microsoft.AppInsights.GettingStarted.dll' or one of its dependencies. The system cannot find the file specified.</errorinfo>
Run Code Online (Sandbox Code Playgroud)

当我打开VS本身,但是当我打开解决方案时,就不会发生这种情况.

installation visual-studio-2013

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

如何在 .Net Core 启动中根据环境动态选择连接字符串?

在ASP.Net MVC Core的StartUp类的Configure方法中,“IHostingEnvironment env”是通过依赖注入传入的。并且可以根据环境做出决定。例如,

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
            app.UseBrowserLink();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }
Run Code Online (Sandbox Code Playgroud)

在 ConfigureServices 中,我想做这样的事情来选择正确的连接字符串。就像是:

        if (env.IsDevelopment())
        {
            services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
        }
        else if (env.IsStaging())
        {
            // Add Staging Connection
        }
        else
        {
            // Add Prod Connection
        }
Run Code Online (Sandbox Code Playgroud)

但默认情况下,“IHostingEnvironment env”不会传递给 ConfigureServices 方法。所以我修改了签名:

public void ConfigureServices(IServiceCollection services)
Run Code Online (Sandbox Code Playgroud)

public void ConfigureServices(IServiceCollection services, IHostingEnvironment env)
Run Code Online (Sandbox Code Playgroud)

并在 ConfigureServices 中放置:

        if (env.IsDevelopment())
        {
            services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
        }
        else if (env.IsStaging())
        {
            // Add Staging Connection
        }
        else
        {
            // Add Prod …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-core

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

为什么 asp-route-id 在我的表单帖子中不起作用?

我在一个实例中使用了 asp-route-id:

它从这样的锚标签工作:

<a id="editModal" data-toggle="modal" data-target="#modal_box"
    class="btn btn-sm btn-primary"
    asp-action="Edit" asp-route-id="@user.Id">Edit</a>
Run Code Online (Sandbox Code Playgroud)

并像这样收到:

public async Task<PartialViewResult> DeleteConfirm(string Id) =>
        PartialView("_DeleteConfirm", await _userManager.FindByIdAsync(Id));
Run Code Online (Sandbox Code Playgroud)

此方法接收正确的 id。

下一个示例在表单标签中包含路由 id,如下所示:

<div class="modal-footer">
    <form asp-controller="Account" asp-action="Delete" asp-route-id="@Model.Id" method="post">
        <button type="submit" class="btn btn-primary"
           asp-action="Delete">Yes - Delete this User</button>
        <a asp-action="Index" class="btn btn-default">Cancel</a>
    </form>
</div>
Run Code Online (Sandbox Code Playgroud)

我试图在这里接收 ID:

    [HttpPost]
    public async Task<IActionResult> Delete(string Id)
    {
        AppUser user = await _userManager.FindByIdAsync(Id);
        if (user != null)
        {
            IdentityResult result = await _userManager.DeleteAsync(user);
            if (result.Succeeded)
            {
                return RedirectToAction("Index");
            }
            else
            { …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc tag-helpers asp.net-core

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

如何在Entity Framework Core中删除多对多关系?

我有两个实体框架实体。1)员工2)案例

我已经在Entity Framework Core中建立了多对多关系模型。

我可以这样添加关系:

    [HttpPost]
    public async Task<Employee> AddCaseEmployee([FromBody]EmployeeCase employeeCase)
    {
        Case lcase = await _caseGenericService.GetSingleIncludingAsync(employeeCase.CaseId);

        lcase.EmployeeCases = new List<EmployeeCase>();
        lcase.EmployeeCases.Add(new EmployeeCase
            {
                CaseId = employeeCase.CaseId,
                EmployeeId = employeeCase.EmployeeId
            }
        );

        await _caseGenericService.UpdateAsync(lcase);

        Employee employee = await _employeeGenericService.GetSingleIncludingAsync(employeeCase.EmployeeId);
        return employee;
    }
Run Code Online (Sandbox Code Playgroud)

现在,我试图删除这样的一种关系:

    [HttpDelete]
    public async Task<Employee> DeleteCaseEmployee(long employeeId, long caseId)
    {
        Case lcase = await _caseGenericService.GetSingleIncludingAsync(caseId,
            a => a.EmployeeCases);

        //lcase.EmployeeCases.Remove(new EmployeeCase
        //{
        //    CaseId = caseId,
        //    EmployeeId = employeeId
        //}
        //);
        EmployeeCase employeeCase = 
            lcase.EmployeeCases.FirstOrDefault(ec => ec.EmployeeId == …
Run Code Online (Sandbox Code Playgroud)

many-to-many entity-framework-core asp.net-core-mvc

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

为什么CHECK约束在SQL Server中不起作用

我试图向表中添加一个约束,其中一列必须是列表中的值之一,如下所示:

ALTER TABLE bread_crumbs WITH CHECK
  ADD CONSTRAINT CK_uplink_relationship
  CHECK (uplink_relationship in ('Cites', 'CitedBy', null))
Run Code Online (Sandbox Code Playgroud)

我仍然可以为uplink_relationship列插入任何值的行.该CHECK约束不被强制执行.

我读了几个答案,如果在有违反行的情况下创建约束,可能会发生这种情况.

所以我删除了约束,修复了所有数据,并重新添加了约束.

但没有运气.

我仍然可以输入无效数据.

任何想法为什么会这样?

此外,我尝试使用和不WITH CHECK使用声明的部分.

sql-server

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

为什么将.Net Standard和.Net Core项目混合在一个解决方案中?

我刚刚开始研究Apress“使用Visual Studio 2017构建Web应用程序”。我正在开始设置项目。因此,我建立了一个名为SpyStore的解决方案。然后是一个名为SpyStore.DAL的.Net Core控制台应用程序。然后是一个名为SpyStore.Models的.Net标准类库项目。

我的问题是作者为什么会选择.Net标准类库而不是.Net核心类库。有区别吗?

.Net Standard和.Net Core有什么区别。突然之间,他有可能混用Standard吗?

.net-core

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