Newbie to ASP.Net

  • Thread starter Thread starter Xarky
  • Start date Start date
X

Xarky

Hi,
I am writing a small application and I am facing the 2 following
problems.

1)
I have implemented an authentication screen (simple username and
password), and when user signs in, I use the following and redirect
user to a main page
Session["connected"] = username;

When user tries to visit the main page, without first having signed
in, in the Page_Load, I check the value of the Session["connected"]
and if its empty, I redirect user back to authentication screen.

Now when user signs out, Session["connected"] is set "" and user is
redirected to authentication screen.

When user have at leasted visted main page once in authenticated
state, and then in non-authenticated state, he tries again to visit
the main page, he is not being directed to authentication screen, but
entering main page normally. I tried to do some debugging in the
method Page_Load, but at the time descrived in this paragraph, it is
not entering in this method.

Is there any other method that I should handle/overload?


2)
I have followed this link to do a drop-down menu:
http://msdn.microsoft.com/library/d...ta/html/OfficeFrontPageCreateDropDownMenu.asp

Now one of the menu Items is Sign Out. In this Sign out I have done a
link to the Authentication screen described earlier. Now before I
redirect the user I require to do some operations like
Session["connected"] = "";

Can this be done with some scripting. I have done something similar
to this in another language, previously.


I hope someone understands my problems and helps me out.
Thanks in Advance
 
Hello Xarky,

You should look at the FormsAuthentication class [1]. All of this logic has
already been implemented for you, and it seems as if you're trying to reinvent
the wheel. Plenty of examples are available via a google search for FormsAuthentication
examples. This should solve both of your issues.
 
Hi,

For problem 1, I am following this link.
http://www.codeproject.com/aspnet/custom_authentication.asp

In the Page_Load of all secure pages I added the following
Response.Cache.SetCacheability(HttpCacheability.NoCache);

Now for most of secure pages its working, but for one of the pages,
after I sign out, I can still enter the url and visit the page. What
could this be?

For the 2nd problem I haven't found anything useful yet.

Can someone recommend me some links
Thanks


Matt Berther said:
Hello Xarky,

You should look at the FormsAuthentication class [1]. All of this logic has
already been implemented for you, and it seems as if you're trying to reinvent
the wheel. Plenty of examples are available via a google search for FormsAuthentication
examples. This should solve both of your issues.

--
Matt Berther
http://www.mattberther.com
Hi,
I am writing a small application and I am facing the 2 following
problems.
1)
I have implemented an authentication screen (simple username and
password), and when user signs in, I use the following and redirect
user to a main page
Session["connected"] = username;
When user tries to visit the main page, without first having signed
in, in the Page_Load, I check the value of the Session["connected"]
and if its empty, I redirect user back to authentication screen.

Now when user signs out, Session["connected"] is set "" and user is
redirected to authentication screen.

When user have at leasted visted main page once in authenticated
state, and then in non-authenticated state, he tries again to visit
the main page, he is not being directed to authentication screen, but
entering main page normally. I tried to do some debugging in the
method Page_Load, but at the time descrived in this paragraph, it is
not entering in this method.

Is there any other method that I should handle/overload?

2)
I have followed this link to do a drop-down menu:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_f
p2003_ta/html/OfficeFrontPageCreateDropDownMenu.asp
Now one of the menu Items is Sign Out. In this Sign out I have done a
link to the Authentication screen described earlier. Now before I
redirect the user I require to do some operations like
Session["connected"] = "";

Can this be done with some scripting. I have done something similar to
this in another language, previously.

I hope someone understands my problems and helps me out. Thanks in
Advance
 
Hi,
First problem has been solved.

But for 2nd problem nothing has been found yet.

I have the following piece of code. In reality it is a menu which has
more options.

<table class="navbar" width="100%">
<tr>
<td class="menuNormal" width="20%">
<p>Sign out</p>
</td>
</tr>
</table>

On the sign out option I require an onmousedown() event, that when
fires, does the following operations.

{
Session["UserID"] = "";
Response.Redirect(...to login page);
}


Can someone help me do it.
Thanks in Advance
 
Hi

I tried it with the following code, and it worked. But is this the
correct way to do it?

<a href=Login.aspx onmousedown="<% Session["UserID"] = "";%>">
 
Back
Top