locked
405 Error while updating and deleting record RRS feed

  • Question

  • User2041008840 posted

    I am getting 405 error while update and deleting record from database. my project is asp.net core web api  and front end is blazor web assembly 

    I am getting this error after uploading to server on localhost its working fine. i have https redirect 301 activated on hosting.

    when user visited it will automatically redirect to https. the Insert and Select data is working fine but update and delete showing 405 Error this method is not allowed. 

    its Cors problem. I also put this code in server side startup file of asp.net core web api. 

    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.ResponseCompression;
    using Microsoft.EntityFrameworkCore;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using Newtonsoft.Json;
    using System.IO.Compression;
    using System.Linq;
    
    namespace CRM.Server
    {
        public class Startup
        {
            public Startup(IConfiguration configuration)
            {
                Configuration = configuration;
            }
            public IConfiguration Configuration { get; }
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddCors(options =>
                {
                    options.AddDefaultPolicy(
                    builder =>
                    {
                        builder.WithOrigins("https://cbr.aawe33.in").AllowAnyHeader().AllowAnyMethod().AllowCredentials();
                        builder.WithOrigins("https://localhost:44348").AllowAnyHeader().AllowAnyMethod().AllowCredentials();
                    });
                });
    
    
                services.AddControllersWithViews();
                services.AddRazorPages();
                services.AddControllersWithViews().AddNewtonsoftJson(options =>
                {
                    options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                    options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
                    options.SerializerSettings.MaxDepth = 100;
                    options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
                });
                services.AddSignalR();
                services.AddResponseCompression(option =>
                {
                    option.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] {
                    "application/octet-stream"
                    });
                });
                services.Configure<GzipCompressionProviderOptions>(options =>
                {
                    options.Level = CompressionLevel.Fastest;
                });
                services.AddDbContext<CRMServerContext>(options =>
                        options.UseSqlServer(Configuration.GetConnectionString("CRMServerContext")));
                services.AddResponseCaching();
            }
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                    app.UseWebAssemblyDebugging();
                }
                else
                {
                    app.UseExceptionHandler("/Error");
                    app.UseHsts();
                }
    
                app.UseHttpsRedirection();
                app.UseBlazorFrameworkFiles();
                app.UseStaticFiles();
                app.UseRouting();
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapRazorPages();
                    endpoints.MapControllers();
                    endpoints.MapFallbackToFile("index.html");
                });
            }
        }
    }
    

    i really don't know, what's get wrong? help me please

    Thursday, October 15, 2020 2:25 PM

Answers

  • User1535942433 posted

    Hi Prathamesh Shende,

    Accroding to your description, 405 HTTP code means Method Not Allowed. Served returned this error because action expects POST request (since it's marked with [HttpPost])  and  browser sends GET request.You must make sure your method is right.

    And your codes post aren't related with delete.You could post to us.And it will help us to solve your problem.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 16, 2020 6:48 AM