Search This Blog

Loading...
Showing posts with label ASP.NET. Show all posts
Showing posts with label ASP.NET. Show all posts

Monday, August 22, 2011

ASP.NET - new session id when refresh the page

Using Visual Studio 2005, dotnet framework 2.0.

Try to get a session id in default.aspx


  public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            txtSessionID.Text = this.Session.SessionID;
        }
    }

when i refresh the page, new session id show. This is weird because it won't happen in Asp.net for dotnet framework 1.1.

To solve the problem, simply add below code in global.asax to register an event handler for the session start event


void Session_Start(Object sender, EventArgs e)
        {

        }


Tuesday, October 12, 2010

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Face strange error when try to print report using crystal report.

Server Error in 'xxx' Application.

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

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.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

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:



[AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]
CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options) +0
CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options) +95
CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened() +271


[Exception: Load report failed.]
CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened() +333
CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob) +894
CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename) +84
Transaction_InvoicePrint.Print() +149
Transaction_InvoicePrint.Page_Load(Object sender, EventArgs e) +5
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627



I'm not sure what could cause this issue but after i reset iis, everything work fine.

Tuesday, September 21, 2010

ASP.NET Security Vulnerability: Take Action Immediately

This is very important for those who have asp.net application running out there. Attacker can get data encrypted data in view state or web.config data if you ignore this.

Detail informations and workaround stated in Scottgu's Blog


For more others information, please refer to


Monday, September 20, 2010

Keep track download in ASP.NET

Situation:
I have a software in my web server and let visitor download for free, i wish to keep track of total download and visitor location. 

Feasibility:
For the location keep tracking, i use GeoIP (GeoLiteCity.dat) http://www.maxmind.com/app/ip-location 

Solution:

Database:
I have create a table called downloadlog with field below. I plan to have different type of product in future, so i add ProductFamilyID field. If you don't have that, you can ignore it.















Now, i need a stored procedure called psp_DownloadLog_Add that insert data into table above. The code should be as simple as possible



CREATE PROCEDURE [dbo].[psp_DownloadLog_Add]
(
@p_IP NVARCHAR(50),
@p_Country NVARCHAR(255),
@p_CountryCode VARCHAR(50),
@p_City NVARCHAR(255),
@p_ReferrerURL        NVARCHAR(512),
@p_ProductFamilyID INT
)
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO tblDownloadLog
(
IP,
Country,
CountryCode,
City,
ProductFamilyID,
ReferrerURL,
DownloadDate
)
VALUES
(
@p_IP,
@p_Country,
@p_CountryCode,
@p_City,
@p_ProductFamilyID,
@p_ReferrerURL,
GETDATE()
)

SET NOCOUNT OFF;

END

ASP.NET

To make the system more structural and manageable, I have create 2 classes to handle the download log. DownloadLogInfo class mainly is use the deal with the information that need to log into database. DownloadLog class is mainly the class who do the communication with the database. Please check the code below.

DownloadLogInfo class



 public sealed class DownloadLogInfo
    {
         public DownloadLogInfo() { }
        
         int _downloadID = 0;
         string _ip = "";
         string _country = "";
         string _countryCode = "";
         string _city = "";
         int _productFamilyID = 0;
         string _referrerURL = "";
         DateTime _downloadDate = DateTime.Now;


         public int DownloadID { get { return _downloadID; } set { _downloadID = value; } }
         public string IP { get { return _ip; } set { _ip = value; } }
         public string Country { get { return _country; } set { _country = value; } }
         public string CountryCode { get { return _countryCode; } set { _countryCode = value; } }
         public string City { get { return _city; } set { _city = value; } }
         public int ProductFamilyID { get { return _productFamilyID; } set { _productFamilyID = value; } }
         public string ReferrerURL { get { return _referrerURL; } set { _referrerURL = value; } }
         public DateTime DownloadDate { get { return _downloadDate; } set { _downloadDate = value; } }

         public DownloadLogInfo(int pDownloadID, string pIP, string pCountry, string pCountryCode, string pCity, int pProductFamilyID, string pReferrerURL, DateTime pDownloadDate)
         {
             _downloadID = pDownloadID;
             _ip = pIP;
             _country = pCountry;
             _countryCode = pCountryCode;
             _city = pCity;
             _productFamilyID = pProductFamilyID;
             _referrerURL = pReferrerURL;
             _downloadDate = pDownloadDate;

         }


    }

