|
First check that the method "db.Sp_FindbyId(stid)" return any value or not.
this exeception is because in code var stud = db.Sp_FindbyId(stid).ToList();
stud is not having any recored.
In this case better to use
return (stud.FirstOrDefault())
|
|
|
|
|
Thanks ...Richard MacCutchan & Kunwar Bahadur Singh
|
|
|
|
|
You could put a check before accessing the value from the list
var stud = db.Sp_FindbyId(stid).ToList();
if (stud.Count() > 0 ){
return (stud[0]);
}else{
}
|
|
|
|
|
FirstOrDefault will do exactly the same thing, as suggested in the reply above yours.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I agree , that will do as well. Thanks for pointing out to me. I think I overlooked the last line.
|
|
|
|
|
Hello
I have been trying for some time to log-in to a site who register.aspx page works (new user's details are inserted in the database).
However, when I use those same details of a user (email and password) to log-in, I am not able to. I get no debug errors in Visual Studio 2013 for Web or server errors. The form just stands still when I click the logon button.
Are there are glaring errors, please, in my log-on code? In my aspx file, the two form fields are ID = strEmail and ID = password:
Protected Sub LogonBtn_Click(sender As System.Object, e As System.EventArgs) Handles LogonBtn.Click
Try
Using conn As OleDbConnection = New OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings("students").ConnectionString)
conn.Open()
Dim strEmailValue As String = strEmail.Text
Dim passwordValue As String = password.Text
Dim MSAccess As String = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=|DataDirectory|students.mdb;"
Dim ConnectionString As String = "SELECT * FROM university WHERE strEmail = '" & strEmailValue & "' AND [password] = '" & passwordValue & "'"
Dim cmd As New OleDbCommand
Dim reader As OleDbDataReader = cmd.ExecuteReader
Dim strEmailFound As Boolean = False
Dim passwordFound As Boolean = False
'if in database:
While reader.Read
strEmailFound = True
strEmailValue = reader("strEmail")
passwordFound = True
passwordValue = reader("password")
End While
conn.Close()
'check result
If strEmailFound = True And passwordFound = True Then
Dim target = String.Format("~/userpage.aspx?strEmail={0}", strEmailValue)
Response.Redirect(target, True)
End If
End Using
Catch ex As Exception
Console.WriteLine(ex.Message)
Dim MessageBox As String
MessageBox = "Sorry, email or password not found"
End Try
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Dim strEmailValue As String = ""
'Dim strEmailValue As String = strEmail.Text
If Not IsPostBack Then
strEmail.Text = String.Format("{0}", Request.QueryString("strEmail"))
End If
LblDate.Text = ReturnDate()
strEmail.Focus()
End Sub
End Class
Many thanks!
|
|
|
|
|
Apart from the potential for SQL injection problems with your database, do you really want to store passwords in clear text?
[edit]
Also look at the following sequence:
While reader.Read
strEmailFound = True
strEmailValue = reader("strEmail")
passwordFound = True
passwordValue = reader("password")
End While
You are setting both variables to True without actually checking whether you have found the specific entries in the database. You need to read through your code carefully and check your logic.
[/edit]
|
|
|
|
|
Hello Richard
Many thanks for your reply.
Yes, there are a couple of flaws - plain text passwords as opposed to salting/hashing, and empty form fields - but for the moment I just wanted to get the engine started and then, when I can log in, I will explore those other important features of a log-in form.
Thanks for pointing out the While reader.Read/End While
You mean it's not actually doing anything?!
Thanks again for your reply.
|
|
|
|
|
Look again at my previous reply and the (il)logic of that loop. As soon as you come out of the loop you assume that there has been a match with the email and password entered by the user, but the two variables will contain the last found items.
|
|
|
|
|
I am trying to tidy it up a little. I didn't have these namespaces in, for example, beforehand:
Imports System.Data.OleDb.OleDbCommand
Imports System.Data.OleDb.OleDbDataReader
and the 'order' is OleDbConnection, an OleDbCommand, and an OleDbDataReader. The While/End While code should then read through the data, before closing OleDbDataReader, and then OleDbConnection.
That structure is now reflected in my own code.
The examples I have see around look a lot like this:
dr = myCommand.ExecuteReader()
While dr.Read()
'reading from the datareader
MessageBox.Show("colname1" & dr(0).ToString())
'displaying the data from the table
End While
dr.Close()
I probably need to use something like this
("colname1" &
dr(0).ToString()) from the example above, but I don't want the code to display anything - only to log me on.
As I said earlier, the code I initially posted doesn't actually 'read' the rows, does it?
|
|
|
|
|
Member 8761667 wrote: the code I initially posted doesn't actually 'read' the rows, does it? No idea, you need to do some debugging to check it. I have tried to explain where the logic is wrong in your loop, but you seem to be looking elsewhere.
|
|
|
|
|
As I understand it, the logic should be to read the database using While and End While. In the database, where there are two columns called 'password' and 'strEmail' (the exact same IDs as for the two form fields), the code should check that the email variable (strEmailValue) entered in the email form field is the same as the entry in the database column whose name is strEmail.
(strEmail is the name of the database column AND the email text field in the form, whereas strEmailValue is the variable entered by the user in the form text field.)
If the entry in the database column is the same as the variable entered by the user, then it is true that strEmailValue has been found - hence strEmailFound = True.
Likewise, for password. The code should check that the password variable (passwordValue) entered in the password form field is the same as the entry in the database column whose name is password.
(password is the name of the database column AND the password text field in the form, whereas passwordValue is the variable entered by the user in the form text field.)
If the entry in the database column is the same as the variable entered by the user, then it is true that passwordValue has been found - hence passwordFound = True.
So, I now have:
While reader.Read
If strEmailValue = reader("strEmail") Then
strEmailFound = True
End If
If passwordValue = reader("password") Then
passwordFound = True
End While
Does the above make sense?
Thanks again.
|
|
|
|
|
Yes, that makes some sense. However, you only need a single variable to indicate that you have found the correct user record. Also, you should check the password inside the email test, to ensure you capture the two settings for a single user entry, something like:
bool userFound = false
While reader.Read
If strEmailValue = reader("strEmail") Then
If passwordValue = reader("password") Then
userFound = True
Exit While
End If
End If
End While
|
|
|
|
|
Hello Richard
Many thanks.
I will debug all the code again and give it a trial run.
Before my previous While/End While, I had:
Dim strEmailFound As Boolean = False
Dim passwordFound As Boolean = False
but if I use your
Dim userFound As Boolean = False
I can delete my two declarations because, as you say, 'you only need a single variable to indicate that you have found the correct user record'.
Does it matter which variable finds the record?
Thank again for all your help.
|
|
|
|
|
Member 8761667 wrote: Does it matter which variable finds the record? No, but as I said before, you only need one variable, to tell when you have found the record that matches both userid and password.
|
|
|
|
|
|
Thanks for the links, Richard.
I have just taken a look at this page:
Secure Password Authentication Explained Simply[^]
which looks up-to-date (referring to SHA512 and RNGCrypto), and I have put your post into my favourites but, as I say, I will investigate the While/End While first.
|
|
|
|
|
Error:
Missing type map configuration or unsupported mapping.
Mapping types:
sp_selectall_Result -> Student1
MvcCRUD6.Models.sp_selectall_Result -> MvcCRUD6.Models.Student1
Destination path:
List`1[0]
Source value:
MvcCRUD6.Models.sp_selectall_Result
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
Controller Code:
public ActionResult Index()
{
Mapper.CreateMap<Student, Student1>();
var dbContext = new WorkTraningEntities();
StudentCRUD stud = new StudentCRUD();
var students = stud.SelectAll();
List<Student1> stud1 = Mapper.Map<List<Student1>>(students);
return View(stud1);
}
Index View:
@model IEnumerable<mvccrud6.models.student1>
@{
ViewBag.Title = "Index";
}
Index
@Html.ActionLink("Create New", "Create")
@foreach (var item in Model) {
}
@Html.DisplayNameFor(model => model.First_Name)
| @Html.DisplayNameFor(model => model.Middle_Name)
| @Html.DisplayNameFor(model => model.Last_Name)
| @Html.DisplayNameFor(model => model.Contact_No)
| @Html.DisplayNameFor(model => model.Email_ID)
| @Html.DisplayNameFor(model => model.Temp_Address)
| @Html.DisplayNameFor(model => model.Permanant_Address)
| @Html.DisplayNameFor(model => model.Country.CountryName)
| @Html.DisplayNameFor(model => model.State.StateName)
| @Html.DisplayNameFor(model => model.City.CityName)
| | @Html.DisplayFor(modelItem => item.First_Name)
| @Html.DisplayFor(modelItem => item.Middle_Name)
| @Html.DisplayFor(modelItem => item.Last_Name)
| @Html.DisplayFor(modelItem => item.Contact_No)
| @Html.DisplayFor(modelItem => item.Email_ID)
| @Html.DisplayFor(modelItem => item.Temp_Address)
| @Html.DisplayFor(modelItem => item.Permanant_Address)
| @Html.DisplayFor(modelItem => item.Country.CountryName)
| @Html.DisplayFor(modelItem => item.State.StateName)
| @Html.DisplayFor(modelItem => item.City.CityName)
| @Html.ActionLink("Edit", "Edit", new { id=item.StudentID }) |
@Html.ActionLink("Details", "Details", new { id=item.StudentID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.StudentID })
|
|
|
|
|
|
Hello,
I’m planning to build a website using ASP.net. The members of this site should use a client like Skype. The client should support the following features:
·Audio Chat.
·Text chat and instant messaging.
·Desktop sharing
I do not know the best option to achieve that. Is there an existing library to develop this client? Or I should build the client from scratch? Shall I use SIP, XMPP or other protocols? Can I use Google for work or office 365?
Note: The expected number of users is 100’000 and later in future.
Thanks in advance
|
|
|
|
|
If you want a custom solution have a look at the SignalR framework.
Desktop sharing can be extremely sketchy (you're potentially sending IO command and control over public networks and have a serious possibility of breaking Confidentiality and Integrity) and unless you have a full Dev/QA team is completely not worth developing in any serious way.
Adobe connect does everything you're talking about and already scales; I'm sure there are other options out there as well.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
|
When i am creating a custom control dynamically and add that control on Panel/ContentPlaceHolder and then i Submit the page, now delete all Dynamically Created Custom controls are deleted.
modified 2-May-16 8:15am.
|
|
|
|
|
Controls you create yourself are not automatically remembered, you have to re-add them on page_load or page_init.
|
|
|
|
|
But How to access Data from that control on Submit button click
|
|
|
|
|