我正在将应用程序部署到Azure,但是问题是某些方法(特别是POST方法)在实际在本地工作时会在实时站点上提供404。我一直在尝试使用BurpSuite对其进行调试,但似乎请求是相似的。
控制器:
[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();
}
}
视图中的表单(Index.cshtml):
<form id="PlanForm" asp-action="SavePlan" asp-controller="Plan" method="post">
<input id="PlanDate" name="PlanDate" value="" type="hidden" />
<button class="btn btn-success" type="submit">Save selection</button>
</form>
PlanDate,所需参数通过javascript设置。您可以在BurpSuite的请求中看到它确实已发送。我以为也许是问题所在。
如果有人有什么想法可能会出错,将不胜感激!
答案 0 :(得分:1)
**编辑2:您需要格式化日期客户端并使用clientinfo服务器端来避免mm / dd / yyyy与dd / mm / yyyy不匹配!
编辑1: 您是否在日期中传递斜线?那会破坏它。 而不是用短划线传递日期或在javascript中将其转义。**
右键单击项目,单击属性,单击Web选项卡,向下滚动以查看带有端口的正确iis URL。
.net核心使用launchSettings.json并找到应用程序URL。
当您尝试发布到它时,请确保您正在做localhost:<port>\<controller>\<action>
所以控制器可能在家里,动作是保存计划,然后需要\ plandate