Why do I get Cors error when using dotnet publish command line? - .net-6.0

I'm using VS 2022 to deploy a dotnet 6 web api.
I downloaded a publish profile from my shared hosting account and use the one-click publish button and it works perfectly.
However, I'm trying to automate the process, and when I run the dotnet publish command it says it published successfully and updated the files. However, when I try to login or call the API, it returns 500 status.
Access to XMLHttpRequest at 'Endpoint*' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I tried adding 'Access-Control-Allow-Origin' to the angular app even though it works without it when I publish manually but still no go.
Is VS2022 running any other command besides the one below?
This is the command I use.
dotnet publish project.csproj /p:PublishProfile=profileName.pubxml /p:Password=

After many trials, I found the solution which makes no sense.
I added the following to the command line.
-f net6.0 -c Release
These config settings are already part of the publish profile, I guess it doesn't release those from the publish profile.

Related

Hyperledger-Composer REST Authentication

Request assistance with hyperledger composer. I have created a network and web app around the REST API that was built with the composer-rest-server. I am able to add participants, assets and execute transaction with the default settings. I am now trying to add authentication to the REST server as well as add identities to new participants. However I got stuck. I have reviewed the information at
https://hyperledger.github.io/composer/integrating/enabling-rest-authentication.html
But I'm not sure where I should place the export COMPOSER_PROVIDERS='{.... information to continue the setup.
Any assistance, tips and tricks are much appreciated.
Ok so I figured it out. The problem was that I was running off an older version of composer-rest-server.
I installed the developer tool back in Sep 17 and did the tutorial soon after. I tried the tutorial again and noticed that the deployment command was different and it would not let me deploy my network.
So I updated the composer-rest-server and component cli and it deployed fine. I then followed the steps on the authentication webpage that I referenced above and it worked as intended. I deployed my personal network with the new command and it worked as intended.
Lesson learned this stuff is still being updated and I should be more aware on what changes. Thank you very much #nilakantha singh deo
Open a new terminal from inside the project folder.Format your COMPOSER_PROVIDERS in notepad according to the document you mentioned and copy the whole message and paste it in the terminal.Then you can echo it (see it) by typing the following.
echo $COMPOSER_PROVIDERS
It should ideally return the same json file.
Then make sure that the compopser-rest-server is running with multiuser mode and authentication enabled in the same terminal where you echoed and saw the COMPOSER_PROVIDERS.
In browser now type
localhost:3000/auth/github
It should ask for authentication .Rest of the steps are listed in the document you mentioned.
Cheers!

Swashbuckle + XmlComments work locally, but fail swagger generation on server

I have a webapi project, and I am utilizing the swashbuckle framework to flush out api documentation.
I have followed the directions to build the documentation xml file with my controller and DTO's, and it all works great locally.
However, when generating the swagger document, a 500 error is thrown. I have confirmed if i remove my xml registration line, the swagger doc is generated and returned successfully.
here is my registration line:
GlobalConfiguration.Configuration.EnableSwagger(c =>
{
...
c.IncludeXmlComments($"{System.AppDomain.CurrentDomain.BaseDirectory}bin\\Company.MyApp.xml");
...
Update: I did some additional logging, and while this lne for IncludeXmlComments runs through successfully on startup, when I request the swagger.json file from the server, I am getting a System.IO.FileNotFoundException: Could not find file 'D:\home\site\wwwroot\bin\Monetary.Scheduling.xml' exception. when I use the Kudu tools to look into this directory, I cannot find this file.
TL;DR: Why is this file showing up fine locally, but when I deploy to Azure using Kudu or a Octopus nugget package, this file is not there?
The problem is that somehow the XML file is not making it to your server...
I had this exact issue with an Azure deployment it worked fine in my local machine but not in azure
...and it was because I was missing the XML doc in the release config

Login failed for user 'sa' when the app is run from VS 2015

I have a console application which hosts two WebApi applications using OWIN Self Host approach. One of the apps uses EF6 with Code First. When I run the executable from the bin folder and make a request to the WebApi, everything works like it should - if the database is already created it just returns the results, otherwise it creates the db first. But if I start the console app from Visual Studio (with debugging), I receive the following error:
Additional information: Cannot open database "{db name}" requested by the login. The login failed.
Login failed for user 'sa'.
Anyone has any ideas why this happens?
EDIT: Problem is not related to the self hosted apps. I referenced the dbcontext directly in the console app and the same issue happens. I also tried Integrated Security and it still fails with "Login failed for user '{DOMAIN\USERNAME}'."
EDIT 2: I fixed my problem by doing deleting the .suo file. That helped me find these two questions mentioning the same solution:
Login failed for user "xxx" Failed to open the explicitly specified database solution
EF 4.1 code first causes weird (login) runtime errors
Can anyone say the reason why the .suo file causes this?

Getting a 404 using App Harbor and BitBucket

I'm new to AppHarbour and I'm trying to deploy my MVC app on a free account.
I keep getting a 404 error.
The app is coming from Bit-bucket and it was deployed successfully.
In my Hostnames section i see the following
so i have added the following to the Hosts file in my machine:
176.34.122.158 camelotfaultmanagement.apphb.com
but i still get a 404 ..
What am i doing wrong ?
And a follow-up question how can i edit one of the files to be able to edit the connection ?string to my DB?
It looks like you may not have any successful builds yet - You have to push to Bitbucket to trigger your first build. You can see a list of builds on the app dashboard: https://appharbor.com/applications/camelotfaultmanagement
To use the built-in .apphb.com domain, you don't have to mess with any DNS setup.

Accessing NuGet functionality from behind a corporate firewall

When I right mouse click on the References folder in the Solution Explorer window and selecct "Add Package Reference Library", I get teh error
The package source named "NuGet official package source https://go.microsoft.com/fwlink/?LinkId=206669 is eiether invalid or not available and thus is unreachable"
When I use IE directly to access this URL, I am redirected to http://packages.nuget.org/v1/FeedService.svc/ and see an XML response.
I suspect that my company's security is preventing me from accessing this site. I'd like to request that they make an exception. What specifically should I request that would enable me to access it?
And similarly, I would like to access the Extnsion Manager functionality from within VS but I get a more vague "An error occured error" ..
This seems to be a known issue with NuGet. I've been getting the same error and I updated to the latest version of NuGet but still get the error when using the proxy, but everything works when the proxy is disabled. I'm not sure when they will have this resolved.

Resources