Archive for the 'ASP and ASP.net' Category

How to generate valid Credit Card numbers and validate in asp.net

Disclaimer: The following information is intended for informational purposes only.

creditcardsJust read the hacker quarterly magazine 2600 while I am in the SQL training. And I found out the information on the Page 19 is very interesting. Within it, the author taught how to generate the valid credit card numbers to fool some free trial web sites since these web site will not verify the credit card is real, but only to check these numbers are valid.

I think it will be a good point for us, as developer, to use these formula to do some simple  credit card numbers validation as well in our code. Or just simply to generate some fake-real credit card to do the application testing.

Continue reading ‘How to generate valid Credit Card numbers and validate in asp.net’

Related posts

Send Free Text Messages via SMTP in applications

I was thinking to update some of my ASP.net  applications which are sending alerts to subscribers via emails. The update will allow them to send out alerts as SMS (Short Message System) or text messages to users’ mobile phones.

I believe we need some third-party add-ons in the ASP.NET code to accomplish the above. But in North America, there is a work-around to do so since most of the cellular providers have a email-like system for their phone numbers.

Continue reading ‘Send Free Text Messages via SMTP in applications’

Related posts

Easy way to Format Strings with Capital Inital letters in VB.NET

I am developing a web application with ASP.NET and Oracle database. In the Oracle, there is a table with a “City” field whose data is in Upper Case. To make the data look good, I format the city name in the Stored Procedure with InitCap function from Oracle as the blow:

SELECT DISTINCT INITCAP(F_city) AS CITY FROM CITY_TAB
ORDER BY CITY ASC;

Now, I need to accomplish the same in my VB.NET code. Of course, based on my previous knowledge I was not aware of  such String Function in VB.net the similar as the INITCAP. And I used to write a function to loop all strings and put the first letter in Capital when we were coding in VB script (ASP).

This week, I found out a easy way to do so in ASP.NET. Now you can use StrConv to get the formatted string. For example:

Dim strCity as String = strConv(strCity, vbstrconv.vbproperCase)

Enjoy programming!

Related posts

System.Data.OracleClient will be deprecated in .net framework 4.0

Got an email forwarded by the co-worker, saying the Microsoft ADO.NET team is going to deprecate OracleClient as a part of their ADO.NET roadmap.

The Decision

After carefully considering all the options and talking to our customers, partners, and MVPs it was decided to deprecate OracleClient as a part of our  ADO.NET roadmap.

Recommendation and Guidance:

System.Data.OracleClient will be available in the upcoming 4.0 release of .NET Framework; however, it will be marked as deprecated. This will have no impact to existing applications and these applications will continue to work as expected. Developing new applications which use OracleClient will be supported; however, warnings will be raised if the applications are compiled against .Net 4.0. Once compiled, no warnings or errors will be generated while running these applications. We strongly recommend customers to use  our partners’ ADO.NET Provider for Oracle  instead of continuing to use Microsoft’s OracleClient for new application development.

Continue reading ‘System.Data.OracleClient will be deprecated in .net framework 4.0′

Related posts

Domain user name issue in web.config for Windows authentication

Today one of my co-workers did the trouble shooting and resolved this stupid problem together with me, and suggested put on the blog to share it. So here we go.

To make one of our internal web application authentication method simply, I decided to use Windows authentication and put the only one user in the web.config. The following are what I put in the web.config:

<authentication mode=”Windows”  />
<authorization>
<allow users=”DOMAINNAME/USERID”/>
<deny users=”*”/>
</authorization>

But the web form won’t authenticate me even I put the right user name and password, a windows logon prompt always jumped out.

I changed to <deny users=”?” /> then everyone can get in.

By the way, I have made the change in IIS to disable the anonymouse authentication and enable the Integrated Windows Authentication.

Finally, we figure out that we used the wrong slash in the user name. We should use backward slash “\” instead of the forward slash “/”. The working code should be

<authentication mode=”Windows”  />
<authorization>
<allow users=”DOMAINNAME\USERID”/>
<deny users=”*”/>
</authorization>

Gosh, never paid attentions on it before. I used both of them in asp.net 1.1.

Related posts

two issues of asp.net development

Today, got bothered by two issues when I was doing the asp.net development.

First, all of the sudden, the “~” symbol in my code did not work anymore after I did some modifications. For example, I have one line of code to re-direct the users to an error page (/MyApp/App_Include/ErrorPage.aspx) like the below.

Response.Redirect("~/App_Include/ErrorPage.aspx?aspxerrorpath=" & Me.Page.Request.Url.ToString(), True)

But when any errors raised in some web forms in the location of /MyApp/Forms/somepage.aspx, I could not be re-directed to the ErrorPage.aspx, instead I got a 404 page not found error. It seemed the system was trying to find /MyApp/Forms/~/App_Include/ErrorPage.aspx.
Continue reading ‘two issues of asp.net development’

Related posts

Fix Access is denied (Exception from HRESULT: 0×80070005 (E_ACCESSDENIED)) on local machines

ASP.NETSince Wednesday, all developers’ machines could not load asp.net applications on Visual Studio’s development servers. And we even could not debug, build the solution and could not Copy Website either; and could not drag/drop the AJAX Extension toolkit controls to the web forms.

The error message when we loaded the web application was the following:

Server Error in ‘/MyAPP’ Application.


Access is denied. (Exception from HRESULT: 0×80070005 (E_ACCESSDENIED))

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

……

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

……

[FileLoadException: Could not load file or assembly 'AjaxControlToolkit, Version=1.0.20229.20821, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e' or one of its dependencies. Access is denied.]

