0

I have developed an SPA app using Aurelia in ASP.NET Core. Right now, I in my startup.cs file I have the following in my configure method:

app.UseIISPlatformHandler();

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseStaticFiles();

            app.UseFileServer(new FileServerOptions
            {
                EnableDefaultFiles = true,
                EnableDirectoryBrowsing = false
            });

From what I understand, this app.UseStaticFiles() directs the app to look in the wwwroot folder for a default.html or index.html. I want to somehow do some business logic to check the users windows username and run it through our business logic to check/verify it. Is there a way in which I can just create a home controller and have that controller return the wwwroot/index.html file after it does the proper checking or maybe even accomplish this from within the startup.cs file? If so, can you elaborate on how.

1

1 Answer 1

1

I think the best solution for that will be inserting you file in view folder. Then add to startup

    app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});

In Index method put your business logic for checking for verify.

If you interested in nice solutution for autenticate user you can look at : https://docs.asp.net/en/latest/security/authentication/identity.html

Sign up to request clarification or add additional context in comments.

6 Comments

I've got my index.html in my wwwroot folder. Is there a way that I can redirect to that file from the controller?
Juste use return File("~/index.html", "text/html");
@Kalten I have all of these other files that need to be rendered along with the index.html file. For example, my scripts, libraries, require.js, etc. How do I accomplish that?
If you need to validate each files, edit the route template to match all query. And in your controller, use the Context.Request property to get the requested file. But custom middleware best fit for this case.
@Kalten I don't need to validate each file. There's only 1 html file in the wwwroot folder, but when I return my file in my controller, I'm getting an error that it's not loading my scripts (in the wwwroot) folder. What's the syntax to bundle everything or "request" everything all together?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.