DownloadLog Class

    public sealed class DownloadLog
    {
        public void Add(DownloadLogInfo pInfo, string pConnectionString)
        {
            SpParamInfo[] myParamInfo = new SpParamInfo[6];
            myParamInfo[0] = new SpParamInfo("@p_IP", SqlDbType.NVarChar, pInfo.IP);
            myParamInfo[1] = new SpParamInfo("@p_Country", SqlDbType.NVarChar, pInfo.Country);
            myParamInfo[2] = new SpParamInfo("@p_CountryCode", SqlDbType.NVarChar, pInfo.CountryCode);
            myParamInfo[3] = new SpParamInfo("@p_City", SqlDbType.NVarChar, pInfo.City);
            myParamInfo[4] = new SpParamInfo("@p_ProductFamilyID", SqlDbType.Int, pInfo.ProductFamilyID);
            myParamInfo[5] = new SpParamInfo("@p_ReferrerURL", SqlDbType.NVarChar, pInfo.ReferrerURL);

            DbAdapter myDbAdapter = new DbAdapter(pConnectionString);
            myDbAdapter.ExecuteNonQuery("psp_DownloadLog_Add", myParamInfo);

            myDbAdapter.Dispose();

        }

    }

Now, I have create a page, call download.aspx. This page will actually get information from the visitor and insert into database. After that it will force a file to be downloaded. Before that, i already GeoLiteCity.dat file and put into my App_Data folder.


Code behind for download.aspx


protected void Page_Load(object sender, EventArgs e)
    {
        string VisitorReferrer;

        // Full path to GeoLiteCity.dat file
        string FullDBPath = Server.MapPath("~/App_Data/GeoLiteCity.dat");
        // Visitor's IP address
        string VisitorIP; 
            
        VisitorIP  = Request.ServerVariables["REMOTE_ADDR"];
      
        if (Request.UrlReferrer != null)
        {
            VisitorReferrer = Request.UrlReferrer.ToString();
        }
        else
        {
            VisitorReferrer = "";
        }

        // Create objects needed for geo targeting
        Geotargeting.LookupService ls = new Geotargeting.LookupService(FullDBPath, Geotargeting.LookupService.GEOIP_STANDARD);
        Geotargeting.Location visitorLocation = ls.getLocation(VisitorIP);
        
        DownloadLog myDownloadLog = new DownloadLog();
        DownloadLogInfo myDownloadLogInfo = new DownloadLogInfo();


        if (visitorLocation != null) // get the geoip information using visitor IP address
        {
            myDownloadLogInfo.Country = visitorLocation.countryName;
            myDownloadLogInfo.CountryCode = visitorLocation.countryCode;
            myDownloadLogInfo.City = "unknown";
            if (visitorLocation.city != null)
            {
                myDownloadLogInfo.City = visitorLocation.city;
            }
            
            myDownloadLogInfo.IP = VisitorIP;
            myDownloadLogInfo.ProductFamilyID = 1;
            myDownloadLogInfo.ReferrerURL = VisitorReferrer;
        }
        else
        {
            string country = "unknown";
            string countryCode = "unknown";
            string city = "unknown";
            myDownloadLogInfo.Country = country;
            myDownloadLogInfo.CountryCode = countryCode;
            myDownloadLogInfo.City = city;
            myDownloadLogInfo.IP = VisitorIP;
            myDownloadLogInfo.ProductFamilyID = 1;
            myDownloadLogInfo.ReferrerURL = VisitorReferrer;
        }

       
       // WebConfig.Connection is the connection the database and insert data into database
       myDownloadLog.Add(myDownloadLogInfo, WebConfig.Connection);
        
       Response.ContentType = "application/zip";
       Response.AddHeader("content-disposition", "attachment; filename=softwaresetup.zip");

       FileStream sourceFile = new FileStream(@"C:\inetpub\dotnetfish\software\softwaresetup.zip", FileMode.Open);
        
       long FileSize;
       FileSize = sourceFile.Length;
       byte[] getContent = new byte[(int)FileSize];
       sourceFile.Read(getContent, 0, (int)sourceFile.Length);
       sourceFile.Close();

       Response.BinaryWrite(getContent);
    }

