Login Code (c#) Is Not Working

Apr 26, 2010

I've made a login page but I seem to have missed something and I guess I've become blind to the code because I can't find what's wrong with it. I'm sorry some of it's in swedish. There's no error message when I test the login, the program just stays on the login page.

Login page (aspx.cs):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.IO;
public partial class Start : System.Web.UI.Page
{
string config = System.Configuration.ConfigurationManager.ConnectionStrings["InteraktivaFĂreningenConnectionString1"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
this.TextBoxAnvändarnamn.Focus();
}
protected void ButtonLoggaIn_Click(object sender, EventArgs e) //login-button
{
//kontroll av användarnamn och lĂsenord - controls username and password
try
{
SqlConnection conn = new SqlConnection(config);
{
conn.Open();
string Användarnamn = this.TextBoxAnvändarnamn.Text; //username
string LĂsenord = this.TextBoxLĂsenord.Text; //password
string sql = "SELECT Login.anvandarnamn, Login.losenord, Medlem.ID FROM Login, Medlem WHERE anvandarnamn = '" + Användarnamn + "' AND '" + Session["användarnamn"] + "'";
SqlCommand comm = new SqlCommand(sql, conn);
SqlDataReader dr = comm.ExecuteReader();
{
try
{
dr.Read();
if (Convert.ToString(dr["anvandarnamn"]) == Användarnamn) //username
{
Session["användarnamn"] = TextBoxAnvändarnamn.Text; //username
Session["medlemID"] = dr["medlemID"].ToString(); //memberID
if (Convert.ToString(dr["losenord"]) == LĂsenord)
{
HämtaID(); //getID
Response.Redirect("MĂten.aspx");
}
else
{
string scriptet = "<script>alert('LĂsenordet är felaktigt. Prova igen');</script>"; //wrong password
ClientScript.RegisterStartupScript(scriptet.GetType(), "FelLĂsen", scriptet);
TextBoxLĂsenord.Focus();
}
}
}
catch (Exception)
{
string scriptet = "<script>alert('Användarnamnet är felaktigt. Prova igen.');</script>"; //wrong username
ClientScript.RegisterStartupScript(scriptet.GetType(), "FelAnvändarnamn", scriptet);
TextBoxAnvändarnamn.Focus();
}
dr.Close();
conn.Close();
}
}
}
catch (Exception)
{
}
}
//gets and creates session variables of username and memberID
public void HämtaID() //getID
{
try
{
SqlConnection conn = new SqlConnection(config);
{
conn.Open();
string Användarnamn = this.TextBoxAnvändarnamn.Text; //username
string sql = "SELECT fornamn, efternamn, ID FROM Medlem WHERE ID = '" + Session["medlemID"] + "'";
SqlCommand comm = new SqlCommand(sql, conn);
SqlDataReader dr = comm.ExecuteReader();
{
while (dr.Read())
{
Session["medlemID"] = dr["medlemID"].ToString(); //memberID
Session["användarnamn"] = dr["fornamn"].ToString() + " " + dr["efternamn"].ToString(); //username
}
}
dr.Close();
conn.Close();
}
}
catch (Exception)
{
}
}
}

View 16 Replies


Similar Messages:

Security :: Login Control - Redirect Not Working On Server - Working On Localhost

Feb 21, 2011

I have a login control that is working beautifully on my localhost, but not working on the server. It validates my username & password - and gives me an error if I enter an invalid username/password. However, if I enter the correct username/password, the page refreshes, but does not redirect me to the "ReturnUrl" that I see in the URL. I've seen posts on this, but nothing that I tried worked. I've tried setting the 'MembershipProvider'attribute of the login control. I don't want to set the DestinationUrl...I want it to take what is in the ReturnUrl in the querystring. I don't think it's a web.config issue cuz it works on localhost??

View 3 Replies

Security :: Working With Login Page,but Is Not Working?

Feb 8, 2011

am working with Login page,but is not working.so what can i do. This is my code.

string connect = ConfigurationManager.ConnectionStrings["CarsalesConnectionString"].ToString(); protected void btnLogin_Click(object sender, EventArgs e) { Session["Username"] = txtUsername.Text; Session["Password"] = txtPassword.Text; string status = "Active";
string Query = "Select * from tbl_User where Username = '" + txtUsername.Text + "' and Password = '" + txtPassword.Text + "' and Active = 1 and Status ='" + status + "' "; SqlDataAdapter cnAccess = new SqlDataAdapter(Query, connect); DataSet myAccessDataSet
= new DataSet(); cnAccess.Fill(myAccessDataSet, "tbl_User"); if (myAccessDataSet.Tables["tbl_User"].Rows.Count != 0) { //condition A lblErr.Text = "Invalid Username and Password!"; //Response.Redirect("~/Customer/CustomerForm.aspx"); //Response.Redirect("~/Mainpage.aspx");
} else { //condition B Response.Redirect("~/Mainpage.aspx"); //lblErr.Text = "Invalid Username and Password!"; }

View 2 Replies

Configuration :: Application Is Working Fine In Local Environment But Not Working After Push Code In Live

Aug 19, 2010

My application is working fine in local environment but not working after push code in live. My locale environment and hosting environment both are having same configuration. Same app working fine 2 month before but in different domain but same hosting server.

how to check the both config / any possible to run debug mode in hosting server please let me know. below code used in all page for checking user session status but when I click on any link page redirect to login.aspx I think session got timeout. I don't know why session got time frequently, but this issue not happening in local environment (desktop).

[Code]....
[Code]....

View 6 Replies

Web Forms :: Code Write File 2.0 Is Working In Firefox But IE Not Working

Aug 28, 2010

If Not IsDBNull(ext) Then
ext = LCase(ext)
End If
Select Case ext
'Case ".htm", ".html"
' type = "text/HTML"
'Case ".txt"
' type = "text/plain"
'Case ".doc", ".rtf"
' type = "Application/msword"
'Case ".csv", ".xls"
' type = "Application/x-msexcel"........................

View 5 Replies

Security :: IIS Login Form Not Working

Jul 8, 2010

I am working on an e-commerce project using ASP.Net and C#.Net (Visual Studio 2005-Windows XP).

I am facing problems in the login module. I created the login accounts using the roles and users in the ASP.Net Website Administration Tool. The login module is working fine when I test the website within the Visual Studio. I mean the login form is working properly under the Development Server integrated in the Visual Studio. What I want is to make this work properly under IIS (i.e. the Production Server). When I deployed the project to the IIS, the login form with the login control is displayed, but cannot login and gives a login failed message. . I have searched about this issue in Google and they are providing good tutorial links to solve this issue. Even after reading those I couldn't solve this as I am new to Web Development. Can you provide me a sample source code with the web.config and also a description of the major steps in configuring IIS to support the role based login?

I had gone through the following titles under google

"Always set the "applicationName" property when configuring ASP.NET 2.0 Membership and other Providers".

View 35 Replies

HTML- Login Form Not Working

Mar 16, 2010

I have a child page LoginContent.aspx which contains a login form. If the user logs in he should be redirected to my Welcome.aspx page. But if I press the login button the page just reloads itself, nothing happens.

The codebehind on this page is empty. Both LoginContent.aspx and Welcome.aspx are child forms of the same master page.

[code]....

View 2 Replies

Security :: Login Controls Is Not Working?

Jun 18, 2010

I know that the login controls provide some powerful "straight out of the box" functionality for creating functionality for storing and logging in users. However, all of this fucntionality seems to be based upon having a unique username, and the users email address is stored separately. The login control, http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.aspx, automatically creates a database http://msdn.microsoft.com/en-us/library/ms178329.aspx#the_login_control to store the user information, and looking at the table definitions, there are separate entries for the username and password in different tables.

View 5 Replies

Security :: Login Control Not Working With IIS 5.1?

Dec 28, 2010

I was hoping someone could run me through how to get the login control working properly on my website. I have seen many people's posts on a similar issue, but nothing seems to have worked, and I think I may have been doing something wrong.

Here's what I've done:-

MY SETUP

I am using my laptop with Windows XP Professional Edition, which is running IIS 5.1. I have setup my system with the Web Platform Installer, which uses Visual Web Developer and SQL Server Express 2008.

I added a database in SQL Management Studio, and created an ASP.NET Membership Schema to it using the aspnet_regsql.exe tool. In my web.config file, I created a connection string to this database used both in the code, and with the asp membership.

<add name="ManagementCentral" connectionString="Data Source=localhostSQLEXPRESS;Initial Catalog=ManagementCentral;Integrated Security=TRUE;" providerName="System.Data.SqlClient" />

According to all tutorials I have seen on the ASP.NET login control, I am using <authentication mode="Forms"> in my web.config.

TESTING:

When I run my website via debugging in Visual Web Developer, everything works fine. I can view my site, log in, and it all works as expected.

MOVING TO IIS:

I have set up my site in IIS 5.1, and can access my site through a browser by going to ttp://website.local, as set up in IIS and my hosts file. The site comes up fine, but when I try to login through the login control, I now get the error:-

Cannot open database "ManagementCentral" requested by the login. The login failed.
Login failed for user 'LAPTOPASPNET'.

FIXING ATTEMPTS:-

I have looked through numerous posts and blogs saying that to fix this, I need to grant database access to my ASPNET user, or set up 'impersonation'. The problem is, as you can tell by my connection string, I don't actually have a user called 'ASPNET'. I have checked this in my database.

I tried adding a new user, which has a SQL Server Authentication and password, and db_owner access to my 'Management Central' database. I then added this information into my web.config connection string, which now looks like this:-

<add name="ManagementCentral" connectionString="Data Source=localhostSQLEXPRESS;Initial Catalog=ManagementCentral;Integrated Security=TRUE;Uid=ASPNET;Pwd=p@ssword" providerName="System.Data.SqlClient" />

I also added a line for 'impersonation':-

<identity impersonate="false" userName="localhostASPNET" password="p@ssword" />

View 1 Replies

Moving The Javascript Code To Design View Is Not Working. Only Code-behind Attributes.Add ("onclick" Works. Puzzled

Jul 15, 2010

I wanted to disable a button after it is clicked and at the same time fire the post back event to generate a report. My first set of code did not work because soon after the button is disabled the page won't submit/post back. here's the first set of code which was not implemented. the onclientclick calls a javascript function which has these lines

document.getElementById('btnGenerateReport').disabled=true;
GetPostBackEventReference(btnGenerateReport,'');

since it was not posting back,i tried the following on page_load code behind

btnGenerateReport.Attributes.Add("onclick", "this.disabled=true;" + ClientScript.GetPostBackEventReference(btnGenerateReport, ""))

that worked well. but I tried to copy the javascript that got generated and pasted directly on design view

onclick="this.disabled=true;__doPostBack('btnDownloadClientsWithConviction','');"

its not working from client side alone after I disable the code behind attributes.add
but when I check the view source the 2 pages are the samewhy am I not able to move the code from code-behind to design view?

View 1 Replies

Configuration :: Login Not Working After Publishing Website?

Aug 16, 2010

Login not working after publishing asp.net website

I am used default login control, form based authentication and default sqlmembership provider.but in local my site working fine,when i publish it locally in iis means,the login is not working , i don't know what is the reason?

View 3 Replies

Security :: Membership Login Stoped Working?

Sep 30, 2010

I have a web app that uses the Membership Provider to authenticate users.Everything worked fine until today... when I tryed to log in it failed. I looked in the database if something went wrong there and the user is deleted but everything looks fine there.I tryed to recover the password using the user name and i got an error that the user is not recognized.I tyed to recover the password (even though I am sure what the password is) but still no luck... (I get an error that hased passwords can not be decrypted)I triyed it in local host and guess what ... still the same... this is the provider section in my web config

[Code]....

View 6 Replies

Configuration :: Debug Not Working In Login Form?

Jul 22, 2010

I'm starting a new web site which involves a Novell/LDAP login to enter. Just installed VS2008, using framework 2.0, configured web.config to use authentication using form login.aspx which is the LDAP form we reuse from app to app. Debug is enabled, in form and in VS options. I'm running with localhost web server. Problem is debug doesn't work in the login form, does not stop at breakpoints I put in page_load event. Tried to bypass the login form to make sure, turns out debug will work on some startup form I made but does not when I redirect to login form. It seems VS2008 does not like something in my login form.

View 3 Replies

Security :: Login Control Not Working After Deployment

Dec 11, 2010

just basically as it says in the subject. After I deploy my asp.net 4.0 website, the login control just refreshes itself after a valid username and password have been filled in instead of doing a redirect. The connection to the database works, because I can register and stuff from the database shows up in my website.

View 4 Replies

Web Forms :: Login And Logout Operations Is Not Working

Mar 12, 2010

when i log out, i have this problemwhen i enter the authorized section, its still keep showing me the page, only when i refresh it,it brings me back to login page.for example,i logged in as manager,and then i logged out.when i enter the same authorized managment page it keeps showing me content, but when i refresh it brings me back to the default login page.

View 8 Replies

Security :: 'Remeber Me ' Is Not Working In Login Control?

Mar 15, 2010

In my login control the 'Remember Me' is not working . Can anyone say what is the problem?

i have coded as below:

[Code]....

View 7 Replies

Security :: Login Control Not Working On The Server?

Feb 9, 2010

I made a login control in a webapplication with a membership provider and a role provider. The problem is when I enter the username and the password in the login control (on my system i.e localhost) the user authenticated and redirected without any problem, but when I deploy my webapplication with my database on a host server the login control cant authenticate the same user and tells me "Login attempt was not successful".

View 8 Replies

Security :: Redirect To Login Page Not Working?

Jun 7, 2010

I have a web application where all the pages inherit from a base class, where i have written some methods common to all pagesHere is the code i have written for logout event.

this.Session.Abandon();
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();

My expectation is once the user logs out and if he tries to access any url directly by typing in the browser he should be redirect to login page.But this is not happening now. I have checked the session. it is getting cleared properly while logout. But the user is take in to the screen. How can i fix this? I am looking for something which i can write in the base class so thati need to have to write the same in all the pages. Also this should work in the case of login page(it should not redirect to login page again if try to access login page once user logs out. please not login page also inherits base class).

View 4 Replies

Security :: Login Control DestinationPageUrl Override Not Working?

Feb 5, 2011

When a user logs in I check whether they have the minimum profile info entered. If they do not then I want to redirect them to the account maintenance page, otherwise I want to redirect them to the page where the login link was clicked. To accomplish this. I am trying to override DestinationPageUrl at the LoggedIn event. Isn't working ... the redirect is always to the page where the login link was clicked. Here's my (relevant) code:

[Code]....

View 2 Replies

Security :: Login Control Page Remember Me Not Working?

Aug 12, 2010

why the remember me option of the login control would not be working? Are there some special settings we need to set?

View 13 Replies

Security :: Login Control Not Working When Website Published Onto Server?

Apr 13, 2010

I am a newbie to asp.net and have recently been building a web... I have a login control on the main page which when logged in verifys the user and redirects them to the home page... I published this to the server previously and it worked. Today when I tried logging into my system however I got the following error message:-

"Your login attempt was not successful. Please try again."

The accounts did work before but since I have uploaded a newer version of my program onto the server the above message is displayed. I have been on many websites and read previous forums with suggesstions to add <roles> in the web.config file however the login control worked before and I have not changed anything on the site apart from a different page that doesnt affect the login.

Few points to make... the login control is using the asp.net configuration pre built tables it generates for you, I have created the users and roles inside of asp.net configuration so it is not a custom membership... I am at a complete loss as how to get my login control to work having tried to insert roles into the webconfig file.

View 3 Replies

Security :: Get Roles Working - User To Be Able To Login And The System Recognize?

Apr 22, 2010

I have a sitemap of 5 items. 2 items i only want the admin to see. I want the user to be able to login and the system recognise who it is and if an admin, bring up the 2 items in the sitemap. If not an admin, hide the items.

View 3 Replies

Security :: Login Control Stops Working Requiring It Be Deleted And Replaced

Mar 3, 2011

I have found that eventually the login control I place on my page will not authenticate. The solution appears to be to delete it and replace it with a new instance. Obviously this is not tenable. Can someone enlighten me as to why it might stop working for no apparent reason such that simply deleting it and putting a new instance in place will restore functionality? Update: I find it very sensitive. I just did the above described action, got it working again, found that the Authenticate event was no longer properly wired and tried to fix it by removing the '1' from the Authenticate1 in this line. That was sufficient to kill the control which required me to once again delete it and replace. I cannot believe the login control is that sensitive or no one would touch it. What gives?

onauthenticate="Login1_Authenticate1"

View 2 Replies

Security :: Login Controls Not Working Properly On Textbox Modification In Javascript?

Jun 23, 2010

I am using membership management and role management. As login controls transfer data in plain text, I am encrypting userid/password in javascript and decrypting in serverside code.

Client side javascript:

[Code]....

If i am commenting these last two lines in javascript code.

[Code]....

View 2 Replies

User Controls :: Login Button Not Working In Content Page With URL Rewrites

Apr 27, 2016

I am sucess implemnt url rewite in my site all working fine.

but when i use previous url then login button and signup not working 

#stq&stp=1 come in end of url ..

Working [URL] ....

Non-working [URL] ....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved