This article demonstrates the usage of Forms Authentication. While working in a project, in spite of applying style sheet and user control in my login page, they were not getting reflected while running the application. I have mentioned the problem here.
Forms Authentication:- This approach needs a username and password. The user is let in after verification. If the user requests a page that requires authenticated access and that user has not previously logged on to the site, then the user is redirected to a login page. The user need to login page need to login by providing user name and password.
The fig(a) below is my solution explorer which has main Login.aspx page, followed by SamplePage.aspx
fig(a)
Open the web.config file, and type the following inside <system. web> tag
<authentication mode="Forms">
<forms loginUrl="Login.aspx" name="Login" defaultUrl="SamplePage.aspx" timeout="10" >
</forms>
</authentication>
<authorization>
<allow users ="?"/>
</authorization>
Now to go with Login.aspx form, my login form looks something like this: fig(c)
fig(c)
Here the header is a usercontrol "Header.ascx". Stylesheet.css , a stylesheet is also used.
Use the following source code:
Fig(d)
Here RedirectFromLoginPage method, redirects to the URL specified in the web.config, provided the user is authenticated.
Now let's try to run this application. At runtime the application looks like this:
fig(e)
The login page redirects to SamplePage.aspx.
Now here to note , that in login page the header and .css doesn't seem to showup. But after logging in , the stylesheet class does work. This inconsistency is due to forms authentication. Since forms authentication is used, the image used by Header.ascx and the stylesheet class Stylesheet.css can be accessed only after authentication. So in login page you can not see the image and the stylesheet effect while in SamplePage.aspx you get it !
By adding the below lines in web.config , outside <system.web> tag, you can get out of this problem.
<location path="Images/Header1.JPG">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="StyleSheet.css">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Now try running the application again.
So now the images and stylesheet appears .