Jam*_*mes 5 c# asp.net iis asp.net-mvc
我正在使用IIS 7.5运行ASP.NET 5(Core).我已经安装了httpPlatformHandler并将站点的物理路径(在IIS中)设置为我从visual studio 2015发布的wwwroot文件夹.我得到的只是空白的连续加载页面.我很确定我已经正确连接了所有内容.此外,如果我从Configure方法中取消注释app.Run语句并注释掉app.UseIISPlatformHandler,app.UseDefaultFiles,app.UseStaticFiles和app.UseMVC,它会加载正常.
我的代码如下.我不知道此时还有什么可做的.有什么建议?如果需要任何其他代码段,请告诉我.
Startup.cs(配置方法)
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.UseIISPlatformHandler();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvc();
//app.Run(async (context) =>
//{
// var greeting = greeter.GetGreeting();
// await context.Response.WriteAsync(greeting);
//});
}
Run Code Online (Sandbox Code Playgroud)
web.config中
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600" forwardWindowsAuthToken="true" />
Run Code Online (Sandbox Code Playgroud)
新编辑.我已经将我的文件夹结构更新为MVC(使用控制器,视图等),并且我已经更改了Configure方法.现在它加载一个空白屏幕,控制台正在记录未找到的404.还有什么建议吗?
添加我的完整Startup.cs:
public IConfiguration Configuration { get; set; }
public static string ConnectionString { get; set; }
public Startup()
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsetting.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
ConnectionString = Configuration.GetSection("connString").Value;
}
// 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 http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.UseIISPlatformHandler();
//app.UseDefaultFiles();
app.UseFileServer(true);
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}");
});
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
Run Code Online (Sandbox Code Playgroud)
您是否查看过 IIS 日志以查看是否向 IIS 发出了请求?
您还可以尝试在 Startup 类的 Configure() 方法中定义的每个中间件模块之间放置一个简单的中间件模块。您的中间件可以向 Windows 事件日志写入一条消息,说明它在 Http 管道中的位置以及响应正文的内容。有点像放入警报来调试 Javascript。这至少会让您知道它挂起或清除响应主体的位置。
我在 github 上发布了一个非常容易理解的演示,演示了如何通过三个简单的步骤创建中间件。单击此处转到该演示。
更新:尝试将您的Configure()方法更改为下面的代码(如果我的路线不适合您的设置,则放入您自己的路线)。
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
830 次 |
| 最近记录: |