hacklink al hack forum organik hit kayseri escort b-ok zeta library books z librarygrandpashabetgrandpashabetjojobetjojobet güncel girişjojobet 1019bahiscasinosahabetSlot Oyunlarıankara escortlidoSoft2betdeneme bonusu veren sitelerjojobet jojobetsahabetjojobetjojobetjojobetjojobet girişjojobet girişjojobet girişpadişahbet girişonwinjojobet,jojobet giriş,jojobet güncel giriş,jojobet resmi giriş

Post Details Page

At Devhq.in, we provide comprehensive digital solutions for businesses. From software development and app creation to social media management and brand design, we help you build and grow your digital presence.

Best Way to Connect a Dot NET API with Flutter and Set Up CORS in .NET

Connecting a Connect a Dot NET API with Flutter application is a powerful combination for building robust and high-performing cross-platform apps. In this tutorial, we will guide you through the process of setting up CORS in .NET and making API calls from Flutter. Let’s dive in!

Connect a Dot NET API with Flutter

Now Lets Know how to Connect a Dot NET API with Flutter

Now are going to know ho to Connect a Dot NET API with Flutter

First Create a Api if you dont know how to create then read this API IN DOTNET

Add a CORS policy to access api from any where

 builder.Services.AddCors(options =>
 {
     options.AddPolicy("AllowAll",
         builder =>
         {
             builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader();
         });
 });
C#

Now Call the policy


using DesiMart.DbContext;
using DesiMart.Services;
using DesiMart.Services.Interfaces;
using Microsoft.Extensions.Options;

namespace DesiMart
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            

            builder.Services.AddControllers();
           
            builder.Services.AddEndpointsApiExplorer();

            // Mongo Db Confugration 
            builder.Services.Configure<MongoDbConfigs>(builder.Configuration.GetSection("MonogoSetting"));
            builder.Services.AddScoped<MongoDbContext>();
            // Register ProductService
            builder.Services.AddTransient<IProductService, ProductService>();
            builder.Services.AddTransient<ICart, CartService>();
            builder.Services.AddTransient<IReview, ReviewService>();

            builder.Services.AddSwaggerGen();
            builder.Services.AddCors(options =>
            {
                options.AddPolicy("AllowAll",
                    builder =>
                    {
                        builder.AllowAnyOrigin()
                               .AllowAnyMethod()
                               .AllowAnyHeader();
                    });
            });
            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseHttpsRedirection();

            app.UseCors("AllowAll");
            app.UseAuthorization();

            app.MapControllers();

            app.Run();
        }
    }
}
C#

Now Call the api in flutter

  Future<void> addProduct() async {
    try {
      var response =
          await http.get(Uri.parse("https://localhost:7093/api/Product"));

      print(response.body);
    } catch (ex) {
      print(ex);
    }
  }
C#

Share now :

Facebook
Twitter
LinkedIn
Review Your Cart
0
Add Coupon Code
Subtotal