|
As I'm sure you are well aware, static properties values are shared (hence I believe the VB keyword for it) among all the application's instances. Which means your application is seriously flawed if you expose user data to other users.
The answer: don't use static properties the way you do.
Use normal properties.
And don't mean to be rude, but it seems your project is far away from completion, if you want it to work correctly.
var question = (_2b || !(_2b));
|
|
|
|
|
I agree with Greg. You are using static keyword without knowing how it works. Static variables will stay in memory until the application domain unloads and it is shared between all threads under that application domain. To solve this, Use session variables. These are unique for each visitor.
|
|
|
|
|
But how can I used session variable in class file, its through "Objects reference not set to be instant of an objects". Please check my class file.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.SessionState;
namespace MyStore
{
public class GetConnection
{
static string _conString = null;
public GetConnection()
{
//
// TODO: Add constructor logic here
//
}
public static String DBConnectionString
{
get
{
if (HttpContext.Current.Session["ConnStr"] != null)
{
return HttpContext.Current.Session["ConnStr"].ToString();
}
else
{
return "";
}
}
set
{
HttpContext.Current.Session["ConnStr"] = value;
}
}
}
}
|
|
|
|
|
The way you do it is overkill, and it's flawed.
You should pass the connection string to the constructor, get rid of the static keyword for the DBConnectionString property, add a private field _dbConnection and assign the value of it to the parameter you get in the constructor.
public class GetConnection
{
public GetConnection(string connectionStr)
{
_dbConnection = connectionStr;
}
private string _dbConnection;
public string DBConnectionString
{
get{return _dbConnection;}
}
}
}
It's still overkill.
Having a class with one string property that you set to something you already know.
As you have the connection string (hopefully stored in web.config), just fetch it from web.config everytime you want to connect into the database. In other words, don't keep the whole connection string in a session variable, but rather a key to fetch it by.
var question = (_2b || !(_2b));
|
|
|
|
|
The following are the test urls, i need to remove the "Admin" from the URL. So I want the regular expression to solve this issue
http://www.Admin.testsite.com/Administrator/Login.aspx
http://Admin.www.testsite.com/Administrator/Login.aspx
http://Admin.testsite.com/Administrator/Login.aspx
http://quality.Admin.testsite.com/Administrator/Login.aspx
Once we remove the "Admin" word or text from the above URL , output would be
http://www.testsite.com/Administrator/Login.aspx
http://www.testsite.com/Administrator/Login.aspx
http://testsite.com/Administrator/Login.aspx
http://quality.testsite.com/Administrator/Login.aspx
|
|
|
|
|
jayarajRaman wrote: So I want the regular expression to solve this issue
Try google, there are thousands of regex sites where you can try and test to your hearts content.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
i have implemented this code on the logout button
FormsAuthentication.SignOut();
Session.Abandon();
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
Response.Expires = -1500;
Response.CacheControl = "no-cache";
Response.Redirect("~/frm_default.aspx");
but when i click on back button i am able to go the previous page.
|
|
|
|
|
i think u have to add Headers to restrict Back view
Try this
Response.CacheControl = "no-store";
Response.AddHeader("Pragma", "no-cache");
Response.AppendHeader("Cache-Control", "no-store");
|
|
|
|
|
if u r using master pages, code this in page load of master page or in page load of everypage
Response.Expires = 60;
DateTime now = DateTime.Now.AddMilliseconds(-1);
Response.ExpiresAbsolute = now;
Response.AddHeader("pragma", "no-cache");
int timeout = (Session.Timeout + 1) * 60;
Response.AddHeader("Refresh", timeout.ToString());
Response.AddHeader("cache-control", "private");
Response.CacheControl = "no-cache";
if (Session.IsNewSession)
{
Response.Redirect("~/Default.aspx");
}
and in logout
Session.Abandon();
|
|
|
|
|
This is fine but then when i am on a page (not logged out) and then i click back button it does not take me to the previuos page. ihave to click refresh to get the page.
|
|
|
|
|
browser cache always remains open..
you cant erase bowser cache programmatically.
Only you can do, is when user clicks anything on a page after logoff, throw some error messages.
|
|
|
|
|
Hi,
On the Page Load write
if Session("UserId")="" then
Response.Redirect("Login.aspx")
end if
if you click back now, the page will execute the page load na...it will go to login page.
Ramesh Sambari
|
|
|
|
|
Hello friends
i am having a little issue hope anyone can help me out.
i have a situation my masterpage location changes due to some security requirements, so i am storing Foldername in Web.Config in AppSetting
like this --> add key="adminFolder" value="~/Temp/"
e.g
so i dont need to change everywhere when i have to update the foldername and getting back in Page Load event.
String adminFolder = System.Configuration.ConfigurationManager.AppSettings["adminFolder"];
protected void Page_PreInit(Object sender, EventArgs e)
{
this.MasterPageFile = adminFolder + "MasterPage.master";
}
this approach help me out to solve dynamically assign the foldername of master page
but i cant see Design View of my Code because i dont know how cant i link "adminFolder" Key in the Top of aspx file
|
|
|
|
|
hiii,
I am having a small doubt regarding the querystring ....
In my application there is a form with two pages..
I like to edit the details within the form for this i used a gridview
and querystring....taking the id value in the querystring i got the
details for the first page....
i kept edit&continue button at last which will redirect the page to
second page....
how to get the details in the second page basing on the id value
which we took in the first page....
how to write the querystring plz help me....
|
|
|
|
|
hi
You get query string value like this
String str=REquest.querystring("id")
Known Is Drop.Unknown Is Ocean
|
|
|
|
|
hi
Code behind:
Dim dgitem As DataGridItem
For Each dgitem In Dgdisplay.Items
If cacheRankingName = "cumulativeranking" Then
'If dgitem.ItemType.Item = ListItemType.Header Or dgitem.ItemType.Item = ListItemType.AlternatingItem Or dgitem.ItemType.Item = ListItemType.Item Then
Dim dt As New DataTable
qrytoExecute = "select playerid, firstname , lastname, scores.points as leaderboarddisplay from scores " & qrytoAdd
qrytoExecute &= "group by scores.playerid order by leaderboarddisplay desc, playerid limit 30 "
dt = DBManager.GetDataTable(qrytoExecute)
For i = 0 To dt.Rows.Count - 1
Dim id As String = dt.Rows(i)("playerid").ToString()
Dim Query As String = "select concat(p.firstname,p.lastname) as Name from player p join scores s on s.playerid=p.userid where s.playerid=" & id
Dim retVal = DBManager.GetScalar1(Query)
Dim lbl As Label
Dim intCounter As New Integer
Dim str As String = DirectCast(dgitem.Cells(0).Controls(0), Label).Text
'If txtHNGet.Text = retVal Then
' 'flag = True
' dgitem.Cells(1).BackColor = System.Drawing.Color.DarkRed
'End If
Next
End If
'End If
Exit For
Next
End If
Html:
<asp:datagrid id="Dgdisplay" EnableViewState="False" Runat="server" PageSize="50" GridLines="None"
AutoGenerateColumns="False" Width="65%" AllowPaging="True">
<Columns>
<asp:TemplateColumn HeaderStyle-Font-Bold="True" HeaderText="Rank">
<ItemTemplate>
<asp:Label ID="lblrank" Runat="server">
<%#getRank%>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderStyle-Font-Bold="True" HeaderText="Playername">
<ItemTemplate>
<a href='DisplayPlayerBioData.aspx?ids=<%#Container.DataItem("playerid")%>'>
<%#getPlayerName(Container.DataItem("firstname"),Container.DataItem("lastname"))%>
</a>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderStyle-Font-Bold="True" HeaderText="Count#">
<ItemTemplate>
<asp:Label ID="lblcount" Runat="server">
<%#DataBinder.Eval(Container.DataItem,"leaderboarddisplay")%>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False">
<ItemTemplate>
<asp:Label ID="lbl1" Runat="server">
<%#getPlayerName(Container.DataItem("firstname"),Container.DataItem("lastname"))%>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Mode="NumericPages" ForeColor="#003300" PageButtonCount="2" HorizontalAlign="Right"
VerticalAlign="Top" Font-Bold="True"></PagerStyle>
</asp:datagrid>
i need to get datagrid cell value in codebehind..
here
Dim str As String = DirectCast(dgitem.Cells(0).Controls(0), Label).Text
//error displayed Specified cast is not valid.
Datagrid contain in webusercontrol
how can i get cell value...
Known Is Drop.Unknown Is Ocean
|
|
|
|
|
hi try this,
Dim str As String= CType(dgi.Cells(0).Controls(0), Label).Text
and be sure that control(0) of cell(0) is text field
|
|
|
|
|
I am trying to start/stop a windows service in the code from a web application.The web application runs as IUSR_ComputerName, but this account does not have enough access rights to star/stop the service.
How do I impersonate the local system account, so that I can stop/start the service?
|
|
|
|
|
|
Hi...
I am trying have a dropdownlist which displays a calendar when the drop down arrow is clicked. I am having hard time in figuring it out. Plz tell me hw to achieve it.
Thanks in advance...
|
|
|
|
|
|
You can use the AjaxControlToolkit
With it you can assign a calendar to a textbox with almost no code at all
Alexei Rodriguez
|
|
|
|
|
Please Help Me Out :
I Want to Control The Client Browser i.e When ever a Specific URL Appears in the Client Browser Then The User Must be Redirected To Specified URL.
|
|
|
|
|
what is the problem with this.
If you programmatically want to do, just in your handler, try to transfer your response to the page if certain request occurs.
To get IP use
Request.Servervariables("REMOTE_ADDR")
You can get the absolute URI from this
Request.Url.AbsoluteUri
Now use Server.Transfer to the page.
Otherwise you can also use
<urlMappings enabled="true">
<add url="~/Info/Copyright.aspx" mappedUrl="~/Help/Copyright.aspx" />
<add url="~/Support/Contacts.aspx" mappedUrl="~/Help/Contacts.aspx" />
</urlMappings>
in Web.Config if you want this automatically.
|
|
|
|
|
My Websites are hosted, some times i got error as
Compiler Error Message: CS1056: Unexpected character ''
Error Reported is as
Source Error:
Line 1:
Line 2: áO浦浙á°潥
Line 3: 卤
Line 4: áO浦浙á°†捡ュュ潥
Show Detailed Compiler Output:
c:\windows\system32\inetsrv> "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /utf8output /R:
"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:
"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:
"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:
"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:
"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll"
/R:
"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:
"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:
"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:
"C:\WINDOWS\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll"
/R:
"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll"
/R:"
C:\WINDOWS\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll"
/R:
"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:
"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:
"C:\WINDOWS\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\a7fd3a8e\282a6669\
assembly\dl3\a75afeae\db46742f_f447c901\SMSDLL.DLL" /R:
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll"
/out:
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\a7fd3a8e\282a6669\App_Code.ckhtcfi8.dll"
/debug- /optimize+ /w:4 /nowarn:1659;1699;1701
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\a7fd3a8e\282a6669\App_Code.ckhtcfi8.0.cs"
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\a7fd3a8e\282a6669\App_Code.ckhtcfi8.1.cs"
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.3053
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
This is frequent Issue with webserver, the same code works fine with local testing servers.
When the error is reported, it is fixed in few mintues by host.
Can anybody tell me, what is the exact issue behing this
|
|
|
|