Use A Static DbUtil Class For Web Is It Dangerous?
Oct 4, 2010
is it ok to use something like this in the web:
(my application is on asp.net mvc)
public static class DbUtil
{
public static int Insert(object o, string cs)
{
using (var conn = new SqlConnection(cs))
using (var cmd = conn.CreateCommand())
{
conn.Open();
return Convert.ToInt32(cmd.ExecuteScalar());
[Code]....
View 2 Replies
Similar Messages:
Mar 26, 2011
I have a private static field in my Controller class in an MVC web application.
I have a static method in that controller that assigns some value to that static field, I want to apply lock on that static field until some other instance method in the controller uses the value stored in the static field and then releases it.
DETAILS:
I have a controller named BaseController having a static ClientId field as follows and two methods as follows:-
public static string ClientId = "";
static void OnClientConnected(string clientId, ref Dictionary<string, object> list)
{
list.Add("a", "b");
// I want the ClientId to be locked here, so that it can not be accessed by other requests coming to the server and wait for ClientId to be released:-
BaseController.clientId = clientId;
}
public ActionResult Handler()
{
if (something)
{
// use the static ClientId here
}
// Release the ClientId here, so it can now be used by other web requests coming to the server.
return View();
}
View 1 Replies
Jan 27, 2011
I have a question about C Sharp ASP.NET:Is there a difference (in code speed, resources) between:public static variable declared in public static class MyGlobals in a 'Code File' template;and the variable declared in a normal 'Class File' template;I use this variable in 2 different Class Files and also in _Default Page codebehind cs file.In fact in my case I need about 20 global variables of type List<string>.
View 9 Replies
Jan 8, 2010
If a static class is put in App_Code, does that imply only one instance will be created, shared by different http requests?Or each request still brings one request?
View 3 Replies
Mar 15, 2011
So i have some existing functionality from an older ASP.Net app that is a static class.
Say there's a static method in that class that returns a dataset that I would like to bind to something like a gridview or whatever I can build using MVC3.
View 2 Replies
May 10, 2010
I am using <%# MyFormatClass(Eval("fieldname")) %> to display data in a grid view on my page. MyFormatClass works fine, but now I want to move it to a central location that can be used by many pages. When I try to access the class <%# Utils.MyFormatClass(Eval("fieldname")) %> it no longer works. Is this something we are allowed to do?
View 1 Replies
Mar 4, 2010
Since I'm using Postgresql and can't use LINQ to SQL, I wrote my own wrapper classes.
This is a part of the Student class:
[code]....
It works now! I replaces all Run methods in the Student class with DB.Run
But I want to know if it will work fine with a lot of people online, not me only. I'm not sure how static things work with ASP.NET, maybe it'll eat a lot of memory?..
View 3 Replies
Jun 10, 2010
I would like to generate my links automatically via a static class in each of my aspx pages (or in a common BasePage).Currently I use this:
private const string TEMPLATE =
"~/One.aspx";
public static string Link ()
(
string link = String.Format(TEMPLATE);
return link;
)
But the name of my page, One.aspx is hardcoded. Is it possible to generate the path instead of this hardcoded constant TEMPLATE. You should know that I do not instantiate the class before creating the link.
View 1 Replies
Jan 6, 2010
I have a method that returns an array of custom class objects that are created by parsing a text file. At the moment every time I use it I am rereading the file which isn't very efficient.
What I wat to do is create an array containing the objects when the page loads and store them in an array which can then be used later.
[Code]....
I thought I could create the static object using something like:
static Album myAlbums[] = readArray("Albums.txt");
but I am getting the following error:
A field initializer cannot reference the nonstatic field, method, or property 'B2M._Default.readArray(string)'
I am new to C# so this is probably something dumb. (Feel free to poke fun in my general direction if this is the case!)
View 2 Replies
Nov 17, 2010
I have some confusion with singleton class, below are my some points:
1.Can singleton class have static method?,if yes then how we call that methods?
2.what is main difference between Static class and Singleton Class?
I have created my singleton class as follows:
[Code]....
In Above class structure I have created two method one is Static and second is non static, When I am trying to access Static Method it gives me compile time error.
How can I use static method of singleton class?
View 7 Replies
Mar 30, 2010
See in below I have writtine a
1. Singleton class Emp1 with Display Method and
2. Static Class with Static Method Display.
What is the advantage of singleton class over Static Class with Static members?
[Code]....
View 9 Replies
Jan 13, 2011
I have a static class I'm using as my data layer in my website. In this class, I have string arrays that store queried information that I can access later. Here's the part of my class and the method in question:
public static class data_layer
{
ivate static string[] items;
private static string[] description;
//will return description for an item id. if no item id is found, null is returned
public static string getDesc(string key)
[code]....
View 2 Replies
Jan 21, 2011
I have a member function that does not depend on any member variables of the class. (in my case the class is an ASP.Net Page)
The function is protected, I dont need it outside of this class. Its only purpose is to build an URL from an given object.
Should I make all my functions static if they dont depend on the class, even if they are not used outside of this class?
View 6 Replies
Feb 22, 2011
I hate to see the name of the class used as a string parameter like "FileDownloader" in the code, and I would like to use something like this FileDownloader.Name(), where FileDownloader is name of the class.
Only problem is that I can't find out how to do that without instantiating object or creating a static method...
Is there a way to get a class name in .net without having the object instance and without creating a static method that returns the name of the class?
View 3 Replies
Nov 12, 2010
Currently, I am accessing the property by creating a static method like the one below.
public static class CartCollection : List<Cart>
{
public static void Add(Cart Cart)
[code]...
View 3 Replies
Feb 2, 2011
I have a simple web service, in it i have a static class which has a static collection to remember alive tokens.
I just want to make sure that the token collection lives until the next iisreset or the application pool recycles.
And what is the difference between remembering states in Application bag and static class?
View 1 Replies
May 7, 2015
What is the use of declaring the static class. I know that we cant create the object for the static class but i want to know that is the use of creating the class as static.
View 1 Replies
Jul 28, 2011
I understand the problem of the static variable inside a class in the web application, now I try to create a simple class to deal with SQL Server for example, so I created Static Method inside this class, this static method used in insert, update and delete from database, I wonder if this is safe, and there is no problems will appear ?
View 10 Replies
Jan 28, 2010
I am on .aspx page and i want to take the width and height of a control from a static class
where i have defined them as constans.
Is there any way to access that class directly from the aspx page?
I know that i can make a method like:
width="<%= getWidthSize() %>"
and inside the aspx.cs to define this method to take the size from that static class.
But i am asking if this could be directly managed from the web aspx page...?
View 2 Replies
Jul 21, 2010
We have a Static class that 's called CData in our asp.net c# app.It handles all the data layer CRUD functionality on our pages.
Problem is, were are losing the intellisense reference in our pages to it.For example: we would expect to type CData.(dot) and have a list of methods and properties available to us.
Nope. Not there.
I kind of thought it was because the file was getting too long at 3000 lines of code, since some other static classes were working ok.
So then I thought that I'd try wrapping the CData Class in a namespace. That worked, but of course I had to put an include statement of the top of each page that's using CDATA, also, now some of the other developers are getting errors in there pages complaining about missing methods that are in CDATA, but their pages are not seeing.
View 1 Replies
Mar 22, 2010
Basic question - is it possible to access the current Page from a static class in ASP.NET?
I am thinking no, as google turns up no results.
View 3 Replies
May 17, 2010
is it possible to make an asynchronous call to a static class function?
View 3 Replies
Apr 27, 2016
I have a class and call class A method by creating class A object
unlike this call Class B method by using class B objectÂ
Code is here below
class A {
public void A1() {
Console.WriteLine("I am from Class A");
}
}
class B {
public void B1() {
Console.WriteLine("I am from Class B");
[Code] .....
View 1 Replies
Feb 15, 2011
my MasterPage I have a label that reflects the name of the module that the user is currently in. I change the label text accordingly using the following ..
private void ChangePageTitle(string PageTitle)
{
Label lblPageTitle = (Label)Master.FindControl("lblPageTitle");
lblPageTitle.Text = PageTitle;
}
Instead of placing this method in the code-behind of every page, I want to put it in a single class and call it accordingly. I thought of using a static class but do not know how to reference the MasterPage.Can I use a static class? or do I place the method in the code-behind of one page and call Object.Method from the other pages?
View 2 Replies
Oct 17, 2010
I want to know , how good / bad is it to save configuration values in a static properties?I am creating an application which reads configuration from an XML file and a DataContext file, instead of sending the CustomConfig class into the configuration.xml each time I tought about using an ReadXml() method on application_start at the global.ascx
the ReadXml() method would save the data in static properties of CustomConfig and whereever I would want to read that particler data I would ask CustomConfig.PROERTY_NAME
My question is ? how smart it is ? how long does IIS would save the data in a static member? (if as long as the application exists then I'm ok as long as I add the ReadXml() in the application_start)
View 2 Replies