Base solution for your next web application

Activities of "SperseDev"

Answer

Yes, you are right, but ... My point was that It is not so simple as you describe to change the default background job processor to Hangfire. After exchanging we also need to rewrite some logic to something like you offered. Currently, the documentation doesn't have warnings about this. My offer was to modify HangfireBackgroundJobManager to move enqueueing a job on transaction committing level. Thanks

Answer

Yes, but after an exception at the end of this method all changes will be rolled back, but Hangfire job will be left.

Question

Hi

I have read documentation related to integration with HangFire like alternative job processor. Good explanation and all work correctly, but after several days of working noticed a strange behavior different from the behavior of the classic background job manager.

Simple example to explain:

[UnitOfWork]
public void TestMethod()
{
    PrepareDataForTestJob();
  
    CurrentUnitOfWork.SaveChanges();
	
    _backgroundJobManager.EnqueueAsync<TestJob, TestJobParams>(new TestJobParams()); 
	
    throw new Exception("Some Exception");
}

Method _backgroundJobManager.EnqueueAsync enqueues job immediately and HangFire job processor starts processing without committed prepared data. In a case when method TestMethod throws exception job still exists in queue processing.

First thought, that we need to rewrite HangfireBackgroundJobManager to something like that:

public Task<string> EnqueueAsync<TJob, TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null) 
    where TJob : IBackgroundJob<TArgs>
{
    string jobUniqueIdentifier = string.Empty;

    _unitOfWorkManager.Current.Completed += (sender, args) => 
    { 
        if (!delay.HasValue)
        {
            HangfireBackgroundJob.Enqueue<TJob>(job => job.Execute(args));
        }
        else
        {
            HangfireBackgroundJob.Schedule<TJob>(job => job.Execute(args), delay.Value);
        }
    }
    return Task.FromResult(jobUniqueIdentifier);  //???
}

Do you have any suggestions how to fix this correctly?

Thanks!

Yes.

As I understand, is this behaviour(asp.net zero angular UI sends Authorization: Bearer null in a request to API) is a bug?

Hi. I got null token before login.

The problem in UI part:

.\angular\src\AppPreBootstrap.ts

