سلام وقت بخیر
من یک api درست کردم که بهش یه درخواست xhr میزنم و اطلاعات رو به صورت json بهش ارسال میکنم (در واقع همه میتونن بهش یه درخواست بفرستن)
این پروسه در localhost کاملا درست انجام میشه ولی در هنگامی که api رو در ساب دومینم پابلیش میکنم ! میخوام مقادیر رو به اکشن بفرستم ارور 404 میده و میگه همچین اکشنی post پیدا نشد . ولی همین در لوکال هاست درست کار میکنه و انجام میشه
[Route("[controller]/[action]")] [ApiController] [Produces("application/json", "application/xml", "application/x-www-form-urlencoded")] [EnableCors("AllowAnyOrigin")] public class JsIssueController : ControllerBase { private readonly IUnitOfWork _db; private readonly AppServices _appServices; private readonly IUserServices _userServices; private readonly ISender _sender; private readonly IIssueReportServices _reportServices; public JsIssueController(IUnitOfWork db, AppServices appServices, IUserServices userService, IOptionsSnapshot<SiteSettings> siteOptionsSnapshot, IIssueReportServices issueReportServices) { _db = db; _appServices = appServices; _userServices = userService; _sender = new EmailSender(siteOptionsSnapshot); _reportServices = issueReportServices; } [HttpPost] [Route("/newJsIssue")] public async Task<JsonResult> NewIssue([FromBody]JsIssueViewModel model) { کار اکشن ..... } [Route("/GetData")] public IActionResult GetName(string name) { return Content("Hello " + name); } }
کلاس استارت اپ :
public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers().ConfigureApiBehaviorOptions(options => { options.SuppressConsumesConstraintForFormFileParameters = true; options.SuppressInferBindingSourcesForParameters = true; options.SuppressModelStateInvalidFilter = true; options.SuppressMapClientErrors = true; }); services.AddMvc() .AddXmlSerializerFormatters(); services.AddCors(options => { options.AddPolicy("AllowAnyOrigin", builder => builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); }); services.Configure<SiteSettings>(Configuration.GetSection(nameof(SiteSettings))); services.AddDbContext<DatabaseContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection").Replace("/", @"\")); }); services.AddScoped<IUnitOfWork, UnitOfWork>(); services.AddScoped<IUserServices, UserServices>(); services.AddScoped<AppServices, AppServices>(); services.AddScoped<IIssueReportServices, IssueReportServices>(); //services.AddHsts(options => //{ // options.MaxAge = TimeSpan.FromDays(60); // options.Preload = true; // options.IncludeSubDomains = true; //}); //services.Configure<IISOptions>(options => //{ // options.ForwardClientCertificate = false; // options.AutomaticAuthentication = false; //}); //services.AddHttpsRedirection(options => //{ // options.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect; // options.HttpsPort = 443; //}); services.AddElmahIo(o => { o.ApiKey = ""; o.LogId = new Guid(""); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "My API", Version = "v1",Description = "PatuvTracker Api"}); }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Panel"); //app.UseHsts(); } //app.UseHttpsRedirection(); app.UseRouting(); app.UseElmahIo(); app.UseAuthorization(); app.UseCors("AllowAnyOrigin"); // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API"); }); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllers(); }); } }
ممنون میشم راهنماییم کنید
با سلام، احتما مشکل بابت تنظیمات SSL هاست شما میباشد.
پروژه api محلی شما روی http یا https میباشد؟
هاست شما چطور؟
قبل از پابلیش protocol خود را تغییر دهید. یا برای هاست خود ssl را فعال نمایید
سلام
خیلی ممنون دوست عزیز
بله مشکل از SSL بوده که حل شده
سپاس گذارم.
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)