Tuesday, September 14, 2010

Attempted to read or write protected memory. This is often an indication that other memory has been corrupted.


Hit below error when deploy a new app to existing running application.

Attempted to read or write protected memory. This is often an indication that other memory has been corrupted. 
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.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory has been corrupted. 



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.


Try to set the folder permission but still hit the same error after restart iis. 


Next, i try to run the permissions wizard in the IIS. After run it, restart iis and i'm lucky. It work like normal.








Hope this help.



Monday, March 29, 2010

Failed to access IIS metabase. An unhandled exception occurred during the execution of the current web request. Please review the stack ...

Hit below error when try to setup and new application in IIS.

Server Error in '/encelabs' Application.

--------------------------------------------------------------------------------

Failed to access IIS metabase.

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.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase.

The process account used to run ASP.NET must have read access to the IIS metabase (e.g. IIS://servername/W3SVC). For information on modifying metabase permissions, please see http://support.microsoft.com/?kbid=267904.

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:

[HostingEnvironmentException: Failed to access IIS metabase.]
System.Web.Configuration.MetabaseServerConfig.MapPathCaching(String siteID, VirtualPath path) +3492170
System.Web.Configuration.MetabaseServerConfig.System.Web.Configuration.IConfigMapPath.MapPath(String siteID, VirtualPath vpath) +9
System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) +163
System.Web.CachedPathData.GetConfigPathData(String configPath) +382
System.Web.CachedPathData.GetConfigPathData(String configPath) +243
System.Web.CachedPathData.GetApplicationPathData() +68
System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath, Boolean permitPathsOutsideApp) +3385679
System.Web.Configuration.RuntimeConfig.GetLKGRuntimeConfig(VirtualPath path) +189


Version Information: Microsoft .NET Framework

________________________________________________________

Solution:
For my case, the reason hit above error is because.NET Framework was installed before IIS server. To solve the problem, register .NET framework to IIS will do.

How to do that? (please be aware that the sample using for.NET Framework V1.0)

Steps:

1. Click on Start -> Run






2. Type in cmd and click OK





3. Command prompt screen will appear. go to"C:\Windows\Microsoft.NET\Framework\
v2.0.50727" folder by using command cd C:\Windows\Microsoft.NET\Framework\v2.0.50727 and hit enter. Please refer screen below:





4. Type in
aspnet_regiis -i and hit enter.




5. Screen below will be shown and dotnet user installed.




aspnet_regiis -i

alternatively you can copy and paste this command into windows command prompt

%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i

Thursday, March 25, 2010

Could not load file or assembly 'CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependenci

Deploy a web application that uses crystal report basic 10.5 and hit below error when try to access to the application.

"Could not load file or assembly 'CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified."

This is because we dont have crystal report basic runtime installed in the server.

Where do I get the basic (10.5) runtime? It's on your machine:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\CrystalReports10_5

My server is a 32 bit machine, so i install CRRedist2008_x86.msi in the machine.

Now what? I still can the same error? Wait, we need to restart the IIS to make it work. After restart the IIS, it's work perfectly.

Sunday, March 21, 2010

Parser Error Message: Section or group name 'system.web.extensions' is already defined.

facing below error in my development machine when i try to access to one of my application that running in ASP.NET framework 2.0

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: Section or group name 'system.web.extensions' is already defined. Updates to this may only occur at the configuration level where it is defined.

Source Error:

Line 2:   Line 3:    Line 4:     Line 5:      Line 6:      

Source File: C:\Inetpub\wwwroot\xxxxx\web.config Line: 4



Section or group name 'scripting' is already defined. Updates to this may only occur at the configuration level where it is defined. (C:\Inetpub\wwwroot\formlookup_ajax2\web.config line 5)
Section or group name 'scriptResourceHandler' is already defined. Updates to this may only occur at the configuration level where it is defined. (C:\Inetpub\wwwroot\formlookup_ajax2\web.config line 6)
Section or group name 'webServices' is already defined. Updates to this may only occur at the configuration level where it is defined. (C:\Inetpub\wwwroot\formlookup_ajax2\web.config line 7)
Section or group name 'jsonSerialization' is already defined. Updates to this may only occur at the configuration level where it is defined. (C:\Inetpub\wwwroot\formlookup_ajax2\web.config line 8)
Section or group name 'profileService' is already defined. Updates to this may only occur at the configuration level where it is defined. (C:\Inetpub\wwwroot\formlookup_ajax2\web.config line 9)
Section or group name 'authenticationService' is already defined. Updates to this may only occur at the configuration level where it is defined. (C:\Inetpub\wwwroot\formlookup_ajax2\web.config line 10)


