Hi @Enes Gündoğdu,
This is my structure in IIS site. In my scenario, the web.config
under the httodocs
takes effect, and the web.config
under the frez
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