【发布时间】:2019-10-16 17:22:56
【问题描述】:
当我部署我的网站时,它会更改为某些项目生成的锚链接。在我的本地服务器上,链接原来是http://localhost:49377/Recipe/1,当我单击它时它可以工作。在我部署的服务器上,它显示了deployedsserver.net/Home/Index/1?page=%2FRecipe。
发生变化的是 Menu.cshtml 中的这个链接:
<h3><a asp-page="/Recipe" asp-route-id="@recipe.Id">@recipe.Name</a></h3>
我认为这可能是一些路由问题,但我不知道它是什么。我仍在查看文档,但希望有人可以帮助我或为我指明正确的方向。
我的 Menu.cshtml 中有以下代码
@page
@{
var recipes = await RecipesService.GetAllAsync();
}
@section Title {
<h2 class="title">My Favorite Recipes</h2>
}
<div class="row recipes">
@foreach (var recipe in recipes)
{
<div class="recipe col-md-4 burgerBlackBoard">
<img class="img burgerImage" src="@recipe.GetInlineImageSrc()" />
<h3><a asp-page="/Recipe" asp-route-id="@recipe.Id">@recipe.Name</a></h3>
</div>
}
</div>
这是我的 Recipe.cshtml 页面:
@page "{id}"
@{
var id = long.Parse((string)RouteData.Values["id"]);
var recipe = await RecipesService.FindAsync(id);
ViewData["Title"] = recipe.Name;
}
<div class="row recipe burgerBlackBoard">
<div class="col-6 ">
<div class="col-8 text-center">
<span class="description">
@recipe.Description
</span>
</div>
<div class="col-2 text-center">
<img class="img burgerImage" src="@recipe.GetInlineImageSrc()" />
</div>
<hr />
</div>
<div class="ingredients col-6">
<h3 class="text-center">Ingredients</h3>
<ul>
@foreach (var ingredient in recipe.IngredientsList)
{
<li>@ingredient</li>
}
</ul>
</div>
</div>
我的 startup.cs 包含我的路由:
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
services.AddMvc().AddRazorPagesOptions(options =>
{
options.Conventions.AuthorizeFolder("/Admin");
options.Conventions.AuthorizeFolder("/Account");
options.Conventions.AllowAnonymousToPage("/Account/Login");
}); //dependency injection
services.AddTransient<IRecipesService, RecipesService>();
}
// 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();
}
app.UseAuthentication();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
}
【问题讨论】:
标签: c# asp.net asp.net-core .net-core razor-pages