|
hey there, I'm still learning C# and am having some issues with a login I've created. The login page gets the user info into an object and sets the cookie no problem. But when I go to the next page I can't seem to figure out how to get at the object I created on the login page. Here's a snippet of what I've got...
login.aspx.cs
private void cmdLogin_ServerClick(object sender, System.EventArgs e)
{
UserDetails oUserDetails = validateUser(txtAssocNum.Value, txtUserName.Value, txtUserPass.Value);
if (oUserDetails != null)
{
Response.Cookies["UserID"].Path = "/";
Response.Cookies["UserID"].Value = oUserDetails.UserID.ToString();
FormsAuthentication.RedirectFromLoginPage(txtUserName.Value, chkPersistCookie.Checked);
}
else {
lblMsg.Text = "The information you provided does not match our database.";
}
}
loadDetailsAfterLogin.aspx.cs
protected System.Web.UI.WebControls.Panel PanelMain;
private void Page_Load(object sender, System.EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (!User.Identity.IsAuthenticated)
{
Response.Redirect("~/Login.aspx");
}
UserDetails oUserDetails = new UserDetails();
PanelMain.Controls.Add(new LiteralControl("<table>"));
PanelMain.Controls.Add(new LiteralControl("<tr><td>First Name : </td><td>" + oUserDetails.FirstName + "</td></tr>"));
PanelMain.Controls.Add(new LiteralControl("<tr><td>Last Name : </td><td>" + oUserDetails.LastName + "</td></tr>"));
PanelMain.Controls.Add(new LiteralControl("</table>"));
oUserDetails = null;
}
Thanks in advance.
|
|
|
|
|
liamderice wrote:
First Name : " + oUserDetails.FirstName + "
Last Name : " + oUserDetails.LastName + "
oUserDetails does not exist on this page, therefore you can't access it.
I suggest you learn some OO and C# first, then move on to ASP.NET.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I had wondered that, but thought there might be a fancy new way of keeping the state of an object between pages in c#. Thanks.
|
|
|
|
|
There are ways, but they're neither fancy nor are they new.
I suggest that you google
Asp.net request.querystring
Asp.net session
Asp.net Page State
for the most common methods to pass data between pages.
|
|
|
|
|
Jorgens answer is correct. I'll just add - user info should go in the session, but for anything else, I'd write pages that load data from the db using a value on the querystring.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Yeah, I'm used to doing this kinda thing with classic asp, but thought there might be something different as I moved to c#. Thanks for the advice guys.
|
|
|
|
|
|
Hi All,
I've been grappling with this for a few days now, and am no further forward, here's the scenario:
I have a page that contains the following
linqDataSource : productListDS (Selects * from products table)
GridView : gridProductList (Data source is productListDS)
linqDataSource : productDetailDS (Selects * from products table where id == id)
DetailsView : detailsProduct (Data source is productDetailDS)
The gridview lists all the products in the data source, with paging and select button enabled, when the select command is clicked the details view is then updated to show all the fields of the selected product and has the 'Edit', 'Insert' and 'Delete' commands enabled.
The gridView ONLY shows 5 columns from it's data source (The AutoGenerateColumns option is false) and i'm constructing the colums manually in the columns tag. I have the DataKeys set to id, and when i click the select button everything works flawlessly.
My problem comes when i do an Insert/Delete/Update.
As an example if i add a new record by putting the details form into insert mode, fill in the fields and then click insert, it inserts the record into the underlying SQLServer database, but the gridview does not update.
I've tried doing a 'gridProductList.DataBind()' in the page load, and in the details view 'ItemInserted' event, and still no luck. If however i browse away from the page, and then back the gridView then displays the newly added products. Even pressing F5 to force an update does not work, in fact all that achieves is to resubmit the last insert and add another new record to the DB.
The linq Data SOurce is connected to a LInqToSql DBML class.
Does anyone have ANY ideas on how to force the Grid View to update and show the table changes made using the details view without having to browse away from the page and then browse back.
Cheers
Shawty
|
|
|
|
|
pingpingpong wrote: I've tried doing a 'gridProductList.DataBind()' in the page load,
Page load runs before your events. So, you're binding before the insert. This is why browsing away and back works. Do your databinding in page prerender, always.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thanks Christian,
I'll look into that, one more question...
Does ths even apply when i'm not doing the original databinding manually, i'm just letting the datasource/datagrid sort it out them selves. Calling the DataBind() proc just seemed like a sensible thing to try to force it to update.
|
|
|
|
|
Christian, thanks.... that worked excellently. ![Smile | :)](https://www.codeproject.com/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
sir,
Just to encrypt a string, i used this code.
code:
public string encryptText(string plaintext,string passpharse,string saltValue,string hashAlgorithm,int passwordIterations,string initvector,int keysize)
{
byte[] InitVectorBytes = Encoding.ASCII.GetBytes(initvector);
byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
byte[] plaintextbytes = Encoding.ASCII.GetBytes(plaintext);
PasswordDeriveBytes password = new PasswordDeriveBytes(passpharse, saltValueBytes, hashAlgorithm, passwordIterations);
byte[] keyBytes = password.GetBytes(keysize / 8);
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, InitVectorBytes);
MemoryStream memorystream = new MemoryStream();
CryptoStream cryptostream = new CryptoStream(memorystream, encryptor, CryptoStreamMode.Write);
cryptostream.Write(plaintextbytes, 0, plaintextbytes.Length);
cryptostream.FlushFinalBlock();
byte[] ciphertextbytes = memorystream.ToArray();
memorystream.Close();
cryptostream.Close();
string ciphertext = Convert.FromBase64String(ciphertextbytes);
return ciphertext;
}
I've got the following errors:
Error 1 The best overloaded method match for 'System.Convert.FromBase64String(string)' has some invalid arguments.54,29
Error 2 Argument '1': cannot convert from 'byte[]' to 'string'.54,54
Please help me to resolve it.
|
|
|
|
|
You've declared ciperTextBytes as a byte array, when it needs to be a string.
ConvertFromBase64String(string) is telling you that you need to pass the parameter to it as a string data type.
I'm not 100% sure with out testing it, but
string ciphertext = Convert.FromBase64String(ciphertextbytes.ToString()); !!MIGHT!! work.
Cheers
Shawty
|
|
|
|
|
|
You need to describe it better than that i'm afraid.
the .ToString()??? the function??? the routine??? try to convert your byte array to a string before hand. It's fairly easy.
All you need to do is iterate through the array collection and convert each byte to a char before adding it to a string.
Cheers
Shawty
|
|
|
|
|
Sir,
please explain it in detail
|
|
|
|
|
There's not much to it.
You just need to declare a string, make it empty :
String [myvariablename] = ""
then you just need to loop over your byte array :
foreach(byte [mybytevariablename] in [mybytearrayname])
then in the loop just concatenate each element.
[myvariablename] = [myvariablename] + [mybytevariablename]
When your finished, then the string you defind should be a string of all the chars in your byte array which you can then pass to the function.
replace the [..] above as appropriate for your variable names where you've defined them.
|
|
|
|
|
If you can write encryption code, I fail to understand why you have a problem with such trivial error. At least you tell me what your code is trying to do, and why you are impementing it this way.
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Hi,
Good Day!!!
I did a asp.net website application in one system. When I place the same application in other system, I could not able to open it.
Can anyone please suggest me that what are the minimum requirements to be done to open the application in other system?
Thanks,
Ravi Chandra.
|
|
|
|
|
nuthan anand wrote: I did a asp.net website application in one system. When I place the same application in other system, I could not able to open it.
What does it mean? VS is there ? Did you copied complete Web sites and Solution file?
nuthan anand wrote: Can anyone please suggest me that what are the minimum requirements to be done to open the application in other system?
Open VS -> File -> Open -> Web sites.
Browse the folder , and open it.
That's all.
cheers,
Abhijit
CodeProject MVP
|
|
|
|
|
I think the most common thing is this. Someone creates a website within visual studio and so the security on the directory is handled for you. Then you move the directory to someother location for deployment and it doesn't work. Typically this is because the service that is running doesn't have proper access to the new directory. However, it would be more helpful if you shut of friendly error messages and posted what the exact error is that your getting.
|
|
|
|
|
HI all,
I gave the stored procedure for a sql adapter(database1) and in the select command i selecedt stored procedure ..
I have other adapter(database2) in tat i gave the update stored procedure for same table.
can i do the code like this
sqladapter1.fill(ds)
take that dataset and update to other sqladapter 2
sqladpater2.update(ds)
wether it will work?
or any other idea or easy way to insert a table datas from one db to other db table ..
pls help me
|
|
|
|
|
try googling:
1.) T-SQL Append from
2) .NET SQlCommand
should answer all your questions in the 1st page of each search
|
|
|
|
|
Specifically:
Windows Server 2008 Datacenter 64-bit
Oracle 10.2 instant client x86 64-bit
IIS 7
.NET 3.5 / ASP application
The behavior is that the app pool sometimes crashes when I hit the website, or sometimes it gives a database connection ASP error page. I can get it working by stopping the site, then renaming the directory and binding the site to the renamed directory. I startup the site and it works! But when I reboot the machine it doesn’t work, so it seems like there’s something intermittent with the database drivers.
Any suggestions?
|
|
|
|
|
Khaldris wrote: he behavior is that the app pool sometimes crashes when I hit the website
How did you say that? Is there other application also added to the same application pool ?
cheers,
Abhijit
CodeProject MVP
|
|
|
|