I have an intranet application that uses windows authentication to get the username and then sets the application user to a user found within the application database. How can I authenticate on whether the user exists in the application database and then serve a custom error page.
I am receiving statusCode 500 internal server error when trying to log into the intranet application using a user not found in the database but despite setting custom errors on and trying to redirect to a specific page I am getting a strange error where the url gets changed to:
http://servername:82/NotFound.cshtml?aspxerrorpath=/
In my web config I have:
<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>
Within system.web I have tried:
<customErrors mode="On" defaultRedirect="~/Views/Shared/NotRegistered.cshtml" />
And also tried:
<customErrors mode="On"
<error statusCode="401" redirect="~/Views/Admin/NotFound.cshtml" />
<error statusCode="402" redirect="Error.cshtml" />
<error statusCode="403" redirect="Error.cshtml" />
<error statusCode="404" redirect="Error.cshtml" />
<error statusCode="500" redirect="NotFound.cshtml" />
</customErrors>
What is the best way to authenticate that the windows user has a related account and if not redirect them to the relevant not registered page. When using forms authentication I was able to do this:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>
This automatically directed users to the login page when they were not authenticated. Is there a similar property when using windows authentication?