Private Shared Vs Public Shared Vs Protected Shared
Jan 5, 2010let me know what does these access modifiers means.private shared vs public shared vs protected shared
View 5 Replieslet me know what does these access modifiers means.private shared vs public shared vs protected shared
View 5 RepliesI can access a module from code behind but not from the aspx page in inline VB code <% ... %>.
I know its got to be something simple but I can't seem to find the answer anywhere.
I would like to connect to a password protected shared location that has an access database using an ASP page. I have the user name and password needed to connect to the shared location but I am not sure how to set up the connection string in order to get this done. The access database I would like to connect to does not need a username or password, only the shared location does.
View 1 RepliesIn page behind classes I am using a private and shared object (list<client> or just client) to temporary hold data coming from database or class library. This object is used temporarily to catch data and than to return, pass to some function or binding acontrol. 1st: Can this approach harm any way ? I couldnt analyse it but a thought was using such shared variables may replace data in it ?2nd: Please comment also on using such variables in BLL (to hold data coming from database) where new object of BLL class will be made everytime.
[Code]....
In page behind classes I am using a private and shared object and variables (list or just client or simplay int id) to temporary hold data coming from database or class library. This object is used temporarily to catch data and than to return, pass to some function or binding a control.1st: Can this approach harm any way ? I couldn't analyze it but a thought was using such shared variables may replace data in it when multiple users may be sending request at a time?
[code]...
I have the following code in a class in which I call from different pages, I wanted to know where this info is being stored at as I can see it from different pages.
[Code]....
Also, is this saved on the browser session? IIS? will whatever being set from 1 user be affected by every other user on the site?
We have an application that has quite an extensive APP_Code directory (about 150 functions). The functions are split across multiple files and then classes and namespaces.
On numerous pages we have to create numerous instances of the classes to be able to access the functionality, which can get very repetitive and means we're repeating code on every page declaring the instance etc.
As far as I can tell, a way to navigate this issue, is to make the functions Public Shared (as opposed to just Public functions).
For reasons I would rather not discuss, I need to create a custom authentication system for my app. I was just reviewing the system and am having some doubts if my solution is thread safe. My goal was to create a solution that would allow my app to authenticate a user one time and that users authentication info would be shared by all master pages, pages, classes, user controls, etc that are used. (But not share the same info between users) Here is my setup: PageHttpModule.cs - this is added to the web.config as a httpModule.
public class PageHttpModule : IHttpModule
{
public void Init(HttpApplication app)
{
app.AuthenticateRequest += new EventHandler(OnAuthenticateRequest);
}
public void OnAuthenticateRequest(Object s, EventArgs e)
{
CurrentUser.Initialize();
}
public void Dispose() { }
}
CurrentUser.cs
public static class CurrentUser
{
public static bool IsAuthenticated { get; private set; }
public static string Email {get; set;}
public static string RealName {get; set;
public static string UserId {get; set;}
public static void Initialize()
{
CurrentUser.AuthenticateUser();
}
Note: this is a scaled down version of my authentication code.
public static void AuthenticateUser()
{
UserAuthentication user = new UserAuthentication();
user.AuthenticateUser();
if (user.IsAuthenticated)
{
CurrentUser.IsAuthenticated = true;
CurrentUser.UserId = user.UserId;
CurrentUser.Email = user.Email;
CurrentUser.RealName = user.RealName;
}
}
}
UserAuthentication.cs
public class UserAuthentication
{
public string Email { get; set; }
public string RealName { get; set; }
public string UserId { get; set; }
public bool IsAuthenticated { get; private set; }
public UserAuthentication()
{
IsAuthenticated = false;
Email = String.Empty;
RealName = String.Empty;
UserId = String.Empty;
}
public void AuthenticateUser()
{
//do some logic here.. if the user is ok then
IsAuthenticated = true
Email = address from db
UserId = userid from db;
Realname = name from db;
}
}
I have tested between 3 different browsers and it seems to work fine, but I am still learning and don't want to make a huge mistake. If my logic is totally wrong, then how should I do it so I dont have to put user lookups on every page directly?
I am using the following code for slide show of AjaxToolkit. It works. But I wanna get the label1.text as picture name But I cannot do it in public shared function ! How can I do that !
[Code]....
I have made public readonly shared properties in my class.
I want to acces a property's value in .aspx page. As i think that is possible through scriptlet like this
<%= ClassName.Propertyname %>
But its not working .Where i am wrong ?
I have a gridview that is dynamically created and have finished all but one problem - I need for my code that is within a Public Shared Function to access a textbox string - In the below I need myinput to return the string so that my query's can use the variable - the below shows: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
If I remove the "Shared" the error goes away however it crashes other parts. (if I hard code the text then all works as expected)
[Code]....
I want to call a non shared function in a shared function in which i am having a textbox control instance. Its giving no error but when i call this shared function from client callback it gives me no response
Any Idea except removing shared from the function.
Here is my code :
<WebMethod()> _
Public Shared Function myF() As String
Dim pg As New _Default
Return "{'Hello':'" & pg.setText & "'}"
End Function
Public Function setText() As String
Dim pg As New _Default
pg.TextBox1.Text = "This is a test"
Return pg.TextBox1.Text
End Function
I have the following variable which creates problem when i use multiples instance of the same web form. how i could what variables other than shared i can use to achieve this purpose?
Public strRoleType As String = String.Empty
Protected Shared isAreaSelected As Integer = 0
Protected Shared isStoreSelected As Integer = 0
Protected Shared isHeadOfficeSelected As Integer = 0
Protected Shared isRegionSelected As Integer = 0
am using SSRS with MS SQL Server 2008 R2, which has the new feature of supporting shared datasets.First, I created my shared dataset, and made sure that it worked correctly and had a good connection. That worked great.Second, I created a new report (Let's call it "ReportSub"), and I had it use my shared dataset. The report works great.Third, I created another report (Let's call is "ReportMain"), and I put a subreport object into the report and associated it with "ReportSub". Doesn't work. Instead, I get this error:
Data retrieval failed for the subreport, 'ReportSub', located at: /ReportSub. Please check the log files for more information.Any ideas of what the problem may be? It will work if I use an embedded dataset, but I really need to use a shared dataset.
How To Get The Unc Share Name Of A Given Folder (If Shared)?
View 2 RepliesIn my Views folder I have a several folders such as Category, Origin, Price. They all have a Browse.aspx file and the code in this file displays a table of products. All controllers associated with these folders use the same ViewModel, but in each view I have a repetitive code. The code is:
Folder Category, file browse.aspx
Folder Origin, file browse.aspx
.....
<% foreach ( var p in Model.Products) { %>
<li> <%: p.productname + " " + p.price + " " + p.origin.originname + " " + p.category.categoryname %> </li>
<% } %>
How can I create a shared view and use the shared view in all these views?
I have a basic ASP.NET application which is used to request data which is stored on disk. This is loaded from files and sent as the response. I want to be able to store the data loaded from these files in memory to reduce the number of reads from disk.
All of the requests will be asking for the same data, so it makes sense to have a single cache of in-memory data which is accessible to all requests. What is the best way to create a single accessible object instance which I can use to store and access this cached data? I've looked into HttpApplication, but apparently a new instance of this is created for parallel requests and so it doesn't fit my needs.
I have View which loads more than one partials.
[Code]....
It's convinient to me to divide menus for pieces. But number of partials keep growing and it is getting harder to find concrete partial in Shared folder. Can I store partials in view folder which uses this partial? Html.RenderPartial() doesn't have such parameter as Controller Name so I think that it's impossible. But if there are any solutions to solve this inconvinience?
I have CMS and FAQ as 2 different modules/projects each uses a different DLL file. When those two modules was structured as the same application. I was using the following piece to get the FAQs categories as part of my menu
[Code]....
Now those two modules are separated. .. Can I use the following shared function which is already exist in the FAQ separate DLL to loop the categories? and how can I do it?
[Code]....
I was curious if there is a shared hosting platform for asp.net web sites that would allow me to setup a service that would do something at predetermined intervals. Dedicated hosting is not an option due to budget constraints.
So far, it looks like my solution will have to be to set an object in the cache and use the expired callback.
Has any one used the above method? and how successful was it?
Is there a better option or method than this?
I have few websites based on the WebForms and one based on MVC. All websites have the same settings for forms authentication in web config.
The problem is that once logged in to WebForms website, I have to re-login for MVC websites, but when I log out from MVC website, I am automatically logged out from WebForms websites.How can I pass information to the MVC website that user was successfully logged in when using WebForms.
So I have an ASP DOT NET web service which needs to impersonate Windows Authenticated users. This web service calls into a Com Api to perform database operations.
It seems like the Impersonation does not persist into the Com Api. Is this because the Com DLL is loaded into its own memory space and treated as a separate process? Also what would be some ways to deal with this issue and persist the Impersonation into the Com Api Dll?
Moving the functionality of the Com Api into the dot net code is not an option at this point. Also the Com Api was written in C++.
i ve deployed many applications with file uploading feature on dedicated server and never got any issue. but it is not working on shared sever :( .. i think Server.MapPath("~") is not working on shared server. as in shared sever i am unable to find those directories which must for uploading.
m using following code for creating directories
string RootLocation = Server.MapPath("~") + "\";
string siteUploads = RootLocation + "uploads" + "\";
Directory.CreateDirectory(siteUploads );
how to refer shared function in a class , this function itself inside same class
public class cls1
Public Shared Function getDBDate(ByVal pDate As Date) As String
Return Format(pDate, "yyyy-MM-dd")
End Function
Private Function GetDb_Format(ByVal pDateString) As String
Dim d As Date = Me.ParseDate(pDateString)
Return clsDate.getDBDate(d)
End Function
End Class
can i have any other way to use getDbDate function
Do I have to lock access to instance members?
public class HttpModule : IHttpModule
{
//...
Dictionary<int, int> foo;
void UseFoo(int a, int b)
{
foo[a] = b;
}
}