login control can i used to controll what data can user see it

i have a project with mulit company can i used login control to control what company user can see it and what user cant see it

the company comes from database


thanks alot for any help
http://www.feckra.com/blog/
0
wael_e
4/12/2008 9:40:10 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

2 Replies
1032 Views

Similar Articles

[PageSpeed] 30

first of all you should have a table in database database that contains (user_id, company_id,  password, auth_level). the auth_level can be used to grant specific content/page access to each user of each company. but, you need to override the authentication process as bellow.

  

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
Login login = (Login)sender;
if (AuthenticateLogin(login.UserName, login.Password, Session, Request))
{
e.Authenticated = true;
}
else
{
e.Authenticated = false;
}
}



private bool AuthenticateLogin(string userName, string password, HttpSessionState session, HttpRequest request)
{
//DBConnection is my own implementation of DataBase connection.
//That simply connects and executes queries.

DBConnection dbc = new DBConnection();
string qry = "SELECT * " +
"FROM Users, SecurityLevels " +
"WHERE (UserName = '" + userName + "') AND (Password = '" + password + "')";

SqlDataReader reader = dbc.GetDataReader(qry);

bool retVal = reader.Read();

if (retVal)
{
UserData user = new UserData();
user.UserID = (int)reader["userid"];
user.SecLevel = (int)reader["SecLevelID"];
session["user"] = user;
}

reader.Close();
reader = null;
dbc.Close();

return retVal;
}
 

The UserData class contains simple getter/setter for the attributes i listed above for the table (except the password ofcourse). you can also add anything more in this class if you want.
Then whenever you need to check access permission for a user, try this:

  

//assume SecLevel is maximum when it is 0.
//the higher SecLevel of user, the lower privilege he has.

int desiredSecLevelForPage = 2;

if(Session["user"]==null){
//not logged in. redirect to login page.
Response.Redirect("Login.aspx",true);
}

UserData user = (UserData)Session["user"];

//check if current user has proper access
if(user.SecLevel > desiredSecLevelForPage){
Response.Redirect("UnAuthorized.aspx",true);
}

//.... rest of the code for the page...
 

hope this makes sense.

zp bappi.

 

0
zpbappi
4/12/2008 3:30:19 PM

Would it not be simpler to use the built-in login control, and web.config user allow/diallow rules to achieve this?

