There are php sites in other folders in the httpdocs folder of the server. Could it be conflicting with these sites?
ASP.NET Core Web Site Publishing Problem from Subfolder
Hello,
I am developing a website using Visual Studio with [ASP.NET] Core MVC (C#) .NET 8 and I have published my site. My project files are located in the httpdocs/frez folder of the server. But normally web files should be in the httpdocs folder. When I put my project files in the httpdocs folder the site works fine, but I need to keep these files in the httpdocs/frez folder.
I made the following edits to Program.cs to make it work in this folder structure:
builder.WebHost.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), “httpdocs”, “frez”));
I also edited my Web.config file as follows:
<?xml version=“1.0” encoding=“utf-8”?>
<configuration>
<location path=“.” inheritInChildApplications=“false”>
<system.webServer>
<handlers>
<add name=“aspNetCore” path=“*” verb=“*” modules=“AspNetCoreModuleV2” resourceType=“Unspecified” />
</handlers>
<aspNetCore processPath=“dotnet” arguments=“./frez/project.dll” stdoutLogEnabled=“true” stdoutLogFile=“./logs/stdout” hostingModel=“inprocess” />
<rewrite>
<rules>
<rule name=“Rewrite to frez folder” stopProcessing=“true”>
<match url=“(.*)” />
<action type=“Rewrite” url=“/{R:1}” />
</rule>
</rules>
</rewrite>
</system.webServer>
</location>
</configuration>
Although I made these arrangements, my website is not working. Can you help me to solve the problem?
Developer technologies ASP.NET ASP.NET Core
Developer technologies C#
4 answers
Sort by: Most helpful
-
-
SurferOnWww 4,706 Reputation points
2024-11-30T01:57:42.6666667+00:00 Why don't you deploy your ASP.NET Core app as the site of IIS according to the Microsoft tutorial Publish an ASP.NET Core app to IIS?
-
Anonymous
2024-11-29T03:31:23.27+00:00 Hi @Enes Gündoğdu,
This is my structure in IIS site. In my scenario, the
web.config
under thehttodocs
takes effect, and theweb.config
under thefrez
folder does not ...Program.cs
//var builder = WebApplication.CreateBuilder(args); //builder.WebHost.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "httpdocs", "frez")); //Console.WriteLine(Path.Combine(Directory.GetCurrentDirectory(), "httpdocs", "frez")); using Microsoft.Extensions.FileProviders; string basedir = AppDomain.CurrentDomain.BaseDirectory; WebApplicationOptions options = new() { ContentRootPath = basedir, Args = args, WebRootPath = Path.Combine(basedir, "wwwroot") }; var builder = WebApplication.CreateBuilder(options); // Add services to the container. builder.Services.AddControllersWithViews(); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); //app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(basedir, "wwwroot")), RequestPath = "/frez" }); app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run();
httpdocs/web.config
<?xml version="1.0" encoding="utf-8"?> <configuration> <location path="." inheritInChildApplications="false"> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> </handlers> <aspNetCore processPath="dotnet" arguments=".\frez\WebApplication18.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" /> <rewrite> <rules> <rule name="Add Frez Prefix to Static Files" stopProcessing="true"> <match url="^lib/(.*)" /> <action type="Rewrite" url="/frez/lib/{R:1}" /> </rule> <rule name="Add Frez Prefix to CSS and JS Files" stopProcessing="true"> <match url="^(css|js)/(.*)" /> <action type="Rewrite" url="/frez/{R:1}/{R:2}" /> </rule> <rule name="Add Frez Prefix to Other Static Files" stopProcessing="true"> <match url="^(images|fonts)/(.*)" /> <action type="Rewrite" url="/frez/{R:1}/{R:2}" /> </rule> </rules> </rewrite> </system.webServer> </location> </configuration> <!--ProjectGuid: 4b4aa7f2-0cce-41fd-ab2e-73900cd8dc9e-->
**
**
Test Result
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Jason
-
Enes Gündoğdu 0 Reputation points
2024-11-29T10:10:31.5833333+00:00 When I open the website, this is what it says on the screen;
This page is not working
website.com is unable to handle this request at this time.
HTTP ERROR 500