Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my ASP.NET 5 Application Not Run On IIS 7.5?

I'm running ASP.NET 5 (Core) with IIS 7.5. I've already installed httpPlatformHandler and set the physical path of the site (in IIS) to the wwwroot folder that I published from visual studio 2015. All I get is the blank continuous loading page. I am pretty sure I have everything wired up correctly. Also, it loads up fine if I uncomment out the app.Run statement from within the Configure method and comment out the app.UseIISPlatformHandler, app.UseDefaultFiles, app.UseStaticFiles and app.UseMVC.

My Code is below. I don't know what else to do at this point. Any suggestions? If any other code snippets are needed, let me know.

Startup.cs (Configure method)

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);
        //});
    }

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" />

New Edit. I've updated my folder structure to MVC (using Controllers, Views, etc) and I've changed the Configure method a bit. Now it loads a blank screen and the console is logging a 404 not found. Anymore suggestions?

Adding my full 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);
like image 337
Brandon Avatar asked Oct 31 '22 06:10

Brandon


1 Answers

Have you looked at the IIS logs to see if the request is even making to IIS?

You can also try putting a simple middleware module inbetween each middleware module defined in the Configure() method of class Startup. Your middleware can write a message to the Windows event log stating where it's at in the Http pipeline and the contents of the response body. Kind of like putting in alerts to debug Javascript. That will at least let you know where it's hanging up or clearing the response body.

I posted a very easy to understand demo on github that demonstrates how to create middleware in three easy steps. Click here to go to that demo.

UPDATE: Try changing your Configure() method to the code below (put in your own route if mine isn't correct for your setup).

app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseStaticFiles();

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});
like image 143
Clint B Avatar answered Nov 15 '22 04:11

Clint B