|
Hi All,
My application is build in framework 3.5 and now i m converting into 4.5. Here is the code.
Response.Redirect(Request.ApplicationPath + path, true);
While converting this line to 4.5, i m getting "\" in Request.ApplicationPath. But i need application path.
Please anyone tell me why i m getting the "\" insider of the application path.
|
|
|
|
|
If you don't want the "\" then remove it using TrimStart or TrimEnd depending where you want to remove it from.
|
|
|
|
|
Hi,
Getting "\" is not a problem. Insider of getting "\", i need application path.
|
|
|
|
|
What is your definition of the "application path"?
|
|
|
|
|
|
"Website path" means nothing on its own, give me an example. What would the "website path" be for http://www.mysite.com/somefolder/page.aspx?param=1
|
|
|
|
|
In my local
http://localhost:1234/Admin/Home.aspx
Response.Redirect(Request.applicationpath + "Admin/Home.aspx")
Here Request.applicationpath returns "\"
|
|
|
|
|
See the first link in the search link I gave you below. But you have still not answered FE's question.
|
|
|
|
|
Thanks a lot for your valuable time. It is working fine. Made a changes based on your search result.
|
|
|
|
|
|
Thank you. It is working fine.
|
|
|
|
|
|
Hi,
I have code as below, which loads a partial view in which I have a Grid, but for some reason when one of the load doesn't happen because some failure or missing View etc, the previous partial view remaining unchanged, can somebody please help me how can I clear the previous page load when loading the current Page. Any help a code snippet, a link or a suggestion anything helps thanks a lot in advance my friends.
function GetLookupTableValue(e)
{<br />
if ($("#drpLookup").data("kendoDropDownList").text() != 'Select')
myHeader.innerText = "List of " + $("#drpLookup").data("kendoDropDownList").text();
else
myHeader.innerText = "";
var noCodeFilter = containsAny($("#drpLookup").data("kendoDropDownList").text(), ['Address Type', 'Gender', 'NPI Status', 'Rendering Provider Status', 'Rendering Provider Classification']);
if (noCodeFilter)
{
var url = '../Admin/GetLookupTableNoCode';
$("#divLookupTable").load(url, { LookupTableId: $("#drpLookup").data("kendoDropDownList").value(), __RequestVerificationToken: $('input[name=__RequestVerificationToken]').val() });
}
else if ($("#drpLookup").data("kendoDropDownList").text() == 'Medi-Cal - Mode of Service - Service Function')
{
var url = '../Admin/GetMCMSSFCrosswalkList';
$("#divLookupTable").load(url, { LookupTableId: $("#drpLookup").data("kendoDropDownList").value(), __RequestVerificationToken: $('input[name=__RequestVerificationToken]').val() });
}
else if ($("#drpLookup").data("kendoDropDownList").text() == 'Service Function Category')
{
var url = '../Admin/GetServiceFunctionCategoryLKPList';
$("#divLookupTable").load(url, { LookupTableId: $("#drpLookup").data("kendoDropDownList").value(), __RequestVerificationToken: $('input[name=__RequestVerificationToken]').val() });
}
else
{
var url = '../Admin/GetLookupTableCode';
$("#divLookupTable").load(url, { LookupTableId: $("#drpLookup").data("kendoDropDownList").value(), __RequestVerificationToken: $('input[name=__RequestVerificationToken]').val() });
}
}
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
load function accepts another parameter which is a function (ajax callback) that takes in response, status and xhr. In case of any error, status will have the error code in it. You can evaluate that and do as needed.
Your code can be refactored to avoid repeated blocks in if/else blocks.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
Can you please give me a small sample of load response error status code and can you please give me small sample of how to refactor the repeated if else blocks. A sample or even a link helps please - thank you very much for your suggestion buddy.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hello
I am hoping to use the following code in my VS 2017 project (register.aspx.vb) to hash/salt a password:
Public Function GetSalt() As String
Dim saltSize = 32
Dim Salt As RNGCryptoServiceProvider = New RNGCryptoServiceProvider()
Dim randomBytes(saltSize - 1) As Byte
Salt.GetBytes(randomBytes)
Return Convert.ToBase64String(randomBytes)
End Function
Public Function HashedPassword(ByVal Salt As String, ByVal providedPassword As String) As String
Dim passWithSalt = String.Concat(Salt, providedPassword)
Dim rawPasswordData() As Byte = Encoding.UTF8.GetBytes(passWithSalt)
Dim SHA512 As New SHA512CryptoServiceProvider()
Dim resultingHash As Byte() = SHA512.ComputeHash(rawPasswordData)
Return Convert.ToBase64String(resultingHash)
End Function
followed by:
Protected Sub btnReg_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReg.Click
Try
Using connection As New OleDbConnection("connectionString")
Dim Sql As String = "INSERT INTO university (username,strEmail,Hash) VALUES (@username,@strEmail,@Hash)"
Dim cmd As New OleDbCommand(Sql)
cmd.Connection = connection
cmd.Parameters.AddWithValue("@username", username.Text)
cmd.Parameters.AddWithValue("@strEmail", strEmail.Text)
cmd.Parameters.AddWithValue("@Hash", "Production based on simple ciphers and fixed encryption keys")
connection.Open()
cmd.ExecuteNonQuery()
End Using
Dim target = String.Format("~/success.aspx?Name={0}", username.Text)
Response.Redirect(target, True)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
How would I relate the GetSalt and HashedPassword functions, please, to the button click, in order to make this code work?
Thank you.
|
|
|
|
|
You need to store the Hash and the salt. When authenticating the password, you need both parts to make a match.
Your really better off using a package like BCrypt to do it for you. I've done it your way but stored the values as byte[] and not string.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Thanks jkirkerx, for your reply.
I am not familiar at all with BCrypt but, following your advice about 'You need to store the Hash and the salt', I take it that I would need two columns in my database to do that, namely, 'Salt', and 'Hash' (where 'Hash' would replace the plain password column), and I would need to alter my code to:
Dim Sql As String = "INSERT INTO university (username,strEmail,Salt,Hash) VALUES (@username,@strEmail,@Salt,@Hash)"
and
cmd.Parameters.AddWithValue("@username", username.Text)
cmd.Parameters.AddWithValue("@strEmail", strEmail.Text)
cmd.Parameters.AddWithValue("@Salt")
cmd.Parameters.AddWithValue("@Hash", "Production based on simple ciphers and fixed encryption keys") (I am not sure about how to code those last two parameters).
Thanks again.
|
|
|
|
|
Yup!
The Hash is the password that has been generated with Salt.
If you don't store the Salt, you can't verify the Hash
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Very many thanks again - you have been a great help.
Regards
|
|
|
|
|
Since you are in the context of ASP.NET, you may want to look at System.Web.Helpers.Crypto class as it provides a few handy functions to do Hashing for you. For example:
using System.Web.Helpers;
public void SavePassword(string unhashedPassword)
{
string hashedPassword = Crypto.HashPassword(unhashedPassword);
}
The Crypto.HashPassword function takes care of creating a salt for you. The returned value of that function already contains both the salt and the hashed password in a single value. All you need to do is store the username and hashed password in your database and you're done.
More info, read: Password management made easy in ASP.NET with the Crypto API | brockallen[^]
|
|
|
|
|
Very many thanks for your post, Vincent. That must be the simplest hash/salt I have seen! Thanks, to, for the link which discusses password verification for use on a log-in page.
I will give it a try.
I am assuming that, for the new user registration page, I would use (as above):
Public Sub CreateAccount(ByVal username As String, ByVal password As String)
Dim hashedPassword = Crypto.HashPassword(password)
CreateAccountInDatabase(username, hashedPassword)
End Sub
and then my 'Submit' button:
Private Sub BtnReg_Click(sender As Object, e As EventArgs) Handles BtnReg.Click
'Dim hashedPasswordText As New Label With {.Text = (Hash512(password.Text, CreateRandomSalt))}
Using connection As New OleDbConnection("connectionString")
Dim Sql As String = "INSERT INTO university (username,strEmail,hashed,salted) VALUES (@username,@strEmail,@hashed,@salted)"
Dim cmd As New OleDbCommand(Sql)
cmd.Connection = connection
cmd.Parameters.AddWithValue("@username", username.Text)
cmd.Parameters.AddWithValue("@strEmail", strEmail.Text)
Dim hashed As Boolean
cmd.Parameters.AddWithValue("@hashed", hashed)
Dim salted As Boolean
cmd.Parameters.AddWithValue("@salted", salted)
connection.Open()
cmd.ExecuteNonQuery()
End Using
End Sub
Does that look as if it may work?
Thanks again!
|
|
|
|
|
You don't need to store the salt anymore in your database as the returned value of the Crypto.HashPassword already has a Salt on it.
Dim hashedPassword = Crypto.HashPassword(password)
For example, the variable hashedPassword already contains the Hash + Salt
So your code would now be something like:
Private Sub CreateAccount(ByVal username As String, ByVal password As String, ByVal email As String)
Dim hashedPassword = Crypto.HashPassword(password)
Using connection As New OleDbConnection("connectionString")
Dim Sql As String = "INSERT INTO university (username,strEmail,hashed) VALUES (@username,@strEmail,@hashed)"
Dim cmd As New OleDbCommand(Sql)
cmd.Connection = connection
cmd.Parameters.AddWithValue("@username", username)
cmd.Parameters.AddWithValue("@strEmail", email)
cmd.Parameters.AddWithValue("@hashed", hashedPassword)
connection.Open()
cmd.ExecuteNonQuery()
End Using
End Sub
Private Sub BtnReg_Click(sender As Object, e As EventArgs) Handles BtnReg.Click
CreateAccount(username.Text,password.Text,strEmail.Text)
End Sub
PS: My apology as I'm not good at VB.NET 
|
|
|
|
|
 That's great, Vincent. Thank you for your time. I got one or two errors ('not declared') in VS 2017, which I have attempted to correct via the application's 'light-bulb', so the code now looks like this:
