|
I have login page and a main page in the asp.net application.In web.config, session Timeout value is set as 5 mins.
My requirements are as below
1.If the main page is idle for 5 mins, the session will expire and the same page will be retained. If the user tries to do some action then it has to redirect to loginpage.
bebuggiung steps
1.comes to session end event in global.asax and the retain the main page
2.comes to session start event in global.asax after the user tries to do some action.
3.check the condition and redirects to login page
2.If the session ends at the time of some action is going in the main page(eg executing a stored procedure for a long time ) then the session has to continue upto the action gets finished.Once it is completed session timeout value has to reset as original value (5 mins)
bebuggiung steps
1. Comes to session end event and assigns the session timeout value to retain the running process in the main page.
I have used the following code to do the above requirements.It is working fine in IIS V5.1 and not working in IIs 6.0 in win 2003 server
Web.config
sessionState timeout="5" mode ="InProc" cookieless ="false"
Global.asax
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["Button"] = "Started";
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
HttpContext context = HttpContext.Current;
HttpCookieCollection cookies = context.Request.Cookies;
if (cookies["starttime"] == null)
{
HttpCookie cookie = new HttpCookie("starttime", DateTime.Now.ToString());
cookie.Path = "/";
context.Response.Cookies.Add(cookie);
cookie.HttpOnly = true;
Application["Button"] = "Started";
}
else
{
if (Application["Button"] == "NotClicked" || Application["Button"] == "Error")
{
context.Response.Redirect("~/Logon.aspx");
}
}
}
void Session_End(object sender, EventArgs e)
{
if (Application["Button"] == "Clicked")
{
Session.Timeout = 60;
}
else
{
Application["Button"] = "NotClicked";
}
}
}
Main Page Load
Application["Button"] = "NotClicked";
Main Page Button Click (calling sp in this button)
Application["Button"] = "Clicked";
Please any one help me out to do the same in IIS 6.0. I have tried with worker process idle time also in application pool.
What is the difference in IIS 6.0 with IIS 5.1 using the above code with cookies? Please any one reply me as soon as possible. its very urgent....
Prasanna
|
|
|
|
|
I need to know the user IP to give the right limit to access my website,
how to detect the user IP?
and moreover, how to know which country is the user from?
thanks!
|
|
|
|
|
|
This is a good article.
|
|
|
|
|
I tried this code on my own PC, it shows the IP: 127.0.0.1
this is obviouly not right. This is not the right IP of my computer.
I saw from internet, there are also others have the same problem. then some people suggest using the following code:
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
but it shows the result as follows:
fe70::8c3:258f:3f47:fd6b%12
this is IP??
do you have more comments on this?
thank you again!!
|
|
|
|
|
I tried this code on my own PC, it shows the IP: 127.0.0.1
this is obviouly not right. This is not the right IP of my computer.
Hi you are in right direction and it is correct. It alwasy gives IP: 127.0.0.1 because you are requesting from your local machine.
When you will acces you web application via different machine then it will give the correct IP.
Anyway your code is correct.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
thanks, I see,
but do you know
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
gives also IP? or sth else?
thank you again!!
your article is great!!
|
|
|
|
|
This will give Host IP where your application is deployed. But you are looking for visitor/Client IP.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
really? if so, I am confused by this code.
thanks again!
|
|
|
|
|
Yes
Now your next job is to find the country name.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
Seraph_summer wrote: your article is great!!
At least the Database provided in the article is the most important part of it. Its a great one indeed.
|
|
|
|
|
Client IP could be found from
ip=Request.ServerVariables("HTTP_X_FORWARDED_FOR");
if(ip==string.Empty)
{
ip=Request.ServerVariables("REMOTE_ADDR");
}
|
|
|
|
|
Hi, thanks!
I tried this code on my own PC, it shows the IP: 127.0.0.1
this is obviouly not right. This is not the right IP of my computer.
I saw from internet, there are also others have the same problem. then some people suggest using the following code:
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
but it shows the result as follows:
fe70::8c3:258f:3f47:fd6b%12
this is IP??
do you have more comments on this?
thank you again!!
|
|
|
|
|
|
|
If the user is behind a proxy then REMOTE_ADDR will be the proxy IP address and HTTP_X_FORWARDED_FOR will be the client IP address. HTTP_X_FORWARDED_FOR can consist of multiple comma separated IP addresses for each proxy the request passes through. Generally, client IP is the first of them.
Finally, you can rely on the above methods only for Transparent proxies. There is no way to trace the actual IP in case of Anonymous or Distorting proxies.
One more good tool for finding country from an IP is this one[^] on codeplex.
|
|
|
|
|
Please Help ,I have 3 day for my presentation in university just
I put a Login Name control into My pages but it show my page name.I am sure User Log in because Login Status Control show LoggedIN template but LoginName Can't show how user login.
I use VS2008(C#) without service pack.PLZ Hlp
|
|
|
|
|
morteza451 wrote: I put a Login Name control into My pages but it show my page name.I am sure User Log in because Login Status Control show LoggedIN template but LoginName Can't show how user login.
Can you please give us the code block ?
If you want to know more about these controls, please read this
ASP.NET Login Controls Overview[^]
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hello everyone,
I am using Windows Server 2003 + VSTS 2008 + .Net 3.5 + C# + ASP.Net + IIS 6.0. I host some files (wmv video file and html file) on the web server, I want to know whether there are any easy to use authentication approach to let user input username and password before they can access (I want to prevent anonymous access)? Since the web site has also aspx ASP.Net page, and I want to use an unified authentication solution for wmv, html and aspx page. If prefer any solution which utilizes username and password stored in SQL Server database which my application already has/use.
Any ideas?
thanks in advance,
George
|
|
|
|
|
Hey George,
I am seeing ur question after a long time. How are u doing ?
George_George wrote: If prefer any solution which utilizes username and password stored in SQL Server database which my application already has/use.
So what is the problem with that ? why you are not authenticate the user from SQL Server itself . maintin session for giving the proper access of the page. or you can implement Roles for that !
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
I am fine, thank! Any ideas to my question?
|
|
|
|
|
in my asp page i have a text box and i want add a text and newline and text again repeatedly.
i uase txt1.text +="hello"+Environment.NewLine ;
but the newline is not working. any idea why ?
|
|
|
|
|
Because you've not set the control to be multiline. It's a property on the control.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
thanx . it's the textmode = multiline ;
|
|
|
|
|
Anyone got a link to a good tutorial which shows how to create a read-only text-box in a Web Application which automatically collects a visitor's IP Address?
Thanks
|
|
|
|