CORS policy errors - asp.net-core

I have an .Net Core API running on https://localhost:44371 and a Blazor app running on https://localhost:44346. As you can see they aren't running on the same port, so I'm getting a CORs error of 'Access-Control-Allow-Origin'. These are new projects generated through Visual Studio.
Can I have them both run from the same port?
If so how can I dictate which port to use?
Will making them run from the same port fix this problem?
If not, what's a work around?
Thank you in advance!!

No, you cannot run two separated app at the same port.
and also, same port wont fix your issue.
You should enable the CORS middleware in asp.net core. try enable it using docs:
https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-5.0
and also be aware that you should have a exception handler because any unhandled exception will clear CORS headers.
you can use this doc:
https://learn.microsoft.com/en-us/aspnet/core/web-api/handle-errors?view=aspnetcore-5.0

Related

ASP.NET Core - Failed to start application '/LM/W3SVC/3/ROOT', ErrorCode '0x8007023e'

I'm currently encountering a problem when I deploy my ASP.NET Core program on IIS, and I have no idea how to fix it. Could somebody tell me why?
Probably missing some server roles or features.
Checking the Application Event Log I found the error '0x8007023e'
Checking the System Event Log I found a WAS (Windows Process Activation Service) communication error:
Then I installed the following roles and features:
Also I reinstalled ASP.NET Core Module
Finally I had to reassign the app pool to the site, and everything worked
In my case, the application had been assigned to a different app pool, somehow. Changing it back fixed the issue.
IIS > {Application} > Advanced Settings > General > Application Pool

Spartacus - Error occurred while trying to proxy request

when doing yarn start in spartacus application at localhost , I am getting following error:
[HPM] Error occurred while trying to proxy request /rest/v2/electronics-spa/cms/pages?fields=DEFAULT&pageType=ContentPage&pageLabelOrId=homepage&lang=en&curr=USD from localhost:4200 to https://localhost:
9002 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
I have pretty standard proxy.bankend.js file. Any suggestions what i can investigate ?
I already tested backend is reachable via url directly.
Regards,
Archit
I am familiar with this situation. Usualy this error happens when the endpoint I an trying to proxy to is not reachable.
Looking at the error I can see your request is still going to https://localhost:9002 so I believe it's possible your proxy might not be picked up.
You should make sure that you specified the proxy config correctly. It can be done in your package.json by modifying the start script: "start": " ng serve --proxy-config proxy/proxy.backend.js", (in this case my proxy is in a proxy folder).
Hope this helps!

resolving session fixation bug fix in resin app server

I am using resin app server
request.getSession.invalidate();reguest.getSession(true) is not working properly and its not resetting session ID while using Resin.
Also I am not able to use request.changeSessionId() as the resin version is not able to use JavaEE7 libraries.
Please share your views on how to resolve session fixation with Resin
Resin 4.0.x doesn't implement Servlet 3.1 API.
Resin provides reuse-session-id configuration option that helps control session cookie behaviour.
http://caucho.com/resin-4.0/reference.xtp#session-config

Silverlight wcf connection error

I'm about a month away developing my silverlight application (this is my first). Everything went rather smoothly until today, when out of the blue I started getting this message:
An error occurred while trying to make a request to URI 'http://localhost:2682/Services/Authentication/LoginService.svc'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.
I'm using WCF Services and this issue never appeared until now.
I've added a clientdomain.xml and clientaccesspolicy.xml file to my [projectname].web folder, and re-wrote them about a 1000 different ways.
I've also used Fiddler and it shows me that the error is on both those files, the error is
[Fiddler] The socket connection to localhost failed. ErrorCode: 10061. No connection could be made because the target machine actively refused it 127.0.0.1:2682
I've searched the error "10061" and it has to do with socket definition. But I couldn't find any solution to that.
Don't know if it has anything to do with it, but my "ASP.net Development Server" port is 6939.
Keep in mind that the app has NOT been deployed, so this is only happening locally. I'm using MS VS 2010 and MS SQL Server 2008.
Am I doing anything wrong or is this a silverlight issue??
On a last note, I haven't changed anything on Port, socket or service configuration. Last thing I was doing was editing a XAML file on client side and and the app started throwing me this error.
Need help, can't do anything until this is solved!!!!
Thanks.
i think you are using you app on localhost and a dynamic port is getting assigned and this port is not fixed and every run and that causes the refuse problem. if you want to fix this, create a solid url for example,
http://localhost/apps/Services/Authentication/LoginService.svc
Well, last night, just before I went to bed, I noticed something odd. In my "ServiceReferences.ClientConfig" file, the endpoint ports for each one of my services where diferent from the ones the silverlight machine used, so going on a hunch (and because I was reaching my sanity breakpoint) I decided to eliminate all my Service References and re-add them again.
I worked... go figure. Still don't know why this happened and if anyone could shed some light on the subject, I would appreciate it. It's kinda of annoying having to re-add all my services references. Right now I have only 6 of them, but in the near future they may go over 20, and if this happens again... well, it's going to be a real pain...
Thanks

local work but hosting on AppHarbor can not query SQL Server

So I have my web.config connection string pointing to my SQL Server on appharbor - from local (running Visual Studios) I can login and the memberships works. However from the build that is on the hosting side I get sorry, an error occurred while processing your request.
This is strange because I made a new user from local and check with SQL Server Management Studio whether or not the data has been added to the hosting server and it WORKS.
From my latest build I get the error:
Sorry, an error occurred while processing your request.
which is weird because they both point to the same server...
Anyone have an idea of what I am doing incorrectly?
ASP.NET MVC project has the "HandleErrorAttribute" on by default. You should remove it from FilterConfig.cs in App_Start Folder to see the actual error rather than the handled response.
It's located in the RegisterGlobalFilters method where filters.Add(new HandleErrorAttribute()); should be removed.
AppHarbor has a FAQ to help you troubleshoot deployment errors like these. In particular, you should inspect the "Errors" interface on AppHarbor and disable customErrors. Please elaborate the question if the FAQ doesn't help you solve the problem.