Situation:

In My IIS setting
My Default Web Site Location path point to an application that running asp.net framework 3.5
When i access to one of my application that park under Default Web Site that running in asp.net framework 2.0, it hits error above.

Solution:
Remove the Default Web Site Location path solve my problem.

Monday, March 15, 2010

Exception Details: System.UnauthorizedAccessException: Access to the path C:\xx\aa.xml is denied. ASP.NET is not authorized to access the requested re

Access to the path 'C:\xxx\aa.xml' is denied.

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.UnauthorizedAccessException: Access to the path 'C:\xxx\aa.xml' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

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:

[UnauthorizedAccessException: Access to the path 'C:\xxx\aa.xml' is denied.]    System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +651    System.IO.File.Delete(String path) +157    Admin_PropertyEdit.GenerateXML(Int64 pPropertyID, String pPropertyTypeName) +124    Admin_PropertyEdit.btnRemove_Click(Object sender, EventArgs e) +248    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107    System.Web.UI.WebControls.Button.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 

Hit above error when trying to write a xml file in the web server. I've tried to set write permission for both internet guest user & also ASP.NET user but still the same.

Finally, i add into web.config and the problem solve.
<identity impersonate="true"/>

syntax

<configuration>
<system.web>
<identity impersonate="true"/>
</system.web>
</configuration >



I'm not sure why, to know more, please check on

http://msdn.microsoft.com/en-us/library/72wdk8cc.aspx



Thursday, November 12, 2009

Method not found: 'Void System.Web.UI.ScriptManager.RegisterStartupScript

Deploy a running web application from one windows 2003 server to another windows 2003 server. The application is running asp.net 2.0 framework with Ajax.net v1, MSSQL 2005.
After deploy everything and run the application, Error message

Method not found: 'Void System.Web.UI.ScriptManager.RegisterStartupScript(System.Web.UI.Page, System.Type, System.String, System.String, Boolean)'

Situation:
In the bin folder, we deploy together with
AjaxControlToolkit.dll
AjaxControlToolkit.pdb
System.Web.Extensions.Design.dll
System.Web.Extensions.dll

After look around and found that the server already installed with the same version but the strange thing is the file size are different from the one i have in bin folder. The first thing can thought of is reinstall the ajax.net.

No luck, after the ajax.net reinstallation, it's not work. Still the same error message:

Method not found: 'Void System.Web.UI.ScriptManager.RegisterStartupScript(System.Web.UI.Page, System.Type, System.String, System.String, Boolean)'

Try to delete all 4 dlls
AjaxControlToolkit.dll
AjaxControlToolkit.pdb
System.Web.Extensions.Design.dll
System.Web.Extensions.dll
from the bin folder but still same error show. So, i undo the deletion.

Try to google around and look for useful suggestion but no luck. All post stated that working after the ajax.net re installation.

Finally, i uninstall the ajax.net from the server and let the application use the 4 dlls
AjaxControlToolkit.dll
AjaxControlToolkit.pdb
System.Web.Extensions.Design.dll
System.Web.Extensions.dll
in the bin files.

It solve my problem.

Hope this sharing helps.

Thursday, September 3, 2009

The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use .. pool

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool.
This may have occurred because all pooled connections were in use and max pool size was reached.

My web app written is ASP.NET C# and database use MySQL.

To solve it. Close all your connection each time you have finishing your query.

Monday, August 24, 2009

Sys.WebForms.PageRequestManagerServerErrorException: an unknow error occured while processing the request on the server. ..status code returned .. 500

My situation:
Environment: ASP.NET, AJAX.NET and MySQL DB

I got error return when using one of the form written in AJAX.NET when calling MySQL Stored Procedure

Sys.WebForms.PageRequestManagerServerErrorException: an unknow error occured while processing the request on the server. the status code returned from the server was: 500



