I want to add CORS support to a locally hosted web api 2 project following this tutorial:
https://learn.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api
I have added the CORS package via the package manager:
Install-Package Microsoft.AspNet.Cors
Next, as described in the tutorial, I have added the following line to my webconfig.cs file:
config.EnableCors();
Intellisense is now showing that I need a reference for the EnableCors call. I have searched around the web and the latest documentation I can find states that the following reference is required:
using System.Web.Cors;
However, this reference does not resolve the EnableCors call. Can anyone explain what reference namespace is needed?
Thank you for your help!
UPDATE! I got this problem figured out! In Nuget, I loaded Microsoft.AspNet.WebApi.Cors. The reference in the WebConfig.cs file becomes
using System.Web.Http.Cors;
At the beginning of the webConfig.cs file, add the following lines, changing the URL for your specific situation:
var cors = new EnableCorsAttribute("http://localhost:57357", "*", "*");
config.EnableCors(cors);
In the tutorial, an attribute is used. If you wish to use an attribute, then add the call to enable CORS in the WebConfig.cs file, shown here:
config.EnableCors();
I hope this answer provides some guidance to others dealing with this problem. Happy coding!
Related
I have written the logic for a backend e-commerce REST API, and I have documented it here:
https://app.swaggerhub.com/apis-docs/chris-larham-1983/e-Commerce_Registration_Customers_Addresses_Orders/0.1#/. I would like to include this specification in my project that is deployed on Heroku so that the project and documentation are in one place.
I have configured the Heroku database, populated the 'customers', 'orders', 'products', and 'addresses' table with sample data, and the specified endpoints are working as specified in the document - for example, https://codecademy-e-commerce-rest-api.herokuapp.com/api/products.
So far I have tried downloading the documentation from within my Swagger Hub account in 'html', 'html2', and 'dynamic html' formats, as I thought I would just include a .html document in my project. However, these downloaded documents do not closely resemble the documentation as linked above; the formatting is very different and does not look as professional.
Does anybody know I could include my Swagger Hub API definition in my project so that the documentation and project are both hosted on Heroku?
Thanks in advance for any help/pointers to tutorials.
After a couple of hours of searching and configuring, I have solved this problem thanks to an npm package called swagger-ui-express. This package can be found here: https://www.npmjs.com/package/swagger-ui-express.
I downloaded my API specification in the format JSON resolved and added it to my project as a file named swagger.json. Then I followed the configuration information in the swagger-ui-express documentation, uploaded to heroku, and it worked!
The lines of code I added in index.js were:
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
I hope this helps somebody in the future :)
Upgrading Microsoft.Bot.Builder.LanguageGeneration from 4.14.1 to 4.15.0 results in new errors about the fromFile() method. Couldn't find any solution or similar issues on the internet yet. This holds us from upgrading so any feedback is welcome.
/UnitTests/bin/Debug/net5.0/Resources/Lg/General.lg line 25:2 - line 25:39: Error occurred when parsing expression 'fromFile('../Cards/HelpCard.json')'. fromFile does not have an evaluator, it's not a built-in function or a custom function.
This release introduces a global flag called
"Templates.EnableFromFile" that indicates whether the Adaptive
Expression fromFile function is allowed in LG templates. If an
application had previously made use of this function, it is now
required to add the line "Templates.EnableFromFile = true;" to the
Startup.cs code.
from botbuilder-dotnet/releases
Adding it in Startup.cs (or Program.cs) didn't help. I had to put it in the constructor of the service where I used the Templates class.
For someone who needs sample on how to add it.
Add it like this in startup.cs-> ConfigureServices method.
Also on lg file - you dont have to create manually lg file - it will be generated in backend.
You just have to add your content in bot responses which is the content it will be generated in lg file in backend - you can open the same solution in visual studio and see it.
I try to use the package https://github.com/BlueBayTravel/Mailchimp as in examples but i got an error:
ErrorException in Mailchimp.php line 64:
Undefined property: BlueBayTravel\Mailchimp\Facades\Mailchimp::$users
when i try to use: Mailchimp::users(), while i can get a connection via Mailchimp::getDefaultConnection(); mean the package is completely red, what u guess the problem with me here ?
I saw that you already opened an issue in the package repo.
If you are using Laravel, and you want to use an existing integration with Mailchimp, I would recommend you to give a try to the spatie/laravel-newsletter package. It's the most complete package I've found for the integration Laravel + Mailchimp, and it uses the drewm/mailchimp-api API wrapper (which IMO, is the best php wrapper for Mailchimp). You can find some examples at Freek's blog or at the README file of the project. And if you do not find what you need, you can go to a lower level using the drewm wrapper: $api = Newsletter::getApi();
If this is not what you are looking for, you can always create your own service in Laravel, adapted to your needs and requierements ;)
I am implementing Twilio in Laravel 5, the tutorial I am using is very good https://www.twilio.com/blog/2014/09/getting-started-with-twilio-and-the-laravel-framework-for-php.html.
Do you know what the namespace is for laravel 5?
I am getting
Class 'Services_Twilio_Twiml' not found
Thanks
If you install the twilio/sdk package via composer you should have access to all the Twilio classes automatically, since laravel uses composer's autoloading.
They are not really namespaced. You would use \Services_Twilio_Twiml.
You can tell composer to load your Twilio folder by adding :
"autoload" : {
"classmap" : [ "your/Twilio/folder" ]
}
to your composer.json
If I understood you clearly you have put your Twilio code in a given file and you are getting this error saying "Class 'Services_Twilio_Twiml' not found".
I am writing here possible reason you are getting this.
/config/services.php- you have not added Twilio details which are
i. sid
ii. token
iii. from
in file in which you have integrated your Twilio code, you have to ensure to write use Twilio;
In your app.php you have to add in providers section Twilio which you are using for example: 'Aloha\Twilio\TwilioServiceProvider'
and aliases section 'Twilio' => 'Aloha\Twilio\Facades\Twilio',.
If you look at this you might find answer.
For Laravel 5 (and older Laravel 4 applications) I suggest using the aloha/twilio package. It provides some code samples in the readme file that should help you get going quickly. One can inject a configured object using the TwilioInterface type hint which has methods to send SMSs MMs and calls.
I'm using a package (aws) and I wish to get a var from it's config file.
The config file is located in:
config>packages>aws>aws-sdk-php-laravel>config
I've tried:
Config::get('packages.aws.aws-sdk-php-laravel.config.key')
But no luck, any ideas?
Config is easily accessed and Laravel has support for packages. The structure for calling it would be.
Config::get('package::file.option');
I've just taken a look at the package you are using, and they've set up a nice handy namespace for access. Since the package only has one config file, you can also omit that, like so:
Config::get('aws::key');
For more information regarding third party package configuration, here's the Laravel documentation on the subject http://laravel.com/docs/packages#package-configuration.
Hope that helps.
Use the package notation for config files:
Config::get('aws/aws-sdk-php-laravel::key');
And you may also have to add the namespace to Laravel:
Config::addNamespace('aws/aws-sdk-php-laravel', __DIR__.'/path/to/config');