private static getUserConfiguration(callback: () => void): JQueryPromise<any> { const cookieLangValue = abp.utils.getCookieValue('Abp.Localization.CultureName'); return abp.ajax({ url: AppConsts.remoteServiceBaseUrl + '/AbpUserConfiguration/GetAll', method: 'GET', headers: { Authorization: 'Bearer ' + abp.auth.getToken(), <---------------Without null Bearer it works---------------------------------------------------- '.AspNetCore.Culture': ('c=' + cookieLangValue + '|uic=' + cookieLangValue), 'Abp.TenantId': abp.multiTenancy.getTenantIdCookie() } }).done(result => { $.extend(true, abp, result);

HTTP raw request data:

GET <a class="postlink" href="http://localhost:22742/AbpUserConfiguration/GetAll">http://localhost:22742/AbpUserConfiguration/GetAll</a> HTTP/1.1 Host: localhost:22742 Connection: keep-alive Pragma: no-cache Origin: <a class="postlink" href="http://localhost:4200">http://localhost:4200</a> Abp.TenantId: null User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36 Content-Type: application/json Accept: application/json, text/javascript, /; q=0.01 Cache-Control: no-cache X-Requested-With: XMLHttpRequest .AspNetCore.Culture: c=null|uic=null Expires: Sat, 01 Jan 2000 00:00:00 GMT Referer: <a class="postlink" href="http://localhost:4200/account/login">http://localhost:4200/account/login</a> Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9

HTTP/1.1 200 OK Transfer-Encoding: chunked Content-Type: application/json; charset=utf-8 Server: Kestrel Access-Control-Allow-Origin: * X-SourceFiles: =?UTF-8?B?RDpcc291cmNlc1xBc3AuTmV0IFplcm9cQXNwLk5ldCBDb3JlICYgQW5ndWxhclw1LjAuNFxORVQgRnJhbWV3b3JrIDQuNi4xXFBsYXRmb3JtMlxQbGF0Zm9ybVxhc3BuZXQtY29yZVxzcmNcU3BlcnNlLlBsYXRmb3JtLldlYi5Ib3N0XEFicFVzZXJDb25maWd1cmF0aW9uXEdldEFsbA==?= X-Powered-By: ASP.NET Date: Mon, 18 Dec 2017 16:43:43 GMT

e3e {"result":{"multiTenancy":{"isEnabled":true,"sides":{"host":2,"tenant":1}},"session":{"userId":null,"tenantId":null,"impersonatorUserId":null,"impersonatorTenantId":null,"multiTenancySide":2},"localization":{"currentCulture":{"name":"en","displayName":"English"},"languages":[{"name":"de","displayName":"Deutsch","icon":"famfamfam-flags de","isDefault":false,"isDisabled":false,"isRightToLeft":false},{"name":"en","displayName":"English","icon":"famfamfam-flags gb","isDefault":true,"isDisabled":false,"isRightToLeft":false},{"name":"es-MX","displayName":"Español (México)","icon":"famfamfam-flags mx","isDefault":false,"isDisabled":false,"isRightToLeft":false},{"name":"es","displayName":"Español (Spanish)","icon":"famfamfam-flags es","isDefault":false,"isDisabled":false,"isRightToLeft":false},{"name":"fr","displayName":"Français","icon":"famfamfam-flags fr","isDefault":false,"isDisabled":false,"isRightToLeft":false},{"name":"it","displayName":"Italiano","icon":"famfamfam-flags it","isDefault":false,"isDisabled":false,"isRightToLeft":false},{"name":"pt-BR","displayName":"Português (Brasil)","icon":"famfamfam-flags ................ ................ ...............

Hello.

I have downloaded:

  • Project Type (required) - ASP.NET CORE & Angular
  • Project Version (required) - v5.0.4 (latest)
  • Framework (required): - .NET Framework 4.6.1

For back-end - I opened solution(.\aspnet-core\Sperse.Platform.Web.sln) under VisualStudio 15.4.4 and changed in appsettings.json IdentityServer IsEnabled --> "true" than ran migrator and than started project Sperse.Platform.Web.Host under IIS Express.

For front-end - I restored packages via yarn and run npm start - after successful webpack compilation I opened a browser and went to localhost:4200 and after that I received an exception on back-end:

System.InvalidOperationException Message: You must either set Authority or IntrospectionEndpoint StackTrace: at Microsoft.AspNetCore.Builder.OAuth2IntrospectionOptions.Validate() at IdentityModel.AspNetCore.OAuth2Introspection.PostConfigureOAuth2IntrospectionOptions.PostConfigure(String name, OAuth2IntrospectionOptions options) at Microsoft.Extensions.Options.OptionsFactory1.Create(String name) at Microsoft.Extensions.Options.OptionsMonitor1.<>c__DisplayClass10_0.<Get>b__0() at System.Lazy`1.CreateValue() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

Here is HTTP Raw Request data:

GET http://localhost:22742/AbpUserConfiguration/GetAll HTTP/1.1 Host: localhost:22742 Connection: keep-alive Pragma: no-cache Origin: http://localhost:4200 Abp.TenantId: null Authorization: Bearer null Content-Type: application/json Accept: application/json, text/javascript, /; q=0.01 Cache-Control: no-cache X-Requested-With: XMLHttpRequest User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36 .AspNetCore.Culture: c=null|uic=null Expires: Sat, 01 Jan 2000 00:00:00 GMT Referer: http://localhost:4200/ Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9

HTTP/1.1 500 Internal Server Error Server: Kestrel X-SourceFiles: =?UTF-8?B?RDpcc291cmNlc1xBc3AuTmV0IFplcm9cQXNwLk5ldCBDb3JlICYgQW5ndWxhclw1LjAuNFxORVQgRnJhbWV3b3JrIDQuNi4xXFBsYXRmb3JtMlxQbGF0Zm9ybVxhc3BuZXQtY29yZVxzcmNcU3BlcnNlLlBsYXRmb3JtLldlYi5Ib3N0XEFicFVzZXJDb25maWd1cmF0aW9uXEdldEFsbA==?= X-Powered-By: ASP.NET Date: Mon, 18 Dec 2017 16:25:34 GMT Content-Length: 0

Hello.

I am using ASP.NET Zero (ASP net core & angular, full .net framework targeting, azure separate back and front end hosting).

I need to implement OAuth Authorization code flow for zapier - <a class="postlink" href="https://zapier.com/developer/documentation/v2/oauth-v2/">https://zapier.com/developer/documentation/v2/oauth-v2/</a>. While I was doing some investigation I found that ASP.Net Zero framework has already implemented Resource owner password flow.

As I understood I need to implement following components(to implement OAuth Authorization code flow for zapier) :

  • i need to implement UI in Web.Host project for user interaction with account login, consent and grants management and it will redirect after user press allow.
  • implement controller in Core.Web project which handls user interaction + generating code and storing that code for next call to identity server for exaching that code to access token.

What can you recommend for easiest OAuth Authorization code with user credentials implementation? Maybe you can provide some example or tell what components are already implemented?

What about using LocalDb for auto-tests? Or update DBContext to move schema part to table prefix (if not dbo) when running tests?

Showing 1 to 10 of 14 entries