iolevel / wpdotnet-sdk

WordPress compiled to .NET Standard. SDK for ASP.NET Core.
http://www.wpdotnet.com
Other
414 stars 69 forks source link

Integrate PeachPie Wordpress to existing .net core app #128

Closed anilkumarvs closed 1 year ago

anilkumarvs commented 1 year ago

I have successfully integrated peachpie wordpress into an ASP.Net Core 6 Web application. But the problem now is, due to routing the current website is not accessible and instead showing the wordpress site as the entry point of the website. I want to move this entire wordpress under a subfolder, may be "content".

I have added some mapping like app.Map(new PathString("/content"), wordpressApp => { wordpressApp.UseWordPress(); });

This help to access the main website and wordpress (under /Content) separately. But the problem is only wordpress home page is working. The links from wordpress home page and wp-admin etc, are not working due to routing issue.

Can anyone help to fix this issue. Need to access both existing core web app and wordpress simultaneously.

jakubmisek commented 1 year ago

Thank you for the question!

There are two options

  1. order matters - write app.UseWordPress() after other middlewares.
  2. move WordPress into a subpath in your ConfigureServices() method:
    services.AddWordPress(options =>
            {
                options.HomeUrl =
                options.SiteUrl = "https://localhost:5004/wp";
            });
anilkumarvs commented 1 year ago

Thanks for the help. I tried to implement the change, but still not succeed. Now only wordpress site is showing. Please see my program.cs code below. Can you please have a look and give suggestion.

    var builder = WebApplication.CreateBuilder(args);

    builder.Services.AddControllersWithViews();
    builder.Services.AddSwaggerGen();

    builder.Services.AddHttpClient();

    builder.Services.AddWordPress(options =>
    {
        options.HomeUrl = "https://localhost:7288";
        options.SiteUrl = "https://localhost:7288/wp";
    });

    builder.Services.AddAuthentication();

    builder.Services.AddHttpContextAccessor();

    builder.Services.AddAuthorization();

    ConfigurationManager configuration = builder.Configuration;

    var app = builder.Build();

    app.UseHttpsRedirection();
    app.UseStaticFiles();  

    app.UseRouting();

    app.UseAuthentication();
    app.UseAuthorization();

    app.UseWordPress();

    app.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");

    app.Run();
jakubmisek commented 1 year ago

please see my reply above:

  1. order matters - write app.UseWordPress() after other middlewares.
anilkumarvs commented 1 year ago

Dear Jakub, That worked. Thank you so much. Now both my .net web and wordpress works fine.