Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net route中的连字符,与link一起使用,不';我不能直接工作_Asp.net_.net_Asp.net Core_Model View Controller_Routes - Fatal编程技术网

Asp.net route中的连字符,与link一起使用,不';我不能直接工作

Asp.net route中的连字符,与link一起使用,不';我不能直接工作,asp.net,.net,asp.net-core,model-view-controller,routes,Asp.net,.net,Asp.net Core,Model View Controller,Routes,我试图在URL路由中使用连字符。在ASP.NET核心MVC中。我设置了一个默认的MVC模板 我唯一要更改的是添加第一行: [Route("hello-dude")] public IActionResult Privacy() { return View(); } 现在,当我开始测试这个项目时,我点击隐私,它会显示正确的页面和URL。(http://localhost:44386/hello-杜德) 但当我进入地址栏并手动输入时,单击enter,我会得到“无法访问站

我试图在URL路由中使用连字符。在ASP.NET核心MVC中。我设置了一个默认的MVC模板

我唯一要更改的是添加第一行:

[Route("hello-dude")]
public IActionResult Privacy()
{
    return View();
}
现在,当我开始测试这个项目时,我点击隐私,它会显示正确的页面和URL。(http://localhost:44386/hello-杜德)

但当我进入地址栏并手动输入时,单击enter,我会得到“无法访问站点”

这是怎么回事

Startup.Cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace WebApplication8
{
    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)
        {
            services.AddControllersWithViews();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

可能非连字符路径在直接输入时也不起作用?或者可能您混淆了连字符、em连字符、连字符和所有类似的字符?你可以试着把宣传材料(或任何东西)粘贴进去。我甚至不把网址放进去。我点击隐私,然后进入地址栏,在已经存在的url上点击回车。我已经在我这边创建了一个测试演示,效果很好。请共享startup.cs路由配置和布局视图代码好吗。Startup.cs添加到问题中。可能直接输入时非连字符路由也不起作用?或者可能您混淆了连字符、em连字符、连字符和所有类似的字符?你可以试着把宣传材料(或任何东西)粘贴进去。我甚至不把网址放进去。我点击隐私,然后进入地址栏,在已经存在的url上点击回车。我已经在我这边创建了一个测试演示,效果很好。请共享startup.cs路由配置和布局视图代码好吗。问题中添加了Startup.cs。