1

My hosting plan includes 1 site. I have installed a Asp.Net MVC Core 2 project on that site and it is working as designed. Now I would like install a blog on the same site in a subdirectory. The blog I am using is Wordpress. Wordpress is installed to a subdirectory on the Asp.Net MVC Core 2 site. When I run the Wordpress blog I get a .NET error page with the error:

Status Code: 404; Not Found

if the Asp.Net MVC Core 2 site runs at www.example.com, i want the blog site to run at www.example.com/blog

I assume Asp.Net MVC Core 2 is looking for a BlogController when I go the blog directory. Is there a setting in IIS7 or Asp.Net MVC Core 2 (Startup.cs or other config file) that tells it to leave the blog directory alone and not use .NET?

Note: i read MVC3 web site with Wordpress in subdirectory, but it is for MVC3 not Asp Net MVC core 2

seisal
  • 11
  • 1
  • 1
    You can add an ignore route to your Startup.cs, but I wouldn't recommend ASP & WP combination in the same hosting. Wordpress sucks and very slow. It is hard to configure it properly on the same hosting and it will kill your ASP performance. You can either install an ASP blog library, or get a separate hosting for WP and redirect the subdirectory to there at the hosting (it will redirect even before reaching ASP, so you don't have to change anything) using a subdomain blog.example.com (you can do this with your current configuration if you really want to ignore my advice above). – Racil Hilan Jun 16 '18 at 12:53
  • Thanks for reply, unfortunately ignore route not valid in asp net core, i read https://stackoverflow.com/questions/39517816/how-to-ignore-routes-in-asp-net-core-1-0-1 about ignore route but i don't know what i should replace with context.Response.StatusCode = 404. thanks for your offer about using another host but now I like to know how to solve problem regardless the performance :)) is there anyway? – seisal Jun 16 '18 at 13:19
  • Yes, by "ignore route", I was not referring to the `IgnoreRoute()` method which is not available for Code. It is better to do the redirection in IIS instead, but most shared hosting providers limit what you can do with IIS, so see my answer for an alternative approach. – Racil Hilan Jun 16 '18 at 13:35
  • really thanks for detail description, I do your alternative approach, upload wordpress to blog subdirectory and create blog subdomain, and redirection happens from blog.example.com to example.com/blog but still give me "404 Not found" ! :( – seisal Jun 16 '18 at 13:47
  • That's not right, the redirection shouldn't change from blog.example.com to example.com/blog. It should stay as blog.example.com in the URL. Talk to your hosting provider to see if they can help configure it properly. They will need to exclude the `/Blog` folder from ASP in IIS. If they cannot help, you will have to ignore the route using the middleware. See how [`UseStaticFiles()`](https://github.com/aspnet/StaticFiles/tree/dev/src/Microsoft.AspNetCore.StaticFiles) does it for static files and try to mimic the code. – Racil Hilan Jun 16 '18 at 14:41
  • if you mean that i create a virtual directory, i create it and not working :( . about to exclude /Blog from IIS in ASP, I asked for it from provider and so far I have not received any answer. about ignore route, really i don't know how to use it as i say in the first comment. can you guide me how to use it? – seisal Jun 16 '18 at 15:52

1 Answers1

0

You can add an ignore route to your Startup.cs, but it is better to configure it directly in IIS instead. Most hosting providers allow you to create subdomains, so you can create blog.example.com and redirect it to the subfolder /blog. This redirection will be done at IIS level and before the request even reaches ASP.Net, so you don't have to change anything.

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
  • If subdomain would be an option, than two separate websites with the different host name bindings would be a simple solution. Probably for some reasons (SEO or technical, or cost) the subdomain does not play – g.pickardou Jan 24 '19 at 05:12