ASP.NET Web应用程序无法实时运行,但可以在本地运行

问题描述 投票:1回答:1

我正在将应用程序部署到Azure,但问题是某些方法(尤其是POST方法)在本地运行时会在实时站点上提供404。我一直在尝试使用BurpSuite对其进行调试,但似乎请求是相似的。

Localhost

Live site:

控制器:

    [HttpPost]
    public IActionResult SavePlan(string PlanDate)
    {
        DateTime dateFrom = DateTime.ParseExact(PlanDate, "dd/MM/yyyy", null);

        // Get planCart
        PlanCart planCart = GetPlanCart();

        // Validate MealPlan
        if (!ValidateMealPlan(planCart))
        {
            TempData["Error"] = "Error: MealPlan contains has too many diet restrictions per day.";
            return RedirectToAction("Index");
        }

        // Create and set MealPlan options
        MealPlan mealPlan = new MealPlan();
        mealPlan.dateFrom = dateFrom;
        mealPlan.dateTo = dateFrom.AddDays(7);
        mealPlan.Meals = planCart.returnList().ToArray();

        mealplanRepository.SaveMealPlan(mealPlan);

        return RedirectToAction("Index");
    }

Startup.cs:

  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)
    {
        // Add Identity server
        services.AddDbContext<AppIdentityDbContext>(options =>
            options.UseSqlServer(
            Configuration["Data:EasyMealIdentityServer:ConnectionString"]));

        // Add OrderCustomersServer
        services.AddDbContext<AppMealOrdersCustomersDbContext>(options =>
            options.UseSqlServer(
            Configuration["Data:EasyMealOrdersCustomersServer:ConnectionString"]));

        // EasyMealMealServer
        services.AddDbContext<AppMealsDbContext>(options =>
            options.UseSqlServer(
            Configuration["Data:EasyMealMealServer:ConnectionString"]));

        services.AddTransient<IMealRepository, EFMealRepository>();
        services.AddTransient<IOrderRepository, EFOrderRepository>();
        services.AddTransient<IMealplanRepository, EFMealplanRepository>();

        services.AddIdentity<AppUser, IdentityRole>()
         .AddEntityFrameworkStores<AppIdentityDbContext>()
         .AddDefaultTokenProviders();

        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => false;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        services.AddMemoryCache();
        services.AddSession();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseAuthentication();
        app.UseSession();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

        app.UseCookiePolicy();
    }
}

如果有人有什么想法可能会出错,将不胜感激!

c# asp.net-core
1个回答
0
投票

右键单击项目,单击属性,单击Web选项卡,向下滚动以查看带有端口的正确iis url。

[当您尝试发布到它时,请确保您正在执行localhost:<port>\<controller>\<action>

所以控制器可能在家里,动作是保存计划,在那之后您需要\ plandate

© www.soinside.com 2019 - 2024. All rights reserved.