Last post Apr 25, 2011 09:27 AM by richt
Apr 04, 2011 06:51 PM|richt|LINK
I'm creating a web site which will have usernames and passwords. When someone inputs the correct id and password, I need it to bring up a web page with there name on it and the page which belongs to them only? I have created the database but I now need the
sql code? Can anyone help.
Apr 04, 2011 07:17 PM|bbcompent1|LINK
Best thign to do is post the relevant code and how the database is laid out and we should be able to help.
Apr 04, 2011 08:43 PM|richt|LINK
I have a log in page, so when you input your id i want it to go to a specific page related to that one id. Then if someone else logs in they will get the web page related to them. As for code, well thats the problem?? In the long run those pages will pick
up information from a database (hopefully). Hope this makes sense. Thanks.
Apr 04, 2011 09:11 PM|mikesdotnetting|LINK
Apr 05, 2011 12:21 AM|bbcompent1|LINK
Apr 05, 2011 01:06 PM|dLcreations|LINK
Is the Your Code in .aspx page
<asp:Login ID="Login1" runat="server" onauthenticate="Login1_Authenticate">
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
if (ValidateFunction(Login1.UserName, Login1.Password))
Login1.Visible = false;
e.Authenticated = false;
private bool ValidateFunction(string UserName, string Password)
bool BoolReturnValue = false;
cn = new SqlConnection(@"Data Source=Dhruval;Initial Catalog=HRMS;Uid=sa;Password=virsap;Connection TimeOut=0");
cmd = new SqlCommand("select * from Login", cn);
SqlDataReader rdr = cmd.ExecuteReader();
if ((UserName == rdr["UserName"].ToString()) & (Password == rdr["Password"].ToString()))
BoolReturnValue = true;
Apr 05, 2011 08:39 PM|richt|LINK
Thanks for this.
I'm using .cshtml pages. I'm then trying to run SQL within that page. This then looks up the database to make sure the correct user is logged in. Hope this makes sense. Thanks.
Apr 05, 2011 08:46 PM|richt|LINK
I have used this upto a point. What I need to do now isn't in there which is a shame. Thanks for the help.
Apr 05, 2011 09:14 PM|mikesdotnetting|LINK
Have you looked at any of the template sites, such as the Starter Site? It has example code for the WebSecurity helpers.
Apr 05, 2011 09:30 PM|richt|LINK
I have, but I'm unable to find anything to make it work.
I'll explain what i'm trying to do. You open your web page and your asked for your username and password this will take you to a generic page. this page will then show information eg; your name, plus total amount of holiday you have. This information is
on a database. So... what Im trying to do is only show the information to the correct username. Hope this makes sense.
Apr 06, 2011 06:42 AM|mikesdotnetting|LINK
You need a SQL Select statement. How that should be constructed depends on your database tables. In your select statement you use WHERE to filter the results to just the current user.
Apr 06, 2011 09:33 PM|rrrsr7205|LINK
It sounds like the poster is trying to relate the login user table (in one db) to some other table (in another db) containing data and/or relationships pertinent to that user. He sounds frustrated because the StarterSite security tables contain very little
info on the user other than the email (which suffices as the userid/username). He is looking to either:
(1) Extend the User Profile table to include additional (and possibly redundant) attributes of the user or
(2) Find some way to implement the Security functionality in his own tables/database or
(3) Find some way to establish a relationship (across two databases) between the user's row in the UserProfile table in the security db and the user's row in his yet-unspecified application database.
None of these seems to be the best way to do this. The target audience of WebMatix is very likely to not have the knowldge and'or fortitude to diddle with the security database.
Is it possible to implement the StarterSite database's security tables in the site's application database and then create an enforceable/maintainable relationship between the two tables that would now be in the same database?
If some similar solution to this exists, the guru who can write a comprehensible tutorial to illustrate the solution would be doing a great service to the WebMatrix user community!
Apr 07, 2011 06:00 PM|bbcompent1|LINK
Only thing I have really been asking him to show me is a visual rep of his database. If he can do that, we can probably code some good examples for him. Since he hasn't really shown us much, we can't do much other than guide. I would say add one column to
the table that holds the content to display and in that table, reference the ID number of the user in the aspnet_user table. He could easily build a gridview that would allow him to set page x to user y. Then when the user logs in, simply reference that ID
Number from the content table and display their "page" as a response write.
Apr 07, 2011 06:41 PM|richt|LINK
I'm using the starter site on webmatrix. I have changed some of the design eg added more tabs and removed things which i don't need. So I've got the log in form and database from the starter site, this works all fine. So, what I want is a dedicated page
for when a person logs in. This page will include information on how much holiday they have etc. For this i built (tried) another database with the following fields: name, department, manager, email, start date and amount of holiday. So a person logs in, this
will then bring up a web page dedicated to them only. Any help would be grateful. Thanks in advance.
Apr 07, 2011 07:37 PM|mikesdotnetting|LINK
Just add suitable tables or fields to the existing membership database. There is no need to create a separate database. The WebPages_membership table includes an ID for each user. If I were you, I'd look to add extra fields to the UserProfile table. You
can store the departement etc in that for each user, and you already have their email address. When a user logs in, redirect them to a page which obtains the holiday etc info that relates to the current user's ID.
Apr 10, 2011 10:23 AM|richt|LINK
Thanks for this, I'm going to give it a go and see what happens.
Apr 12, 2011 09:33 PM|richt|LINK
I've tried all sorts but nothing seems to be working. How do i redirect them. Thanks.
Apr 15, 2011 02:02 PM|a-rad|LINK
Here is an example that I have put together on the fly (untested) - I have based this off of the
Starter Kit (as it already has all the working components). I will stage out the steps to help clarify what my code is doing. We are going to pull data from a table that relates back to the username - so its along the same lines as to what
you want to achieve... You can model my example around it :)
Lets get the database sorted out before I go through it. Open the Starter Site or Create a site from the Starter Kit template. Create a new table called
UserData for this example. Add a column.. First one to be called
id make sure its the primary key and the identity as well as set its type to
int. Now create a column called userid and also make this
int but dont worry about the other settings. Continue to create another column called
flavour and set the type to ntext and one more column called
colour and also set the type to ntext.
You should have a table called UserData with 4 columns (id, userid, flavour, colour) - Let's create an account and populate this database!
Step 1: Register a username (http://localhost:xxxx/Account/Register) or click the link in the top right.
You can also add the account as an admin if you need to but no nessasary for this. To learn more about that go to: http://www.asp.net/webmatrix/tutorials/16-adding-security-and-membership
Step 2: Log into my website using the credentials I just registered (http://localhost:xxxx/Account/Login) or click the link on the top right - You will be re-directed back to the home page, but the top right hand corner will display your
email/username to show you are logged in. We are going to edit this page in a minute to pull some data out that relates to your username!
Step 3: Go to the Databases. First of all open up the
UserProfile table and look at the data. You will see your email address in one column and in the other a number.. Most likey the number
Step 4: Go to the table we created earlier UserData and we are going to add some data in there. Ignore the first column (id), in the
userid column put in the number from the above step (1), in the
flavour column put in chocolate and in the colour
column put in blue.
Now that you have some details that can be linked back via your UserId - lets get the page to pull the data out!
Step 5: We want to create a copy (Right Click > Copy, then Paste) of default.cshtml
and rename the copy to default2.cshtml. Open it up
default2.cshtml and the current code should look like this:
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Welcome to my Web Site!";
ASP.NET Web Pages make it easy to build powerful .NET based applications for the web.</p>
We want to REMOVE all of this and replace it with this:
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Welcome to my Web Site!";
@* Open or select the database we want *@
var db = Database.Open("StarterSite");
@* Set the ID variable as the UserId from the UserProfile table *@
@* Run a query to grab the data and create some variables! *@
var SQLSELECT = "SELECT * FROM UserData where userid=@0";
var Details = db.QuerySingle(SQLSELECT,id);
ASP.NET Web Pages make it easy to build powerful .NET based applications for the web.<br/><br/>
My favourite flavour of ice cream is @Details.flavour.<br/>
The color I like the most is @Details.color.
Step 6: Save the page. Now run the website, make sure you are logged in and go to
http://localhost:xxxx/default2 - you should see the two things we put in the database!
Please let me know how you go - this is a bit rough and I am still new to Razor as well.. Hopefully this helps you understand how you can pull data from seperate tables and how it goes about doing it.
Apr 19, 2011 07:49 PM|richt|LINK
Brilliant, works like a dream. I just need to work it into my college work (lol). Thanks for the input.
Apr 19, 2011 10:42 PM|a-rad|LINK
Be sure to give it a go first - should you get stuck, I will try and assist where I can :)
Apr 25, 2011 09:27 AM|richt|LINK
So far, so good. I have now put it into the web page and all seems ok. Thanks for all your help.