小编Clé*_*cou的帖子

ASP.NET 身份电子邮件确认令牌无效

我正在使用 Asp.Net 身份。当我想使用电子邮件确认令牌确认新用户时,我系统地遇到无效令牌错误。

这是我的 WebApi 用户控制器:

public class UsersController : ApiController
{
    private MyContext _db;
    private MyUserManager _userManager;
    private MyRoleManager _roleManager;


public UsersController()
{
    _db = new MyContext();
    _userManager = new MyUserManager(new UserStore<MyUser>(_db));
    _roleManager = new MyRoleManager(new RoleStore<IdentityRole>(_db));
}

//New user method
[HttpPost]
public async Task<HttpResponseMessage> Register([FromBody]PostUserModel userModel)

{
//New user code
...

var token = await _userManager.GenerateEmailConfirmationTokenAsync(user.Id);
            var message = new IdentityMessage();
            message.Body = string.Format("Hi {0} !\r\nFollow this link to set your password : \r\nhttps://www.mywebsite.com/admin/users/{1}/reset?token={2}", user.UserName, user.Id, HttpUtility.UrlEncode(token));
            message.Subject …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-web-api asp.net-identity

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

Tomcat 8 和 Spring Security Cors

我正在尝试配置 Spring Security 以使其支持 CORS。感谢这篇文章Spring security CORS Filter,我已经使用 Spring Boot 使用以下配置代码使其在我的本地主机上工作:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.cors()
        .and()
        .antMatcher("/api/**")
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .authorizeRequests()
        .antMatchers(HttpMethod.POST, "/api/login").permitAll()
        .antMatchers(HttpMethod.GET, "/api/websocket/**").permitAll()
        .antMatchers("/api/**").authenticated()
        .and()
        .addFilterBefore(new JWTLoginFilter("/api/login", HttpMethod.POST, authenticationManager(), tokenAuthenticationService, myUserService), UsernamePasswordAuthenticationFilter.class)
        .addFilterBefore(new JWTAuthenticationFilter(tokenAuthenticationService), UsernamePasswordAuthenticationFilter.class)
        .csrf().disable();
    }

@Bean
public CorsConfigurationSource corsConfigurationSource() {
    final CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowedOrigins(ImmutableList.of("*"));
    configuration.setAllowedMethods(ImmutableList.of("HEAD",
            "GET", "POST", "PUT", "DELETE", "PATCH"));
    // setAllowCredentials(true) is important, otherwise:
    // The value of the …
Run Code Online (Sandbox Code Playgroud)

java spring tomcat

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

Angular 8:服务中没有 HttpClient 的提供者

为了将 Angular 5 项目迁移到 Angular 8,我使用 Angular CLI 创建了一个空项目,并在我的新项目结构中复制了我的模块、组件和服务。该项目已构建,但在执行时,我收到了经典消息“没有服务中的 HttpClient 提供程序”:

    ERROR NullInjectorError: StaticInjectorError(AppModule)[TimeService -> HttpClient]: 
  StaticInjectorError(Platform: core)[TimeService -> HttpClient]: 
    NullInjectorError: No provider for HttpClient!
    at NullInjector.get (http://localhost:4200/vendor.js:50573:27)
    at resolveToken (http://localhost:4200/vendor.js:52359:24)
    at tryResolveToken (http://localhost:4200/vendor.js:52285:16)
    at StaticInjector.get (http://localhost:4200/vendor.js:52148:20)
    at resolveToken (http://localhost:4200/vendor.js:52359:24)
    at tryResolveToken (http://localhost:4200/vendor.js:52285:16)
    at StaticInjector.get (http://localhost:4200/vendor.js:52148:20)
    at resolveNgModuleDep (http://localhost:4200/vendor.js:76198:29)
    at _createClass (http://localhost:4200/vendor.js:76275:32)
    at _createProviderInstance (http://localhost:4200/vendor.js:76231:26)
Run Code Online (Sandbox Code Playgroud)

我觉得我的 app.module.ts 没问题:我正在导入 HttpClientModule 并且我已经把它放在 @NgModule 导入中,就在 BrowserModule 之后。

@NgModule({
    declarations: [AppComponent,DelegationsComponent],
    imports:      [BrowserModule,
                  HttpClientModule,
                  GlobalModule.forRoot(),
                  AuthenticationModule,
                   DelegationModule,
                   routing,
                   FormsModule,
                   ReactiveFormsModule,
                   BrowserAnimationsModule,
                   ButtonModule, TableModule, DialogModule, …
Run Code Online (Sandbox Code Playgroud)

angular8

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

覆盖IEnumerable <T>在哪里

我编写了一个实现IEnumerable的类:

public class MyEnumerable : IEnumerable<MyClass>
{ 
    IEnumerator IEnumerable.GetEnumerator()
    {
        return this.GetEnumerator();
    }
    public IEnumerator<MyClass> GetEnumerator()
    {
        //Enumerate
    }
}
Run Code Online (Sandbox Code Playgroud)

我想"覆盖"Where方法.我想做的是:

MyEnumerable myEnumerable = new MyEnumerable();
MyEnumerable myEnumerable2 = myEnumerable.Where(/*some predicate*/);
Run Code Online (Sandbox Code Playgroud)

目前这是不可能的,因为myEnumerable.Where()返回一个IEnumerable.我想要的是myEnumerable.Where()返回一个MyEnumerable.

这有可能吗?

谢谢

c# generics ienumerable

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