Web application Sharing including ASP, ASP.NET 1.0 (C#) AND ASP.NET 2.0 (C#) MS SQL 2005 Server, Life, Travelling
Wednesday, October 31, 2007
window.location.search
To test on the usage, save below page as locationsearch.htm. To see the result, add querystring to the page called: locationsearch.htm?p=testing&l=javascript
<html>
<head>
<script language="JavaScript">
function onload()
{
alert(window.location.search);
}
</script>
</head>
<body onLoad="onload()">
</body>
</html>
Monday, October 29, 2007
Top 100 living geniuses
Top 100 living geniuses
|
Extract from http://www.telegraph.co.uk/
Saturday, October 27, 2007
Hot topic in town - Facebook
http://wiki.developers.facebook.com/index.php/ASP.NET
Thursday, October 25, 2007
System.Net.Mail.SmtpFailedRecipientsException
System.Net.Mail.SmtpFailedRecipientsException: Unable to send to all recipients. ---> System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: No such user here --- End of inner exception stack trace --- at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message)
Few things that i test on new server:
- Install SMTP - check on document provided
- Testing with the Pickup directory
You can also compose a simple e-mail text file based on the SMTP specifications (RFC 822). Here is the content of a sample text file typed in Notepad:
From: myname@mydomain.com
To: someone@somedomain.com
Subject: testing
This is the test message body.
Simply copy or move the text file into the Pickup directory where SMTP was installed. (The default path should be "\Inetpub\mailroot\Pickup" but if you have Exchange installed then the path will be "\Program Files\Exchsrvr\Mailroot\Vsi 1\Pickup".) - Set Relay Restrictions in the IIS admin. Put your app server IP Address/Domain Name in the Relay Resctictions.
- After all, remember to restart your machine. Restart IIS or Virtual SMTP server won't help. Restart the server do the best.
Done
CS0030: Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'
Posted by Microsoft on 9/29/2005 at 4:46 PM
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.
Server Error in '/' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0030: Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'
Source Error:
Line 118: public login_aspx() {
Line 119: string[] dependencies;
Line 120: ((Login)(this)).AppRelativeVirtualPath = "~/Login.aspx";
Line 121: if ((global::ASP.login_aspx.@__initialized == false)) {
Line 122: dependencies = new string[6];
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\3e0e0b67\701b7b2\App_Web_login.aspx.cdcab7d2.fhpe1ais.0.cs Line: 120
Many post and solutions can get from the internet. Among them is
- Rename Login.aspx to others name like signin.aspx
- 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.<%@ page ... inherits="theNs.Login" %.namespace theNs { public partial class Login : System.Web.UI.Page { .. } }
- uncheck “Allow this precompiled site to be updatable” when Publish Web Site in Visual Studio 2005.
Wednesday, October 24, 2007
A generic error occurred in GDI+.
Server Error in '/' Application.
A generic error occurred in GDI+.
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.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
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.
Stack Trace:
[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +396978
System.Drawing.Image.Save(String filename, ImageFormat format) +69
Account.WarpImageDimensions(String filePath, String fileName, Bitmap imageToSave) +301
Account.ImageButton1_Click(Object sender, ImageClickEventArgs e) +350
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +86
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
Solve this by:
1. check the permission for upload folder
2. check the correct upload path
problem solved.
Select top xx from DataTable
DataTable outputTable = SourceTable.Clone();
for(int i=0;i<20;i++)
outputTable.ImportRow(SourceTable.Rows[i]);
In my case, i need to sort my DataTable oldTable and select top 20 after the sorting. I use DataView dView to sort it and copy it into a new DataTable newTable. For the display purpose, i use "for loop" to select top 20 from the new DataTable newTable.
Sample Code:
int maxDisplay = 20;
DataView dView = oldTable.DefaultView;
dView.Sort = " [Count] DESC ";
DataTable newTable = dView.ToTable();
int dCount = newTable.Rows.Count;
if (maxDisplay > dCount )
maxDisplay = dCount ;
if (dCount > 0)
{
for (int i = 0; i < maxDisplay ; i++)
{
xxxxxx;
xxx + newTable.Rows[i]["name"].ToString();
xxxxxx;
}
}
text wrapping in table : Firefox and IE
I'm using C# StringBuilder object to generate a long string with all blog Tags with link and without any white space between them. I've tried below code.
.hardbreak
{
width: 190px;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
<table style="TABLE-LAYOUT: fixed; WIDTH: 210px" cellpadding="'3'">
<tr>
<td class="hardbreak" style="WIDTH: 200px">
xxxx return StringBuilder code over here xxxx
</td>
</tr>
</table>
Result in IE: working fine. Even the word can be wrapped.
Result in Firefox: not working
this give me a problem.
I've try to google around and finally i found that i should insert a white space " " after every single tag before append to StringBuilder. Surprisingly, without using the class above, my problem solved.
Friday, October 19, 2007
Server Error in '/'Application. Configuration Error
Server Error in '/'Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Unrecognized attribute 'requirePermission'.
Change the ASP.NET version to the correct version.
Problem solved.
Thursday, October 18, 2007
Must declare the scalar variable "@UserId".
Server Error in '/' Application.
Must declare the scalar variable "@UserId".
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.Data.SqlClient.SqlException: Must declare the scalar variable "@UserId".
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.
Stack Trace:
[SqlException (0x80131904): Must declare the scalar variable "@UserId".]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +862234
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +739110
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1956
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +903
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +62
Dal.GetRecentRater(Int32 PostId, DataTable dt) +190
Post.BindBlogPost() +1295
Post.Page_Load(Object sender, EventArgs e) +49
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
At this point, i suspect something wrong with the staging server DB. So i access to the staging server and execute the stored procedure in Query Panel and it give me some error message.
Must declare the scalar variable "@UserId".
I open and check the stored procedure and the stored procedure is simple
ALTER PROCEDURE [dbo].[GetUserDetails]
@UserId int
as
select * from Users where UserId = @UserID
After check for a while, i change the @UserID to @UserId and magic happened. Problem solved. It's case sensitive.
It's strange because this stored procedure running in production server without any problem. Collation for both MS SQL 2005 DB are SQL_Latin1_General_CP1_CI_AS.
Tuesday, October 16, 2007
DataList Paging
CREATE PROCEDURE [dbo].[GetProductByCategory]
@PageIndex INT,
@NumRows INT,
@Discontinued BIT = 1
AS
BEGIN
SET NOCOUNT ON
DECLARE @StartRowIndex INT;
SET @StartRowIndex = (@PageIndex * @NumRows) + 1;
WITH myProducts AS(
SELECT ProductID, ProductName, UnitPrice,
CategoryName, Description, UnitsInStock,
ROW_NUMBER() OVER(ORDER BY ProductID DESC) as Row,
count(*) over() AS ResultRowCount, Discontinued
FROM Products P
INNER JOIN Categories C
ON P.CategoryID = C.CategoryID
WHERE Discontinued = @Discontinued
)
SELECT * FROM myProducts
WHERE Row BETWEEN @StartRowIndex AND (@StartRowIndex + @NumRows)-1
ORDER BY ProductID ASC
SET NOCOUNT OFF
END
Monday, October 15, 2007
Could not load type '_Default'
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type '_Default'.
Source Error:
Line 1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" % >
Line 2:
Line 3: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
I'm able to run my application in Visual Studio, when try to open the application directly from IE, i get this error. After check for a while, i found that it's the problem for the ASP.NET Version that selected. After i change to ASP.NET 2.0.50727, problem solved.
ASP.NET wrapper for Twitter API
Download the wrapper from Yedda. Unzip the files and you can play around with the project.
What i do is
- Create a new class name TwitterWrapper in my App_Code
- Copy the code from Twitter.cs and paste in TwitterWrapper.cs
to twitter your message:
string xmlOutput = "";
string TwitterUserName = "username";
string TwitterPassword = "password";
string TwitterMessage = "Hello twitter";
if (TwitterUserName != "" && TwitterPassword != "")
{
try
{
TwitterWrapper twitter = new TwitterWrapper();
xmlOutput = twitter.Update(TwitterUserName, TwitterPassword, TwitterMessage, TwitterWrapper.OutputFormatType.XML);
}
catch (Exception ex)
{ }
finally
{ }
}
Sunday, October 14, 2007
System.Web.HttpParseException: Could not load the assembly App_Web_xxxx. Make sure that it is compiled before accessing the page.
System.Web.HttpParseException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page. ---> System.Web.HttpParseException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page. ---> System.Web.HttpParseException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page. ---> System.Web.HttpException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page.at System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCase, Boolean throwOnError)at System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly)at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData)--- End of inner exception stack trace ---at System.Web.UI.TemplateParser.ProcessException(Exception ex)at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData)at System.Web.UI.PageParser.PostProcessMainDirectiveAttributes(IDictionary parseData)at System.Web.UI.TemplateParser.ProcessMainDirective(IDictionary mainDirective)at System.Web.UI.TemplateControlParser.ProcessMainDirective(IDictionary mainDirective)at System.Web.UI.PageParser.ProcessMainDirective(IDictionary mainDirective)at System.Web.UI.TemplateParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.BaseTemplateParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.TemplateControlParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.PageParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)--- End of inner exception stack trace ---at System.Web.UI.TemplateParser.ProcessException(Exception ex)at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)--- End of inner exception stack trace ---at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPath virtualPath)at System.Web.UI.TemplateParser.ParseInternal()at System.Web.UI.TemplateParser.Parse()at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType()at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
After struggling for a while, i found that by doing 2 steps can solve this problem.
- Create a new Application Pool.
- Change the application pool for my application to the newly created pool.
Create new Application Pool in Internet Information Server 6 (Windows Server 2003)
Change the application pool for my application to the newly created pool.
Done.
For Windows XP developer, when face this error, Kill aspnet_wp.exe process,
go to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files and delete all the temporary files. Try to compile your project again.
Saturday, October 13, 2007
remove "Yahoo Toolbar" from Firefox
Open Mozilla Firefox,
Go to Tools Menu, Click On Add-ons
A new Add-ons windows popup, Select Yahoo Toolbar and click on Unistall button.
Done
ASP.NET Cookies
For example, we want to write the information to cookies under mydomain when we access to url beta.mydomain.com
HttpCookie cook = new HttpCookie("mydomain");
Response.Cookies.Clear();
Response.Cookies.Add(cook);
cook["UserId"] = userId;
cook["Name"] = username.Text;
cook.Expires = DateTime.MaxValue;
Response.Cookies.Add(cook);
To retrive the cookies information:
if (Request.Cookies["mydomain"] != null)
{
if (Request.Cookies["mydomain"]["UserId"] != null && Request.Cookies["mydomain"]["Name"] != null)
{
Session["UserId"] = Convert.ToInt32(Request.Cookies["mydomain"]["UserId"].ToString());
Session["UserName"] = Request.Cookies["mydomain"]["Name"].ToString();
}
}
Wednesday, October 10, 2007
Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'
MailMessage msg = new MailMessage();
msg.From = "info@xxx.com";
msg.To = "comments@xx.com";
msg.Bcc = "keith@xxx.com";
msg.Subject = "Comment";
msg.Body = "Comment: xxxxxxx xxxxxxx xxxxxxx ";
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = Global.smtp;
To solve the issue, i change to below code
MailMessage msg = new MailMessage();
msg.From = new System.Net.Mail.MailAddress("info@xxx.com");
msg.To.Add("comments@xx.com");
msg.Bcc.Add("keith@xxx.com");
msg.Subject = "Comment"; msg.Body = "Comment: xxxxxxx xxxxxxx xxxxxxx ";
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = Global.smtp;
Tuesday, October 9, 2007
Could not load file or assembly 'Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of ..........
Could not load file or assembly 'Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Here is the scenario:
My ASP.NET App use AJAX.NET and ASP.NET AJAX Control Toolkit
My application server have NO AJAX.NET and ASP.NET AJAX Control Toolkit installed.
To solve my problem with no AJAX.NET install in my application server:
- Copy AjaxControlToolkit.dll and AjaxControlToolkit.pdb version 1.0.61025.0 from my development machine to my ASP.NET App bin folder. (i install my AjaxControlToolkit in C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\AjaxControlToolkit)
- Copy System.Web.Extensions.dll (C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions) and System.Web.Extensions.Design.dll (C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions.Design) from my development machine to my ASP.NET App bin folder.
Alternatively, we can solve the problem by installing AJAX.NET and AjaxControlToolkit to the server.