Monday, October 24, 2011

Create a hyperlink using a QueryString or Form parameter in C# ASP.NET

 

This is a very short code snippet which shows you how you can create a hyperlink using a QueryString or Form parameter received from a referring page.

Note that you would need to do two things in order for this to work:

Step 1
First, paste the code below in the HTML markup.  The code below assumes that you are using a querystring parameter called “ID” that was passed over from a previous page.

<asp:HyperLink Target="_blank" ID="HyperLinkViewFeedback" runat="server"
NavigateURL='<%# String.Concat("~/Feedback/ViewFeedback.aspx?ID=",Request.QueryString["ID"]) %>'>View Feedback</asp:HyperLink>

Step 2
Add the “Page.DataBind()” method to the OnLoad of the code-behind file.

protected void Page_Load(object sender, EventArgs e)
{
Page.DataBind();
}

After that, you should see the hyperlink with the ID automatically appended as follows:


2011-10-24_132412

Wednesday, February 23, 2011

How to: Enable User Password Recovery Using the ASP.NET PasswordRecovery Control

How to: Enable User Password Recovery Using the ASP.NET PasswordRecovery Control
How to: Install and Configure SMTP Virtual Servers in IIS 6.0
Solving exceptions when doing password recovery

asp.net - Hashed passwords and PasswordRecovery control - Stack Overflow

asp.net - Hashed passwords and PasswordRecovery control - Stack Overflow: "UPDATE:

1) For some reason it works now. Namely, if we set requiresQuestionAndAnswer to false, then PR also sends email to firstUser


2) If passwords are stored in hashed form, then if:

a) enablePasswordRetrieval='true' and enablePasswordReset is set to either true or false --> PR generates exception
b) if enablePasswordRetrieval='false' and enablePasswordReset='false' --> PR generates exception
c) if enablePasswordRetrieval is set to false and enablePasswordReset is set to true, then PR automatically generates new pwd and emails it.


Similarly, if pwd is not hashed, but we have enablePasswordRetrieval='false', then enablePasswordReset must be set to true (so that PR generates a new pwd and emails it), else we get an exception"

Tuesday, February 22, 2011

How to: Read Connection Strings from the Web.config File

using System.Configuration;
using System.Data;

public static string GetUserName(string userid){
string fullname = "Unknown name";
string connString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString; string sqlString = "SELECT * FROM Users WHERE UserID=@UserID";
SqlDataSource sqldatasource = new SqlDataSource(connString, sqlString);
sqldatasource.SelectParameters.Add(new Parameter("UserID", System.Data.DbType.String, userid));

DataView dv = (DataView)sqldatasource.Select(DataSourceSelectArguments.Empty);
if (dv != null && dv.Table != null & dv.Table.Rows.Count > 0)
{
fullname = dv.Table.Rows[0]["FullName"].ToString();
}

return fullname;
}

How to: Read Connection Strings from the Web.config File: "ConnectionStrings.ConnectionStrings['NorthwindConnectionString'];"

Monday, February 14, 2011

MembershipUser Class (System.Web.Security)

MembershipUser Class (System.Web.Security)

Using ConfigurationManager.AppSettings

Step 1
======
Add a reference to assembly


Step 2
======
Add this before the class header

using System.Configuration;

Step 3
======
Access the configuration setting using this code:

System.Configuration.ConfigurationManager.AppSettings["WebMasterEmail"]