2 years ago
#66456

Flash Death
404 When running .Net application when using IISExpress
Like the title says I'm getting a 404 when trying to start my .net app with IIS Express in Visual Studio. I'm thinking it has to have something to do with my routing, but I can't figure out why. It never gets to my controller and this happens immediately after it setups up my claimstransformer.
Here is my Startup:
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<MyContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddTransient<IClaimsTransformation, ClaimsTransformer>();
services.Configure<CookiePolicyOptions>(options => {
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddAuthentication(IISDefaults.AuthenticationScheme);
services.AddAuthorization();
services.Configure<IISServerOptions>(options => {
//kpd debug toggled to true
options.AutomaticAuthentication = true;
});
services.AddAuthorization(options => {
options.AddPolicy(CONSTANTS.EDIT_POLICY_NM, policy => policy.Requirements.Add(new SameAuthorRequirement()));
... More Authorizations ...
services.AddSingleton(Configuration);
services.AddSingleton<IAuthorizationHandler, MyAuthorizationHandler>();
services.AddScoped<IDocumentRepository, MyRepository>();
services.AddMvc();
}
// 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(CONSTANTS.ERROR_REDIRECT_URL);
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
*** This is where it goes into immediately after my claimstransformer setup with 404 ***
app.UseStatusCodePages(async context => {
HttpResponse response = context.HttpContext.Response;
HttpRequest request = context.HttpContext.Request;
context.HttpContext.Response.ContentType = "text/plain";
await context.HttpContext.Response.WriteAsync(CONSTANTS.STATUS_CODE_MSG + response.StatusCode
+ " for user: " + context.HttpContext.User.Identity.Name);
});
app.UseEndpoints(endpoints => {
//Home
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
... More Routes ...
});
}
}
My IIS Express settings:
{
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iis": {
"applicationUrl": "http://localhost:",
"sslPort": 0
},
"iisExpress": {
"applicationUrl": "https://localhost:44375/",
"sslPort": 44375
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "https://localhost:44375/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
},
"use64Bit": true
}
}
}
My web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" hostingModel="InProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44375" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Any help is greatly appreciated!
c#
.net
asp.net-mvc
iis
http-status-code-404
0 Answers
Your Answer