Continue reading ‘Fix Access is denied (Exception from HRESULT: 0×80070005 (E_ACCESSDENIED)) on local machines’

Related posts

How to add “Reply-To” in email message created in ASP, ASP.net code

ASP.NETThis post is not to discuss how to create and send emails from your asp, or asp.net code. And I assumed that you already knew how to do so. I just wanted to share with you that how I make “Reply-To” work in asp and asp.net code.

Why do we need the “Reply-To” at the first place? Well, replying to an email message usually sends the response to the person who sent the email. However, there are scenarios where you may want to have the reply go to an alternate email address. For example, if you are sending out emails on web site with the consistent system email address, you may want to have any replies go directly to the person who is responsible on one particular application.

Continue reading ‘How to add “Reply-To” in email message created in ASP, ASP.net code’

Related posts

How to display images in Crystal Reports for Visual Studio .NET 2005

visual_studio I had an ASP.net script which calls Crystal Report Viewer to display Crystal Reports, and it had no problem at all till this week. I have a report from the co-worker which has an image inside. But when it shows in ASP.net page, the image place had a broken link. Of course, the rest of report was fine.

After I right clicked the broken link, I saw a URL saying “CrystalImageHandler.aspx?…” something. Since there was no physical CrystalImageHandler.aspx existing in the web server, my understand was that there should be some function of Crystal Report Viewer missed here.

Continue reading ‘How to display images in Crystal Reports for Visual Studio .NET 2005′

Related posts

How to set the default value of a data binding DropDownList easily with ASP.NET page

ASP.netThere are a lot ways to set the default value for a dropdownlist when it has been databinded in an ASP.NET Page. I will list some of them and point out the pros and cons.

Way #1 (recommended way):

In an ASP.NET page, if the DropDownList web control (here I call dropdownExample) has an datasource (sqldatasource or objectdatasource), and when it is data binding you can define the following:

Protected Sub dropdownExample_DataBound(ByVal sender As Object,
ByVal e As System.EventArgs) Handles dropdownExample.DataBound
’set the default value for the drop down

Me.dropdownExample.SelectedIndex = Me.dropdownExample.Items.IndexOf ( Me.dropdownExample.Items.FindByValue ( ‘The Default Value’ ) )
End Sub

Continue reading ‘How to set the default value of a data binding DropDownList easily with ASP.NET page’

Related posts

Confusion about Server.MapPath method in asp.net

ASP.NETToday one of my co-worker asked a very interesting question about the mapPath menthod in asp.net. He used the MapPath(”virtualpath”) in his ASP.NET web file directly to get the physical path of files. But he could not do so in his component files (like class .vb files).

He understood that was because the place he used does not have the namespace for MapPath imported by default. But he just could not find the right namespace.

To help him and myself understand more in the future, let us explain a little bit more here.

Continue reading ‘Confusion about Server.MapPath method in asp.net’

Related posts

How to fix Enter key press issue in multiline textarea with defaultbutton defined in asp.net page

As I posted on How to set the DefaultButton in a Page Based on ASP.NET Master Page, a DefaultButton property has been defined in the ASP.NET pages which can fire the onClick event in asp.net page when the Enter key is pressed. But I got another new problem: when I pressed Return key in a multiline textbox, a new line was not generated. Instead, the in-completed form was tried to be submitted.

And I found out it caused the problem only when I used Firefox, and I tested it in IE everything was fine.

According to the Microsoft Online Support, there is a in-compatible issue in ASP.net 2.0 generated Javascript.

Continue reading ‘How to fix Enter key press issue in multiline textarea with defaultbutton defined in asp.net page’

Related posts

The problem with Microsoft VSS and Copy web in Visual Studio .net

Asp.NETWhen I am using the Copy Web command in the Microsoft Visual Studio .net 2005 to copy asp.net files from the local to the remote server, sometime I got error saying “Access denied” (BTW, to see the Error Log, you will have to scroll down and click the Log… button which might be invisible if you have a small screen).

To resolve this problem, you will have to logon to the remote server to make sure

  • The destination folder is opened with Write permission for the ASP.NET users
  • If you are replacing the files, please make sure the files are not READ ONLY on the remote server

The item #2 happened to me a lot, and I had to uncheck the READ ONLY checkbox from the files’ properties. The only explanation I can come up is that the Microsoft Visual Safe 6.0 sometime made the files READ-ONLY since we are using VSS for the coding collaboration.

Related posts

How to set the DefaultButton in a Page Based on ASP.NET Master Page

Challenges:

Asp.NETAs I mentioned in my previous post, I fixed the issue of hitting enter key on an ASP.NET page with a single textbox and submit button. But now new issue occurred: I could not use the Enter key on other button web controls. Whenever I hit the Enter key in the web form, the onClick event of the search button fires not the other submit buttons. I know I am using Master page and the search button is included in every page based on this master page. And the search button is in the first button web control position.

Trouble Shootings:

OK, the first thing came to my mind to resolve the issue above was to use the  new DefaultButton properties in ASP.NET 2.0 form or panel controls. But since I am using Masterpage, when I put defaultButton=”btnSubmit” in master page or put the following code in my Page_load event

Page.Form.DefaultButton = “btnSubmit”

I got the following error:

Server Error in ‘/MyApplication’ Application.
The DefaultButton of ‘form1′ must be the ID of a control of type IButtonControl.

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: System.InvalidOperationException: The DefaultButton of ‘form1′ must be the ID of a control of type IButtonControl.

Continue reading ‘How to set the DefaultButton in a Page Based on ASP.NET Master Page’

Related posts