Base solution for your next web application

Activities of "ajayak"

I want to access Request object in ApplicationService. As the AppService is not a MVC Controller, how can I do so? I am trying something like this:

var json = new StreamReader(Request.InputStream).ReadToEnd();

I logged into my app. Then the page is redirected to external application(Shopify) which makes request to API in my app service. In my function, I save a FullAuditedEntity but the CreatorUserId and TenantId is null in that case.

I'm using ASP.NET Core

I have created a Shopify app. When user clicks a button on my page, then I'm redirecting the user to Shopify app page. On that page, there is an Install button. User clicks on install and Shopify install the app. After installing, Shopfiy calls a url in my app and I don't have any control over request parameters

Hi @ismcagdas,

IHttpContextAccessor solution worked for me :)

I have created the following function:

public async Task<RedirectResult> Install(string shop)
        {
            if (!await GenericHelper.IsValidShopDomainAsync(shop))
            {
                throw new UserFriendlyException(L("PP_Invalid_Shopify_Url"));
            }
            return new RedirectResult(_shopifyManager.GetAuthRedirectUrl(shop));
        }

In the code block, when user hits exception, I am getting following error on client: ![image]( <a class="postlink" href="https://imgur.com/a/zqhXl">https://imgur.com/a/zqhXl</a> )

2:5000/api/services/app/Shopify/Install?shop=asd:1 GET <a class="postlink" href="http://localhost:5000/api/services/app/Shopify/Install?shop=asd">http://localhost:5000/api/services/app/ ... l?shop=asd</a> 500 (Internal Server Error) sales-channel:1 Failed to load <a class="postlink" href="http://localhost:5000/api/services/app/Shopify/Install?shop=asd">http://localhost:5000/api/services/app/ ... l?shop=asd</a>: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 500. scripts.bundle.js:44583 WARN: scripts.bundle.js:44583 Content-Type is not sent! Subscriber.js:238 HTTP error: 0, webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:238 ...

I have created the following function:

public async Task<RedirectResult> Install(string shop)
        {
            if (!await GenericHelper.IsValidShopDomainAsync(shop))
            {
                throw new UserFriendlyException(L("PP_Invalid_Shopify_Url"));
            }
            return new RedirectResult(_shopifyManager.GetAuthRedirectUrl(shop));
        }

In the code block, when user hits the last line(return new RedirectResult), I am getting following error on client: ![image]( <a class="postlink" href="https://imgur.com/a/qdwfc">https://imgur.com/a/qdwfc</a> )

2shopifyplay.myshopify.com/admin/oauth/authorize?client_id=da2faafba7cc7898876351c74ae39446&scope=read_customers,write_customers&redirect_uri=http://localhost:5000/api/services/app/Shopify/Auth:1 OPTIONS <a class="postlink" href="https://shopifyplay.myshopify.com/admin/oauth/authorize?client_id=da2faafba7cc7898876351c74ae39446&scope=read_customers,write_customers&redirect_uri=http://localhost:5000/api/services/app/Shopify/Auth">https://shopifyplay.myshopify.com/admin ... opify/Auth</a> 404 (Not Found) sales-channel:1 Failed to load <a class="postlink" href="https://shopifyplay.myshopify.com/admin/oauth/authorize?client_id=da2faafba7cc7898876351c74ae39446&scope=read_customers,write_customers&redirect_uri=http://localhost:5000/api/services/app/Shopify/Auth">https://shopifyplay.myshopify.com/admin ... opify/Auth</a>: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 404. scripts.bundle.js:44583 WARN: scripts.bundle.js:44583 Content-Type is not sent! Subscriber.js:238 HTTP error: 0, webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:238 webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.error @ Subscriber.js:197 webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber._error @ Subscriber.js:128 webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.error @ Subscriber.js:102 webpackJsonp.../../../../rxjs/OuterSubscriber.js.OuterSubscriber.notifyError @ OuterSubscriber.js:22 webpackJsonp.../../../../rxjs/InnerSubscriber.js.InnerSubscriber._error @ InnerSubscriber.js:26 webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.error @ Subscriber.js:102 webpackJsonp.../../../../rxjs/observable/ErrorObservable.js.ErrorObservable._subscribe @ ErrorObservable.js:77 webpackJsonp.../../../../rxjs/Observable.js.Observable._trySubscribe @ Observable.js:171 webpackJsonp.../../../../rxjs/Observable.js.Observable.subscribe @ Observable.js:159 subscribeToResult @ subscribeToResult.js:22 webpackJsonp.../../../../rxjs/operator/catch.js.CatchSubscriber.error @ catch.js:111 webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber._error @ Subscriber.js:128 webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.error @ Subscriber.js:102 webpackJsonp.../../../../rxjs/OuterSubscriber.js.OuterSubscriber.notifyError @ OuterSubscriber.js:22 webpackJsonp.../../../../rxjs/InnerSubscriber.js.InnerSubscriber._error @ InnerSubscriber.js:26 webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.error @ Subscriber.js:102 webpackJsonp.../../../../rxjs/observable/ErrorObservable.js.ErrorObservable._subscribe @ ErrorObservable.js:77 webpackJsonp.../../../../rxjs/Observable.js.Observable._trySubscribe @ Observable.js:171 webpackJsonp.../../../../rxjs/Observable.js.Observable.subscribe @ Observable.js:159 subscribeToResult @ subscribeToResult.js:22 webpackJsonp.../../../../rxjs/operator/catch.js.CatchSubscriber.error @ catch.js:111 webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber._error @ Subscriber.js:128 webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.error @ Subscriber.js:102 onError @ http.es5.js:1244 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:425 onInvokeTask @ core.es5.js:3881 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:424 webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask @ zone.js:192 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:499 invokeTask @ zone.js:1427 globalZoneAwareCallback @ zone.js:1445 XMLHttpRequest.send (async) scheduleTask @ zone.js:2744 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:411 onScheduleTask @ zone.js:301 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:405 webpackJsonp.../../../../zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:236 webpackJsonp.../../../../zone.js/dist/zone.js.Zone.scheduleMacroTask @ zone.js:259 (anonymous) @ zone.js:2769 proto.(anonymous function) @ zone.js:1274 (anonymous) @ http.es5.js:1275 webpackJsonp.../../../../rxjs/Observable.js.Observable._trySubscribe @ Observable.js:171 webpackJsonp.../../../../rxjs/Observable.js.Observable.subscribe @ Observable.js:159 webpackJsonp.../../../../rxjs/operator/map.js.MapOperator.call @ map.js:54 webpackJsonp.../../../../rxjs/Observable.js.Observable.subscribe @ Observable.js:156 webpackJsonp.../../../../rxjs/operator/catch.js.CatchOperator.call @ catch.js:79 webpackJsonp.../../../../rxjs/Observable.js.Observable.subscribe @ Observable.js:156 webpackJsonp.../../../../rxjs/operator/mergeMap.js.MergeMapOperator.call @ mergeMap.js:85 webpackJsonp.../../../../rxjs/Observable.js.Observable.subscribe @ Observable.js:156 webpackJsonp.../../../../rxjs/operator/catch.js.CatchOperator.call @ catch.js:79 webpackJsonp.../../../../rxjs/Observable.js.Observable.subscribe @ Observable.js:156 SalesChannelComponent._this.installShopify @ sales-channel.component.ts:21 (anonymous) @ SalesChannelComponent.html:17 handleEvent @ core.es5.js:12023 callWithDebugContext @ core.es5.js:13493 debugHandleEvent @ core.es5.js:13081 dispatchEvent @ core.es5.js:8615 (anonymous) @ core.es5.js:10783 schedulerFn @ core.es5.js:3647 webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:238 webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.next @ Subscriber.js:185 webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber._next @ Subscriber.js:125 webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.next @ Subscriber.js:89 webpackJsonp.../../../../rxjs/Subject.js.Subject.next @ Subject.js:55 webpackJsonp.../../../core/@angular/core.es5.js.EventEmitter.emit @ core.es5.js:3621 webpackJsonp.../../../forms/@angular/forms.es5.js.NgForm.onSubmit @ forms.es5.js:4032 (anonymous) @ SalesChannelComponent.html:17 handleEvent @ core.es5.js:12023 callWithDebugContext @ core.es5.js:13493 debugHandleEvent @ core.es5.js:13081 dispatchEvent @ core.es5.js:8615 (anonymous) @ core.es5.js:9226 (anonymous) @ platform-browser.es5.js:2651 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:425 onInvokeTask @ core.es5.js:3881 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:424 webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask @ zone.js:192 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:499 invokeTask @ zone.js:1427 globalZoneAwareCallback @ zone.js:1445

Hi aaron,

CORS is configured correctly in the app as

services.AddCors(options =>
            {
                options.AddPolicy(DefaultCorsPolicyName, builder =>
                {
                        .AllowAnyOrigin()
                        .AllowAnyHeader()
                        .AllowAnyMethod();
                });
            });

and used as

app.UseAbp(options =>
            {
                options.UseAbpRequestLocalization = false; //used below: UseAbpRequestLocalization
            });

            app.UseCors(DefaultCorsPolicyName); //Enable CORS!

All the other app services are working fine. Only getting Internal Server error on line:

throw new UserFriendlyException(L("PP_Invalid_Shopify_Url"));

In browser, it says CORS error but I suspect it to be something else.

When I add Microsoft.AspNetCore.Mvc in ApplicationService solution and use RedirectAction, it causes server error. I also tried installing AbpAspNetCore package but still no luck.

Is there any other way to perform a redirect?

Hi @aaron,

This is in continuation to #3984. All the problems go away after I removed Microsoft.AspNetCore.Mvc from ApplicationService. But I'm still stuck with Redirect.

I believe creating IRedirectionDelegate could solve my problem. Can you share a sample for that? :)

Showing 11 to 20 of 202 entries