After a User Logs-out the page is redirected to Login.aspx page but after pressing the Back Button he is able to see the previous pages.
I have already used JavaScript to disable the Back Button
My Logout.aspx is as Follows:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Logout.aspx.vb" Inherits="Logout" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
<title>Untitled Page</title>
<script type="text/javascript" language="Javascript">
history.go(1);
</script>
</head>
<body onload="changeHashOnLoad(); ">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
<script type = "text/javascript">
function disableBackButton() {
window.history.forward();
}
setTimeout("disableBackButton()", 0);
</script>
<script type="text/javascript">
function noBack() { window.history.forward() }
noBack();
window.onload = noBack;
window.onpageshow = function(evt) { if (evt.persisted) noBack() }
window.onunload = function() { void (0) }
</script>
</html>
And Logout.aspx.vb as Follows:
Imports System.Data.SqlClient
Imports System.Data
Partial Class Logout
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strHostName As String = System.Net.Dns.GetHostName()
Dim clientip As String = GetIpAddress()
Dim params() As SqlParameter = New SqlParameter(6) {}
params(0) = New SqlParameter("#compname", strHostName)
params(1) = New SqlParameter("#ip_add", clientip)
params(2) = New SqlParameter("#mac_add", "")
params(3) = New SqlParameter("#login_id", Session("login").ToString())
params(4) = New SqlParameter("#user_name", Session("topusr").ToString())
params(5) = New SqlParameter("#login_status", "Logout Success")
params(6) = New SqlParameter("#counted", "Y")
Dim cnString As String = ConfigurationManager.ConnectionStrings("patravaliConnectionString").ToString
Dal.ExecuteNonQuery(cnString, CommandType.StoredProcedure, "sp_audit1", params)
Response.Cookies.Add(New HttpCookie("Asp.Net_SessionId", ""))
Response.Cookies.Add(New HttpCookie("ASMSAUTH", ""))
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetExpires(Now.AddSeconds(-1))
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
System.Web.Security.FormsAuthentication.SignOut()
Response.Redirect("login.aspx")
'FormAuthentication.Signout()
Response.Buffer = True
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1D)
Response.Expires = -1500
Response.CacheControl = "no-cache"
'Response.Buffer=<SPAN style="COLOR: blue">true;<o:p></o:p>
'Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
'Response.Expires =-1500;
'Response.CacheControl = "no-cache";
'if(Session["SessionId"] == null)
'{
' Response.Redirect ("WdetLogin.aspx");
'}
'}
'
Session("topusr") = ""
Session("topdept") = ""
Session("usercd") = ""
Session("branch") = ""
Session("prt") = ""
Session("deptcd") = ""
Session.Abandon()
Session.Abandon()
Session.Clear()
Session.RemoveAll()
Application("genericstr") = "uu"
Response.Redirect("~/Login.aspx")
End Sub
Public Function GetIpAddress() As String
Dim stringIpAddress As String
stringIpAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If stringIpAddress Is Nothing Then
'may be the HTTP_X_FORWARDED_FOR is null
stringIpAddress = Request.ServerVariables("REMOTE_ADDR")
'we can use REMOTE_ADDR
Dim add As String = HttpContext.Current.Request.UserHostAddress
End If
Return stringIpAddress
End Function
End Class
The previous page which is viewed is just a Cache because any changes made on that page redirects it to home page.
But all previous pages contain information which should only be visible to the Logged-In person.
Related
I have got an old ASP.NET web page. When I press F5, Visual Studio is giving me error:
0x800a138f - JavaScript runtime error: Unable to get property 'txtAppl' of undefined or null reference.
HTML page,
<%# Page Language="C#" Debug="true" %>
<script runat="server" src="uzpo2003_tbbuild.cs"></script>
<html>
<head>
<title></title>
<script type="text/javascript" src="uzpo2003_client.js"></script>
</head>
<body onload="form_load();">
</body>
</html>
uzpo2003_client.js,
function form_load() {
if (document.formSelect.txtAppl.value == -99999999)
return null;
}
uzpo2003_tbbuild.cs,
public class TableBuild
{
StringBuilder output = new StringBuilder();
public string tblBuilder(string department, string un)
{
int dept = int.Parse(department);
string dom;
dom = "<center><table border='0' style='font:14pt;' bgcolor='#A7C7B7'>";
dom += "<input type = 'text' name = 'txtAppl' value = '' size=16 id = 'Text1'></P>";
return output.ToString();
}
}
How can I solve this problem?
I want to show data stored in Array-list in body of Mailbox. User can then add mail ids in To: according to his/her convenience and send the mail.
But its throwing JavaScript error when large amount of data is sent to body.
Here is the test code of .aspx page:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function mail()
{
var array_store;
array_store = document.getElementById("array_store");
var vs = array_store.value;
window.location.href = "mailto: &body=" + encodeURIComponent(decodeURIComponent(vs));
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button_mail" runat="server" Text="OpenInMailBox" OnClientClick="mail()" />
<input type="hidden" id="array_store" name = "ArrayStore" value = '<%=this.ArrayStore %>' />
</form>
</body>
</html>
Code of .CS page :
public partial class mailto_check : System.Web.UI.Page
{
protected System.Text.StringBuilder ArrayStore = new System.Text.StringBuilder();
string str = "";
protected void Page_Load(object sender, EventArgs e)
{
ArrayList al = new ArrayList();
al.Add("Test1");
al.Add("hello ");
al.Add("Testing");
try
{
for (int y = 0; y < al.Count; y++)
{
str = al[y].ToString();
this.ArrayStore.Append(str+",%0D");
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
for large data I tested it by adding values to array-list.
Please help me with this.
Thanks in advance for positive answers.
I want to read the Page(.aspx) Hiddenfield Value in the User Control that is placed on that Page and process some logic.
FOr eg: I have a hidden field x on a Page. The Page has many user controls and I want to access this hidden field (x) in those User Controls where value of x will be set by a Javascript in the Page.
I am trying to find the HiddenControl and read its value from codebehind of usercontrol(.ascx.cs) but always get null.
HiddenField colname = UIUtils.FindControlRecursive(this.Parent.Page, "MainContent_AssignedTo_ColName") as HiddenField;
The ID is same as the hiddenfield on client Side. I tried this.Parent and this.Parent.Parent for the first argument too but no luck.
what am I missing here.
Here is my aspx page:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestFindControl._Default" %>
<%# Register Src="ReadHiddenField.ascx" TagName="Assign" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HiddenField ID="HiddenField1" runat="server" Value="10">
</asp:HiddenField>
<asp:placeholder ID="Placeholder1" runat="server"><uc1:Assign id="test" runat="server"></uc1:Assign> </asp:placeholder>
</div>
</form>
</body>
</html>
and here is my code behind on control:
protected void Page_Load(object sender, EventArgs e)
{
HiddenField test = (HiddenField)Page.FindControl("HiddenField1");
var j = test.Value;
}
Try:
HiddenField colname = (HiddenField)Page.FindControl("The id of control");
private void GetParentPageHiddenField()
{
System.Web.UI.WebControls.HiddenField ParenthiddenField = null;
Control ctl = this.Parent;
while (true)
{
ParenthiddenField = (System.Web.UI.WebControls.HiddenField)ctl.FindControl("ParentPageHiddenFieldID");
if (ParenthiddenField == null)
{
if (ctl.Parent == null)
{
return;
}
ctl = ctl.Parent;
continue;
}
break;
}
var parentHiddenFieldValue=ParenthiddenField.Value;
}
Please help me to refresh periodically an image in a web form (asp.net).
Here is my code. The image is not refreshing. Thank you in advance.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.11.0.min.js">
$(document).ready(function () {
var refreshId = setInterval(function () {
var obj = document.getElementById("<%=Image1.ClientID%>");
var src = obj.src;
var pos = src.indexOf("?");
if (pos >= 0) {
scr = src.substr(0, pos);
}
var date = new Date();
obj.src = src + '?v=' + date.getTime();
return true;
}, 10000);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/sOverview.png" />
</div>
</form>
</body>
</html>
and the code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Image1.ImageUrl = Image1.ImageUrl + "?" + DateTime.Now.ToLongTimeString()
End Sub
A script element gets its script from either the text node inside it, or the URL of the src attribute. Not both.
If you want to load two scripts (one from a URL and on in the text node) then you need two script elements.
How can I register AND execute that JavaScript function in ASP.NET on a Page_Load event so my textbox content gets validated and if nothing is in there I can disable a save button?
function Validate(source, arguments)
{
}
Use ClientScriptManager.RegisterStartupScript
See here for example
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public void Page_Load(Object sender, EventArgs e)
{
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
StringBuilder cstext1 = new StringBuilder();
cstext1.Append("<script type=text/javascript> alert('Hello World!') </");
cstext1.Append("script>");
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>RegisterStartupScript</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Hope this helps