1

Is it possible to use this URL domain.tld/android_application_name.apk to serve an Android application apk file from AndroidApplications directory?

In other words, I have a folder sibling to Controllers folder and wwwroot folder and Program.cs file. It's called AndroidApplications and inside it I have a bunch of .apk files. But I don't want to add an extra segment to the URL for them. I want to be able to serve app1.apk via this URL: domain.tld/app1.apk. How can I achieve that?

6
  • Did you tried reading the docs and the static files middleware? learn.microsoft.com/en-us/aspnet/core/fundamentals/… Commented May 7, 2018 at 7:44
  • @Tseng, thanks for the link. Yeah I've read that. My case is very special and I've done many things to make it work. Yet it doesn't. Please see my previous question Commented May 7, 2018 at 8:26
  • I don't see anything special about serving a static file from an ASP.NET Core application and nothing in your question hints that there is some special requirement and WHICH requirement that may be. With static files middleware any file located in wwwroot folder can be served back as download as long as it exists (and if registered before other middlewares, registration order matters) Commented May 7, 2018 at 9:56
  • @Tseng, if you read the question carefully, my .apk files are located inside another folder. And to serve from another folder, we need a path segment to be specified. In other words, you can't serve /something.jpg from another folder. You need to serve it via /some-path-segment/something.jpg. But I already have my URLs published to other places, so I can't prefix them. Commented May 7, 2018 at 10:20
  • Did u get this working i think the term u mean is provision. I am wanting to do same with customers app Commented Sep 26, 2021 at 1:36

2 Answers 2

1

You should have a look at the Url Rewriting Middleware.

public void Configure(IApplicationBuilder app)
{
    var options = new RewriteOptions()
        .AddRewrite(@"^(.*?\.apk)$", "AndroidApplications/$1", 
            skipRemainingRules: true)

    app.UseRewriter(options);
}

This should rewrite all urls ending with apk, i.e. from /myapp.apk urls to /AndroidApplications/myapp.apk.

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

Comments

1

I've seen a few answers like: 1) add ".apk" extension and correspoding mime type in IIS

enter image description here

2) add below node in system.webServer node of web.config

But neither works.

So I found another solution and it works for me

3) set ServeUnknowFileType of StaticFileOptions to true in the Configure method of Startup

var staticFileOptions = new StaticFileOptions { ServeUnknownFileTypes = true };

        app.UseStaticFiles(staticFileOptions);

But I'm worried about the security issue.

Also the above two solutions might be for windows only, it will still be an issue when migrated to linux, correct me if I'm wrong.

Comments

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.