Setup ASP.Net 2.0 Providers

(from: http://www.aquesthosting.com/HowTo/Sql2005/Providers.aspx)
Note: The new Aquest Hosting control panel now has a page that will install your ASP.Net 2.0 Providers to your SQL database for you. All you have to do is pick your database and click the button. If you are already hosting with Aquest Hosting, then you can skip this tutorial and use the installer in the control panel.

For the rest of you, this quick tutorial will show you how to setup the ASP.Net 2.0 Providers in SQL Server 2005

To follow this tutorial, you will need ‘dbo’ permissions to your database, and if you are an Aquest Hosting customer with a SQL Server 2005 database, then you already have ‘dbo’ permissions to your database.
Requirements:

You can connect to a SQL Server 2005 database using SQL Server Management Studio, and SQL Server 2005 Express Edition, which is available free as part of Visual Web Developer which can be downloaded free from
http://go.microsoft.com/fwlink/?linkid=46255&clcid=0x409.

This tutorial is using SQL Server Management Studio, but you should be able to figure out the other tools.

Part 1: Create the script:Create the script:

1. Open the ASP.Net 2.0 command prompt on your computer by clicking “Start | All Programs | Microsoft Visual Studio 2005 | Visual Studio Tools | Visual Studio 2005 Command Prompt”.
2. Enter “aspnet_regsql.exe -A all -sqlexportonly C:\runproviders.sql” and hit the enter key.
3. *You have written the script to “C:\runproviders.sql”, so open that file, and use your text editor’s “Replace” feature to replace all occurences of “aspnetdb” with your database name.

Part 2 – Run the script:

1. Connect to your SQL Server 2005 database server.
2. Click “New Query” in the top left corner.
3. Copy and paste your sql script into the query window.
4. Click the “Parse” check mark button to see if your script is error free.
5. Click the “Execute” button to run your script.

Part 3 – Verify Roles were added:

1. Look in the Security folder under your database and see if the provider roles were added (see image). They all start with “aspnet_”.

Part 4 – Add your sql user account to the roles:

1. Clear out the text in the Query window, or open a new Query window.
2. Make sure your database is selected in the drop down list in the tool bar.
3. Add the following script to the window.

Exec sp_addrolemember ‘aspnet_Membership_FullAccess’, ‘yourUser’
go
Exec sp_addrolemember ‘aspnet_Personalization_FullAccess’, ‘yourUser’
go
Exec sp_addrolemember ‘aspnet_Profile_FullAccess’, ‘yourUser’
go
Exec sp_addrolemember ‘aspnet_Roles_FullAccess’, ‘yourUser’
go
Exec sp_addrolemember ‘aspnet_WebEvent_FullAccess’, ‘yourUser’
go
4. Replace ‘yourUser’ in each command with your sql user name.
5. Click “Parse” to check for errors.
6. Click “Execute” to run the script.

Completed:

You have now completed setting up your ASP.Net 2.0 Providers in SQL Server 2005.


Invalid operator for data type. Operator equals add, type equals bit

When I wrote a sql server stored procedure, got a error message about bit data type when I tried to run this script:

Invalid operator for data type. Operator equals add, type equals bit.

The error msg is saying that a bit type parameter cannot be concatenated against the 2 strings. Cast it as varchar or nvarchar

The final script is like the following:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

IF EXISTS(SELECT name FROM sysobjects WHERE name = ‘procADGetStatus4Email’ AND type = ‘P’)
BEGIN
DROP PROCEDURE dbo.procADGetStatus4Email
END
GO

/*===============================================================
Creation Date: 19 June 2007
Author:        XXXXXX
Description:     Get Status List
Tables:     StatusDomain
Revisions:
===============================================================*/
CREATE   PROCEDURE dbo.procADGetStatus4Email
@StatusCode    smallint = NULL,
@EmailSendInd    bit = NULL
AS
SET NOCOUNT ON

Declare @strSQL as nvarchar(2000)
Declare @strSQLwhere as nvarchar(2000)

select @strSQL = ‘select DISTINCT A.StatusCode,  A.Member, A.StatusShortDesc, A.StatusLongDesc,’
select @strSQL = @strSQL + ‘A.CreatedDate, A.UpdatedDate,  A.UserID, A.EmailSendInd’
select @strSQL = @strSQL + ‘ FROM dbo.StatusDomain A ‘

select @strSQLwhere = ‘ WHERE A.StatusCode > 0 ‘

IF @StatusCode is Not Null and @StatusCode <> ‘-1’
select @strSQLwhere =  @strSQLwhere + ‘ And (A.StatusCode =  ‘ + cast(@StatusCode as nvarchar) + ‘)’

IF @EmailSendInd is Not Null
select @strSQLwhere =  @strSQLwhere + ‘ And (A.EmailSendInd =  ”’ + cast(@EmailSendInd as nvarchar) + ”’)’

IF DATALENGTH(@strSQLwhere)>0
select @strSQL = @strSQL+ @strSQLwhere

select @strSQL = @strSQL + ‘ ORDER BY A.StatusCode ‘

print @strSQL

EXEC  sp_executesql @strSQL

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

GRANT  EXECUTE  ON [dbo].[procADGetStatus4Email]  TO [LMS_Readers]
GO


How To Create an ASP.NET Application from Multiple Projects for Team Development

I got this good article from Microsoft:

How To Create an ASP.NET Application from Multiple Projects for Team Development

(from: http://support.microsoft.com/kb/307467)

I copied all their content in my Blog before, and put there , nobody told me sth. about it, but yesterday I transfer my old blog to this new one, sb. else posted comment and let me know seems I can not copy all content here.

Ok, let me just copy their Summary and give the left to redirect their site.  But I am just worried about they change their URL and I will lost this article. I really need it.

SUMMARY

loadTOCNode(1, ‘summary’); This article describes how to make multiple ASP.NET projects participate in the same Web application.

You may find it useful to separate a large Web application project into multiple projects for team development of ASP.NET Web applications in Microsoft Visual Studio .NET. Microsoft recommends that you use source control software, such as Microsoft Visual SourceSafe, in all scenarios.

Developing a large Web site frequently involves several developers. These developers must be able to work on specific sections of a Web application without interfering with one another and yet still be able to use each other’s work as the project progresses. To do this, you can use a single project in a Visual Studio .NET solution. You can also separate a Web application into multiple projects by dividing the development project into units to make development easier.

You can develop Web applications in single project or multi-project Visual Studio .NET solutions. The advantages and disadvantages of each method are outlined in the sections to follow.

(… Please go to MS site to read more…. )

http://support.microsoft.com/kb/307467

ASP.NET get page name, visiting user name, function name, form name:

1: string username = Me.Page.User.Identity.Name
2: string username = System.Environment.UserName()

1: string pagename = Me.Page.GetType().Name()
2: string pagename = Request.Path.Substring(Request.ApplicationPath.Length + 1)

1: string functionname = System.Reflection.MethodBase.GetCurrentMethod().Name

1: string formname = Request.Path.Substring(Request.Path.LastIndexOf(“/”)+1);

Cannot convert type ‘ASP.login_aspx’ to ‘System.Web.UI.WebControl’

If you have used a Page that effectively uses a codebehind classname
that is the same as say the Login control, that is Login, e.g. your
page was called Login.aspx, then when you pre-compile (publish) the web
site as an updateable web site, the aspx is retained and tries to
compile against a type called Login in the code behind. It does not
resolve to be that in the codebehind assembly

Try using a classname for your codebehind and defined in the inherits
that does not clash with a type in System.Web, e.g. LoginPage, or
qualify the class and therefore the inherits statement with a
namespace, e.g.
in the .aspx file:

<%@ page … inherits=”MyNameSpace.Login” %.
in the code behind file:

namespace MyNameSpace

{ public partial class Login : System.Web.UI.Page

{

..

}

}

how to get aspx page username ?

in vb its system.environment.username – whats the equivalent in aspx with
code behind (VB) ?

——————————————————————————–

In the codebehind of your aspx code, you could use:

Page.User.Identity.Name ;

In a custom class, you could use:
HttpContext.Current.User.Identity.Name;

——————————————————————————–

thanks but niether seems to work – aspx accepts it but it does nothing!

——————————————————————————–

It depends how you would like to use it.

If you want to get the Windows username you have to make sure you disabled
anonymous access in IIS.

If you use forms authentication you can make a custom principal:
System.Security.Principal.GenericIdentity identity = new
System.Security.Principal.GenericIdentity(“testUse rName”);
System.Security.Principal.GenericPrincipal principal = new
System.Security.Principal.GenericPrincipal(identit y,new string[]{
“TestRole”});

Context.User = principal;

Validation of ViewState Mac failed in ASP.NET 2

I met this asp.net Exception when I create a .mobi application followed the new policy of .mobi (I think it is WAP 2.0). I searched Google and got the following article, then I copy to here ((from : http://aspadvice.com/blogs/joteke/archive/2006/02/02/15011.aspx)). Later I will try to use the solution for my application

If you get this Exception

[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.]

and

* you know *for sure* that you aren’t using a web farm
* it seems that it appears when using built-in databound controls such as GridView, DetailsView or FormView which utilize DataKeyNames.
* it appears if you have a large page which loads slowly for any reason

Paypal STANDARD Website Payment Walkthrough?

Paypal STANDARD Website Payment Walkthrough?

Here is from a question about Commerce Starter Kit (asp.net). maybe it is can used for any e-commerce website code to setup Paypal payment.

Paypal STANDARD Website Payment Walkthrough?

To setup a fictitious Paypal account in the Sandbox and confirming the account:

1. Log into the Developer Central website at http://developer.paypal.com.
2. This will bring you to the Developer Central homepage.
3. Click on the Sandbox link found on the right side of the page or the tab found at the top.
4. This will list your fictious sandbox accounts.  To create a new one, click on Create Account.
5. When you click Create Account, it will open a new page of the Register a New Paypal account on the Sandbox environment.
6. You may select one of three account types (casual shoppers, casual sellers, or business owners)
7. For this example, let’s select casual shopper by clicking on the Start Now button
8. Enter in the pertinent information on the Create A Paypal account page and click on the “I Agree, Create My Account”.
9. This will take you to the Account Sign Up results page.
10. It now tells you to confirm your email address… Go back to the Developer Central page where the Sandbox tab is.  Make sure to click the tab again to refresh the list of test accounts with the new account showing up on the list!
11. Now… click on the Email tab found just two tabs to the right of the sandbox tab – this is where you will find all the email coming to the new fictitious email box.  You will see an email there with the subject Activate Your Paypal account.  Click the link of the “email”.
12. A fake email should popup on a new browser window – copy the confirmation number to the “clipboard”
13. Go back to the Sandbox tab, and select the new test account and click the Launch Sandbox button. Sign in to the sandbox with the new test account email address and password by clicking the Login button.
14. To the left you will see a link to “Confirm Email” – click it.
15. Then click the link… “Click here if a link DOES NOT appear in the email”
16. Paste the confirmation number (saved in the clipboard) into the field and click the Confirm button.
17. The account is NOW confirmed.  You may now click on Continue or Skip to do more setup for the account.

Hope this helps.

A button style HyperLink in ASP.NET

<asp:HyperLink ID=”linkCountry” runat=”server”
NavigateUrl='<%# “CountryLst.aspx?ContinentID=” + DataBinder.Eval(Container.DataItem,”continentid”) %>’
Text='<%# DataBinder.Eval(Container.DataItem, “continentname”) %>’
Font-Bold=”True” ForeColor=”Black” Font-Size=”Medium” BorderWidth=”3px” BackColor=”LightGray” BorderStyle=”Outset” Width=”83px” style=”TEXT-DECORATION: none”  >

Get relavated value of selected row of GridView using javascipts

(from: http://geekswithblogs.net/azamsharp/archive/2006/08/29/89697.aspx)
So, here is the story. I have a GridView which contains the ASP.NET CheckBox control. Each row also have the primary key of the database table. Now, I need to get the ID of the selected checkbox using JavaScript. I used a hidden field to store the ID of the row (The row is hidden and the user cannot see it on the display but you can see the value if you do the view source). Now, I like to access the hidden field of the selected row of the GridView.

<asp:TemplateField>

<ItemTemplate>

<asp:CheckBox id=”chkSelect” runat=”server” />

<asp:HiddenField ID=”hfID” runat=”server” Value='<%# Eval(“ID”) %>’ />

</ItemTemplate>

</asp:TemplateField>

And here is the JavaScript code:

function GetIDFromHiddenField()

{

var elements = document.getElementsByTagName(“INPUT”);

var ID;

var count = 0;

for(i=0; i< elements.length; i++)

{

if(elements[i].type == ‘checkbox’)

{

if(elements[i].checked == true)

{

count = count + 1;

ID= elements[i].nextSibling.nextSibling.value;

}

}

}

// check if more then one exam is selected. If so, then alert the user

if(count > 1) { alert(‘Please only select a single item from the list’); return (-1); }

else return ID;

}

Althought I am only allowing the user to select a single item I am sure you got the basic idea.