英文:
Redirecting Razor page in .NET Core 3.1
问题
我在我的页面文件夹中有一个Razor页面,公共类名为DoStuffModel:PageModel。我想让我的域名/do_stuff访问到我的页面。
我尝试过将以下内容添加到启动文件中:
endpoints.MapControllerRoute(
name: "do_stuff",
pattern: "do_stuff",
defaults: new { page = "/DoStuff" });
还尝试了其他一些方法。这不应该那么难。我已经将其作为do_stuffModel工作,但那是一个糟糕的名称。
英文:
I have a Razor page public class DoStuffModel : PageModel in my Pages folder. I want mydomain/do_stuff to hit my page.
I have tried adding this to startup
endpoints.MapControllerRoute(
name: "do_stuff",
pattern: "do_stuff",
defaults: new { page = "/DoStuff" });
and a few other things. This can't be that hard. I have it working as do_stuffModel, but that is a terrible name.
答案1
得分: 1
为此,请在ConfigureServices
方法中添加以下服务:
services.AddRazorPages();
接下来,添加此中间件:
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
现在,您可以使用Razor Page
,但如果您想在其前面添加路径,您可以在页面文件夹中添加文件夹,例如mydomain/newfolder/mypages
。
英文:
For this first add this service in ConfigureServices
method:
services.AddRazorPages();
Next add this middleware
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
Now you can use Razor Page
but if you want to add path before it you can add folder in pages folder like this mydomain/newfolder/mypages
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论