Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.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
C# ASP.NET核心MVC:此本地主机页可以’;找不到_C#_Asp.net Core_Asp.net Core Mvc - Fatal编程技术网

C# ASP.NET核心MVC:此本地主机页可以’;找不到

C# ASP.NET核心MVC:此本地主机页可以’;找不到,c#,asp.net-core,asp.net-core-mvc,C#,Asp.net Core,Asp.net Core Mvc,使用操作方法创建了用户控制器。右键单击“Upsert”操作方法并添加一个查看页面 问题是当我使用此URL进入浏览器时 https://localhost:44318/Admin/User/Upsert userId正在获取,但显示错误 找不到此本地主机页 同时,我的另一个操作方法正确地运行同一个控制器,如UserLock、userdelete等 public class UserController : Controller { private readonly Application

使用操作方法创建了用户控制器。右键单击“Upsert”操作方法并添加一个查看页面

问题是当我使用此URL进入浏览器时

https://localhost:44318/Admin/User/Upsert
userId
正在获取,但显示错误

找不到此本地主机页

同时,我的另一个操作方法正确地运行同一个控制器,如UserLock、userdelete等

public class UserController : Controller
{
    private readonly ApplicationDbContext _db;
    private readonly RoleManager<IdentityRole> _roleManager;
    private readonly UserManager<IdentityUser> _userManager;

    public UserController(ApplicationDbContext db)
    {
        _db = db;
    }

    public IActionResult Index()
    {
        return View();
    }

    public IActionResult Upsert(string userId)
    {
        ........
        return View(objFromDb);
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public IActionResult Upsert(ApplicationUser user)
    {
        .......
        return View(user);
    }
}
公共类UserController:Controller
{
私有只读应用程序dbContext_db;
专用只读角色管理器(RoleManager);
私有只读用户管理器_UserManager;
公共用户控制器(ApplicationDbContext数据库)
{
_db=db;
}
公共IActionResult索引()
{
返回视图();
}
公共IActionResult Upsert(字符串用户ID)
{
........
返回视图(objFromDb);
}
[HttpPost]
[ValidateAntiForgeryToken]
公共IActionResult Upsert(应用程序用户用户)
{
.......
返回视图(用户);
}
}
StartUp.cs

using BornoMala.DataAccess.Data;
using BornoMala.DataAccess.Repository;
using BornoMala.DataAccess.Repository.IRepository;
using BornoMala.Utility;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BornoMala
{
    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.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(
                    Configuration.GetConnectionString("DefaultConnection")));
            services.AddDatabaseDeveloperPageExceptionFilter();

            services.AddIdentity<IdentityUser, IdentityRole>().AddDefaultTokenProviders()
                .AddEntityFrameworkStores<ApplicationDbContext>();
            services.AddSingleton<IEmailSender, EmailSender>();
            services.AddControllersWithViews();
            services.AddRazorPages();

            services.AddScoped<IUnitOfWork, UnitOfWork>();
        }

        // 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();
                app.UseMigrationsEndPoint();
            }
            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.UseAuthentication();
            app.UseAuthorization();

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

使用BornoMala.DataAccess.Data;
使用BornoMala.DataAccess.Repository;
使用BornoMala.DataAccess.Repository.IRepository;
使用BornoMala.Utility;
使用Microsoft.AspNetCore.Builder;
使用Microsoft.AspNetCore.Hosting;
使用Microsoft.AspNetCore.HttpsPolicy;
使用Microsoft.AspNetCore.Identity;
使用Microsoft.AspNetCore.Identity.UI;
使用Microsoft.AspNetCore.Identity.UI.Services;
使用Microsoft.EntityFrameworkCore;
使用Microsoft.Extensions.Configuration;
使用Microsoft.Extensions.DependencyInjection;
使用Microsoft.Extensions.Hosting;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
名称空间BornoMala
{
公营创业
{
公共启动(IConfiguration配置)
{
配置=配置;
}
公共IConfiguration配置{get;}
//此方法由运行时调用。请使用此方法将服务添加到容器中。
public void配置服务(IServiceCollection服务)
{
services.AddDbContext(选项=>
options.UseSqlServer(
GetConnectionString(“DefaultConnection”);
AddDatabaseDeveloperPageExceptionFilter();
services.AddIdentity().AddDefaultTokenProviders()
.AddEntityFrameworkStores();
services.AddSingleton();
services.AddControllersWithViews();
services.AddRazorPages();
services.addScope();
}
//此方法由运行时调用。请使用此方法配置HTTP请求管道。
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseMigrationsEndPoint();
}
其他的
{
app.UseExceptionHandler(“/Home/Error”);
//默认的HSTS值为30天。您可能希望在生产场景中更改此值,请参阅https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(端点=>
{
endpoints.MapControllerRoute(
名称:“默认”,
模式:“{area=Customer}/{controller=Home}/{action=Index}/{id?}”);
endpoints.MapRazorPages();
});
}
}
}
找不到此本地主机页

请检查是否以正确的文件夹结构组织控制器和视图,如下所示

并检查控制器是否与某个区域关联

[Area("Admin")]
public class UserController : Controller
{
    //...
有关在ASP.NET Core中使用区域的详细信息,您可以查看以下文档:


此控制器是否在管理区,能否显示startup.cs?Asp.net core MVC 5.0@masonHi@SoumikMahajan,有关此案例的任何更新?感谢您的回答,我已经解决了。您好@SoumikMahajan,您找到问题的根本原因了吗?返回错误的数据类型<代码>返回错误的数据类型因此,你能分享这个问题的实际解决方案吗?