I know that this would mean you would have to add your users into the "standard" user database, but I'm sure it's not complete rocket science to point the login control to your own database (although I haven't looked at this!).


Kelsey Thornton
(In the Netherlands)

Don't forget - Mark the post which answered your question with "Answer", then that user will get some kudos, and your post will be marked as "Answered" for future readers!

(VB code examples preferred)
0
KelseyThornton
4/12/2008 3:42:55 PM
Reply:

Similar Artilces:

(How) Can i use the form elements of a user control from another user control???
Hi, i have a user control with 4 other user controls. Actually i have 4 panels and each user control is inside a panel. Its like a 4 page form which are all connected to each other. Is it possible to have access to web controls that i have in my user controls from the main user control. In my main user control i have a submit button and a tab list. User can browse through the tabs and each tab is bound to a panel. so clicking on tab1 makes panel1 visible which holds the first user control, second tab makes second panel visible and the rest invisible and the second panel holds the ...

How can a user-control know the name of the web form that uses it?
How can a user-control know the name of the web form that uses it? How can I code in the user-control access to controls of one of the web form that may use it? You reference the Parent property of the web user control in the user control code. For example, if you want to get a Button found on the web form that contains the current user control, you would put the following code in the code-behind of the user control (in C#): Button myButton = (Button)this.Parent.FindControl("myOtherControlButton"); The FindControl() method accepts the ID of the control you're ...

I can create new user (auto-logged-in) but I can't log in using login-control???
Hi there,  I am a little at loss here. I can create new user and I can set in code that I should be logged in after creation - but if I logout, I can never log in again. I've tried creating new users to be sure I didn't make a mistake with the password, but I simply can't log in! The user is created in database and the page visit is logged in my log table (so I can update the database) I've tried Dim r As Boolean = FormsAuthentication.Authenticate("ajuaju", "xxxxxxx.") which returns false even for the correct password. Is the authentication p...

Creating a user to login with using the Login Control and the Ad provider... can't log user in after creation
  Hi I'm trying to create a user in AD from a web form, and then have the user be able to login to a web form with the login control and the Ad provider.   I have a user created by someone else in AD that can log in, but when I create the user using the code below they can't login.   Does anyone have any idea what I'm not doing to enable this user correctly, hes in the same ou and the same groups as the user that can login. the only difference i can see is the display name is not set and the AdminCount has not been set yet...&n...

How can reference user controls (.ascx controls) using "Reference" directive in a multiple web project scanario?
Trying to reference .ascx controls from one web project into another web project.  I read the following tutorial from http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx Tutorial 6: Creating and Using User Control Libraries  In this sample it details how to reference .ascx control from another web project using "Register" directive. I wanted to reference using "Reference" directive which is currently throwing a exception. Here is the sample code that I have.  <%@ Reference Control="/ctl/MessageBox.ascx" %> &nbs...

How can find a control in the Web User Control
<uc1:Ctrl_Makes ID="Ctrl_Makes1" runat="server" /> The Web User Control has the TextBox which is following:<tr><td class="formtxt"> <asp:Label ID="lblAvailabilityOpt" runat="server">Asking Price</asp:Label></td> <td align="left" height="28" width="74%"> <asp:TextBox ID="txtPrice" runat="server" CssClass="field1"></asp:TextBox> </td></tr>   For example an Default.aspx page contain the following Web Us...

Problem in accessing web form data in user controls when create user control dynamically
HI. I have a problem using web user control. I designed a user control named NewsForm. This user control contains some web form elements like <asp:textbox>. When I add it in an .ASPX page, all things may be true. I can know which user filles in textbox (for example and other controls) <%@ Register TagPrefix="uc1" TagName="NewsForm" Src="NewsForm.ascx" %> and <UC1:NewsForm id="newsForm" runat="server"></UC1:NewsForm> But when i create it in code behined dynamically, however user control has web form controls but their value are blank for example //aspx co...

user control data entry form, use same codebehind as web form?
Hi All, I have a quesiton about the approach I'm taking. I have a series of report forms which I have been in the process of consolidating to a single, generic page and subs/functions in a single code-behind. All the reports can use the same set of data entry elements (a dropdown, a radio list, and a textbox). I'm trying to convert these elements to a user control. However, this user control seems to need to inherit differently than the rest of the code-behind. I've been using a single class in the code behind. Is it feasible to separate out the data entry? the code behind im...

I have a web user control being used by another web user control, but the one being used will not display the labels in the resx file.
I am using DotNetNuke version 3.13 (might be 3.013) on a Window's XP machine, SP2. I have what I find to be an extremely odd situation. I have a project called TDS.Controls. This project is a web control library. Each control has its own resx file, which is located in the App_LocalResources directory. Each control inherits from Framework.UserControlBase, just like DotNetNuke's User control in DNN\Controls\User.ascx.vb. As a matter of fact, this control is doing the exact same thing I am trying to do. It is a web user control with its own resx file being used by another web user control (See ...

Can I use user control within Tabstrip control
Can I use user control within Tabstrip control?...

Can we use Telerik RadWindow control in user control?
Dear All,        I am using a user control in an aspx page. Now in user control i am useing a link and when i click on this link i want a modal rad window to be poped out. But it gives me some Message as "UcControl1_RadWindowManager_RadWindow1(OpenerElementId)-Could not find element on page with id LinkButton1".        Please help me out with this problem. Thanks  Hi,According to your error message, it's very likely that a wrong id of an element is passed, though I'm not familiar with this the control yo...

Can we use a User Control in Staticitemtemplate of the menu control?
I am trying to use a user control in staticitemtemplate but it gives me an error "menu control tag not formed properly" message. The control works fine otehrwise. So I was wondering if i cannot use it in menu control. Can anyone pelase tell me if it so? Thanks... I think it's not using the control but using <%# Eval("NavigateUrl")%> in the control properties that is giving an error. What am I doing wrong? I used this control so I could change the image on mouse over in the static menu items. Please help...... <StaticItemTemplate>      ...

UpdatePanel within a web user control resets data of controls outside the user control
Hello, I have a usercontrol on my page which displays a running marquee text. It makes use of an UpdatePanel (within the user control) to refresh the marquee text (within the updatepanel) at periodic intervals. For this I added a timer control and its tick event as an async postback trigger for the UpdatePanel. I have a lot of textboxes and dropdown list boxes (all with runat=server) on the page outside the above user control. These are also contained in different UpdatePanels. Problem is, when the user control does a postback to refresh the marquee text, it causes some of...

Adding User Controls from Sting can the User Control contain a CompileWith Control directive?
I want to store my User Controls in a DB. So I working with ParseControl and passing it a string. However when I pass as string of a control with codebehind I get this error. My Code: Dim strControl1 As String = "<%@ Control Language=""VB"" AutoEventWireup=""false"" CompileWith=""Control1.ascx.vb"" ClassName=""Control1_ascx"" %>" & vbCrLf & "<div>Control 1<br /><asp:PlaceHolder ID=""Control1PlaceHolder"" Runat=""server""...

Web resources about - login control can i used to controll what data can user see it - asp.net.web-forms

Nintendo NES Controll - Flickr - Photo Sharing!
Nintendo NES Controll at the National Museum of Computing in Bletchley Park PERMISSION TO USE: you are welcome to use this photo free of charge ...

PlayStation Nowthe streaming game servicewill, weirdly, require a proprietary DualShock controll
PlayStation Now—the streaming game service—will, weirdly, require a proprietary DualShock controller to play PS3 games on TVs, phones and tablets. ...

Puzzle Mage - 108km Games - Robot Bros - new 3D Action+Puzzle Game!
This is an original puzzle game, you will take control of the cute little mage to start a new adventure on the magic float islands. By using ...

Pre-Columbian Americas - All Empires
Introduction Although most of Per-Columbian North America north of modern Mexico did not see the formation of large states, Latin America was ...

Price Drop: Star Warfare:Alien Invasion
... our top scientists.And now, as always, our last hope...Is YOU!Solid single player model Various enemies with rich AIl Console-like smooth controll ...

Apple's iPhone 2.0: $199, 3G, On Sale July 11 (AAPL)
Was it worth the wait? You'll have to hang on another month to find out. In other WWDC news: A new version of Mac OS X, code-named Snow Leopard, ...

Cypress Semiconductor
... Sales (MyCypress) Products Automotive Async SRAMs CapSense Clock Distribution PSoC® 1 PSoC® 3 PSoC® 5 Sync SRAMs TrueTouch® Touch Screen Controllers ...

Opinions Run Rampant Over Supreme Court’s Decision to Uphold Obamacare
If you follow the logic of the supreme court. It would be possible for congress to force the individual citizen to do whatever they want. If ...

Product Videos, Ukraine - DinoDirect.com
By these short Product Videos, you can have a brief review about the merchandise on DinoDirect.com. You could pay your orders in UAH.

Album App - Your photo album on the iPad
The App Store is full of apps to edit your pictures, but what if you want these pictures in a digital album on your iPad to show your friends ...

Resources last updated: 1/1/2016 3:43:55 PM