Public Sub CreateAccount(ByVal username As String, ByVal password As String)
Dim hashedPassword = Crypto.HashPassword(password)
CreateAccountInDatabase(username, hashedPassword)
End Sub
Private Sub CreateAccountInDatabase(username As String, hashedPassword As Object)
Throw New NotImplementedException()
End Sub
Private Sub CreateAccount(ByVal username As String, ByVal password As String, ByVal email As String)
Dim hashedPassword = Crypto.HashPassword(password)
Using connection As New OleDbConnection("connectionString")
Dim Sql As String = "INSERT INTO university (username,strEmail,hashed) VALUES (@username,@strEmail,@hashed)"
Dim cmd As New OleDbCommand(Sql)
cmd.Connection = connection
cmd.Parameters.AddWithValue("@username", username)
cmd.Parameters.AddWithValue("@strEmail", email)
cmd.Parameters.AddWithValue("@hashed", hashedPassword)
connection.Open()
cmd.ExecuteNonQuery()
End Using
End Sub
Private Sub BtnReg_Click(sender As Object, e As EventArgs) Handles BtnReg.Click
'Do some forms validation here
CreateAccount(username.Text, password.Text, strEmail.Text)
End Sub
I still get one compilation error while trying to load the page I my browser and that relates to Crypto which, VS tells me, is not declared. Again, the light-bulb pops up with a few alternatives including 'generate Crypto as class'. Not sure if that's what I should opt for as I am in unfamiliar territory here.
Thanks again.
|
|
|
|
|
You need to add a reference to the System.Web.Helpers assembly, and add Imports System.Web.Helpers to the top of your code file.
You'll also want to remove CreateAccount(ByVal username As String, ByVal password As String) and CreateAccountInDatabase(username As String, hashedPassword As Object) , since they're not used, and calling either of them will result in an exception.
NB: Don't remove CreateAccount(ByVal username As String, ByVal password As String, ByVal email As String) , since that's the one you're using.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|