Well, after check around i found out that the problem is in the MySQL Stored Procedure case sensitive issue. Change the case and problem solved!

Tuesday, May 19, 2009

MySql.Data.MySqlClient.MySqlException: Table 'xxx.xx_XxxxXxx' doesn't exist

Hit error when try to connect to MySQL in Linux from ASP.NET in IIS6. Seriously, the table is 100% Exist in the database but i hit error below:

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: MySql.Data.MySqlClient.MySqlException: Table 'xxx. xx_XxxxXxx' doesn't exist




Well, finally find out that it caused by case sensitive on the table name. After i've change the name, it's work perfectly.


Monday, May 18, 2009

Access denied for user 'xxxx'@'xxx.xxx.xxx.xxx' (using password: YES)

Well, my scenario is connecting my ASP.NET 2.0 apps from IIS6 (window 2003 server) to MySQL (Linux) using ADO.NET Connector.

Hit error message when try to connect:
Access denied for user 'userxxx'@'xxx.xxx.xxx.xxx' (using password: YES)



It's quite worry because this is first time trying to connect from a .net web application is IIS to MySQL in Linux.

Prior to that, privileges must be granted in MySQL.
______________________________________________
mysql> grant all privileges on *.* to 'userxxx'@'xxx.xxx.xxx.xxx'
identified by 'xxxpasswordxxx' with grant option;
Query OK, 0 rows affected (0.00 sec)
______________________________________________

Finally, found that it's my own mistake. I've put in the wrong username and password. Check your username and password seriously before the connection.

Sunday, August 17, 2008

Thank You

Thanks For your support!

Tuesday, August 12, 2008

ASP.NET: colon in querystring cause error "is not a valid virtual path."

Server Error in '/' Application.
'~/Search.aspx?pageidx=1&Id=:' is not a valid virtual path.


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.Web.HttpException: '~/Search.aspx?pageidx=1&Id=:' is not a valid virtual path.


Understand that in asp.net, virtual path in the URL with colon (:) is not allowed. To solve this problem, i replace the colon (:) with ASCII value for colon &#58; (please check http://www.asciitable.com/) and HttpUtility.UrlEncode on the search key before pass into search.aspx as querystring.

In Search.aspx.cs, do HttpUtility.UrlDecode and pass to DB for searching purposes. Problem solve. Bear in mind that you might need to disable the ValidateRequest (ValidateRequest="false") which may open for dangerous hijack/request.

Monday, August 11, 2008

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Server Error in '/xxxxx' Application.

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.            

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: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Source Error:

Line 89: <%# if (Eval("UserId").ToString().Length != 0) {%>


googling around and not able to find a solution. What i do is i put the if/else condition into a function and pass in UserId as parameter and output the desire output string.

now my line 89: become <%# FormatRatedDisplay(Eval("UserId").ToString())%> and new function FormatRatedDisplay will return a string. I issue solved.

Monday, July 7, 2008

Retrieve data from DataTable

I have a DataTable that containing set of data. To get only column name "score" from the DataTable called MyDataTable. Below is how i do

for (int i = 0; i < MyDataTable.Rows.Count; i++)

{

string score = MyDataTable.Rows[i]["score"].ToString();

xxxxxx

xxxxxx

}

Thursday, July 3, 2008

W3SVC Restart when changing ASP.NET version in ASP.NET tab (IIS)

I'm not sure what is happening but i suspect that i change the ASP.NET version in IIS cause W3SVC restart. All application in the same application pool working ok and restart successfully but other application pull have some issue.

If anyone face the same or similar issue, maybe can share your solution.

Monday, June 30, 2008

C# String.Format - Input string was not in a correct format Error

Error message: Input string was not in a correct format Error when i try to use String.Format in C#.

below are the code that have problem

info = string.Format("{\"name\":\"{0}\",\"img\":\"{1}\",\"href\":\"{2}\"}", Username, PhotoUrl, UserId);

try to figure out here and there and finally found the problem and solution. It's caused by both { and }.

To solve this problem, change
{ to {{ and } to }}. It will become

info = string.Format("{{\"name\":\"{0}\",\"img\":\"{1}\",\"href\":\"{2}\"}}", Username, PhotoUrl, UserId);

problem solved!