I have an Asp.Net Core app that integrates Views and Controllers. the app works without error. However, When I separated the app's Views and Controllers into two Asp.Net Core apps, it doesn't work properly. Views work as before but Controllers don't.
I followed one of the instructions mentioned at How to host multiple .NET Core apps under the same URL?
I did put Controllers to API Directory and Views in Main Directory like this
/Website
/api
/swagger
/api.dll
/api.exe
/...
/web.config
/wwwroot
/front.dll
/front.exe
/...
/web.config
When I hit www.exampl.com/api/login
, encounter the below error:
500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.
However, When I hit www.exampl.com/index
which is the default page. It works perfectly.
I enabled Browsing Directory in IIS, but not worked.
my Controllers are Routed like below:
namespace MyAppControllers
{
[Route("[controller]")]
[ApiController]
public class loginController: ControllerBase
...
I worth saying that, I enabled logging into both web.config but no error detected.
Update
I just tested Controllers in a separated website, works and swagger appears
http://www.example.com:12345/swagger/index.html
Update 2
Asp.Net Core Web API
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.UseRouting();
app.UseAuthorization();
app.UseCors("mPolicy");
app.Use((context, next) =>
{
context.Response.Headers["Access-Control-Allow-Origin"] = "*";
return next.Invoke();
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
Update 3
I've enabled Detailed Error and I see below error thrown
Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'aspNetCore
However, when I tried the solutions explained here
The 500 - Internal Error is converted to 404 - Not Found.
Either way, the problem still exists.