Click here to Skip to main content
15,353,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have 1 mvc application and that is running fine on 2 url's with the same code deployed to different folder for both the url's to work.

URL's are like https://www.abc.com/ - web form authentication
https://www.abc.com/AD/ - windows authentication

Now the requirement is we have 2 deploy the code in one folder only and both the url's should work like earlier when we are deploying in 2 folders for same application.

so now we have to create a folder named AD within the MVC application and call home controller from root directory after windows authentication.

Any help will be appreciated

What I have tried:

I've tried creating a folder named AD within the application and used windows authentication but when I put my credentials and trying to redirect on root folder's home controller then getting error that resource not found. and sometimes there is no route configured.

also I've tried creating a *.aspx page and redirecting from there
Response.Redirect("../Home/Index");
this.Response.RedirectToRoute("~/Home/Index"); but noting works.
Posted
Updated 5-Aug-21 1:58am

1 solution

You'll need a Windows Authentication action on your Home controller:
C#
[Authorize]
[Route("AD")]
public ActionResult WindowsLogin(string returnUrl = null)
{
    FormsAuthentication.SetAuthCookie(User.Identity.Name, false);
    if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl)) return Redirect(returnUrl);
    return RedirectToAction(nameof(Index));
}
Then update your web.config file to turn on Windows authentication for that route:
XML
<location path="AD">
    <system.webServer>
        <security>
            <authentication>
                <windowsAuthentication enabled="true" />
                <basicAuthentication enabled="true" />
                <anonymousAuthentication enabled="false" />
            </authentication>
        </security>
    </system.webServer>
</location>
You may need to "unlock" these sections:

If you're using IIS, open IIS Manager, open the "Feature Delegation" page from the Management group. Find the four "Authentication - ..." sections, and ensure that they are set to "Read/Write".

If you're using IIS Express, you'll need to edit the applicationHost.config file, which is located in the hidden ".vs\Project_Name\config" folder within your solution folder.
   
Comments
Ashutoshkrsingh 9-Aug-21 15:21pm
   
I've tried this but getting below error
HTTP Error 500.22 - Internal Server Error
An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

and if I change pipeline mode to classic then the actual https://www.abc.com/ is not working
Richard Deeming 10-Aug-21 2:53am
   
Don't change it to "classic" pipeline; find the setting it's complaining about and fix that instead.

If you open the page in a browser running on the server itself, you should get a detailed error message which will tell you which setting it doesn't like.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900