3

How to route Static Files Dynamically in Asp.Net & Asp.Net Core

Hi All, i have to build an application , which will have both static files & dynamic content to be displayed, how can i do this with Asp.Net Core & Asp.Net MVC

Example

       I have site 

            http://dummy.com/

now there are some routes where i need to server its default content but depending on wether the request is from mobile or Desktop i need to change the files

          Ex : http://dummy.com/category1
               index.html
               index-m.html

               in this category1 has a folder & in the site and it has two static files like above
               now when there is a request for "http://dummy.com/category1" i have to check wether its from mobile or desktop
               if its mobile "index-m.html" should be server else "index.html" should be served

         Ex : http://dummy.com/category/getcategories

              this is a dynamic route , when this is requested it should go to its default Action method and get the result

Can any one help me, what do i have to do here to get this

SoftwareNerd
  • 1,875
  • 8
  • 29
  • 58
  • 2
    Serving a different html based on the type of a device is... outdated. A better idea is to have a single html file that has responsive design. – Teodor Kurtev May 24 '17 at 09:56
  • @TeodorKurtev the reason for doing this is , our sites SEO focused, we want the mobile version to be light & fast – SoftwareNerd May 24 '17 at 11:42

2 Answers2

1

To serve static files, in RegisterRoutes(RouteCollection routes), add the following ignore rules:

routes.IgnoreRoute("{file}.html");

Please see the following answer for additional information: Using ASP.NET routing to serve static files

Julien Ambos
  • 2,010
  • 16
  • 29
-3

Use javascript to detect screen resolution.

If screen resolution width is less than 800 pixels, redirect you page to mobile version.

Please let me know if I can help further.