小编joh*_*ohn的帖子

无法使用asp.net身份登录种子数据库配置

我有登录问题,即使我看到表格中填充了来自Configuration.cs的种子用户信息:

protected override void Seed(www.Models.ApplicationDbContext context)
        {
            if (!context.Roles.Any(x => x.Name == "admin"))
            {
                var roleStore = new RoleStore<IdentityRole>(context);
                var roleManager = new RoleManager<IdentityRole>(roleStore);
                var role = new IdentityRole { Name = "admin" };
                roleManager.Create(role);
            }

            if (!context.Users.Any(x => x.UserName == "admin" && x.Email == "admin@admin.com"))
            {
                var userStore = new UserStore<ApplicationUser>(context);
                var userManager = new UserManager<ApplicationUser>(userStore);
                var user = new ApplicationUser { UserName = "admin", Email = "admin@admin.com" };
                var hasher = new PasswordHasher();
                userManager.Create(user, "MySecret5");
                userManager.AddToRole(user.Id, "admin");
            } …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-5 asp.net-identity

6
推荐指数
2
解决办法
913
查看次数

如何与ASP身份用户建立一对多关系

我使用带有MVC +身份的默认Web应用程序来管理用户,并试图使每个注册用户都制作他的电影列表,并且在登录时只能看到他的列表。

所以,以我为例,我上了电影课

public class Movie
    {
        public int MovieId { get; set; }
        public string MovieName { get; set; }
        public string Year { get; set; }
        public string Genre { get; set; }

        public virtual ApplicationUser ApplicationUser { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

并在ApplicationUser中,我把

public virtual ICollection<Movie> Movies { get; set; }
Run Code Online (Sandbox Code Playgroud)

列出电影列表。

我还制作了一个实体FrameWork MovieController,将Movie用作模型,将ApplicationDbContext用作上下文。

所以我在查询数据库时遇到问题,以使每个用户只能查看他的电影列表,在默认的脚手架中,我在MoviesController的索引操作中得到了此信息

 public ActionResult Index()
        {
            var movies = db.Movies.ToList();
            return View(movies);
        }
Run Code Online (Sandbox Code Playgroud)

如果有人对我的问题有经验,请提供帮助,我们欢迎您提供任何意见,也非常感谢。

asp.net-mvc entity-framework-6 asp.net-identity

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

Spring Security不断将我重定向到登录页面

我在地址栏中输入的任何链接都会使我重定向到登录页面。我该如何预防?

例如,如果我添加http:// localhost:8080 / asdasdsa >,它将重定向我到 http:// localhost:8080 / account / login,因此,如果我在http:// localhost:8080 /之后添加任何内容,我将被重定向帐户/登录视图。

我的安全性配置:

package com.example.configuration;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @Autowired
    private DataSource dataSource;

    @Value("${spring.queries.users-query}")
    private String usersQuery;

    @Value("${spring.queries.roles-query}")
    private String rolesQuery;

    @Override
    protected void configure(AuthenticationManagerBuilder auth)
            throws Exception {
        auth
            .jdbcAuthentication()
                .usersByUsernameQuery(usersQuery)
                .authoritiesByUsernameQuery(rolesQuery)
                .dataSource(dataSource) …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc spring-security spring-boot

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

在内存运行时中创建了多少个对象?

我正在攻读1z0-803 Java证书考试.我们必须找出MarkList在这个应用程序中创建了多少个实例:

public class MarkList {
   int num;

   public static void graceMarks(MarkList obj4) {
       obj4.num += 10;
   }

   public static void main(String[] args) {
       MarkList obj1 = new MarkList();
       MarkList obj2 = obj1;            
       obj2.num = 60;
       graceMarks(obj2);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的一位朋友说,在这个问题中答案是两个对象.我认为这只是一个(obj1),虽然我可能错了,因为我是Java新手,但有一些C#经验.

java oop

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