Sep 12 2009

Prevent URL Rewriting of Requests for ASP.NET-WebResources.axd

Category: Ajax | ASP.NETLatif @ 14:50

Hi again,

 WebResources.axd is created by ASP.NET for performing AJAX processes in the page. İn Addition, there is no such file on the web server due to the fact that ASP.NET produce the content dynamically when WebResources.axd is requested.


If you want to see the content of WebResources.axd, you have to run it on browser. Script path is in the page source code like below,


<script src="/WebResource.axd?d=7OCAQ3R3VOQC0D4ciLQ5OCpSc8_wxlQ0C-KYhGZ-_ag1&amp;t=633566872339565967" type="text/javascript"></script>


İf you are using Url Rewring, URL rewrite rule may accidentally make the requests to WebResources.axd and this will break your application.


Anyway, in order to prevent URL Rewriting of Requests for ASP.NET Web Resources(.axd) and other type of files such as .xml,.js,.css , you should add rule to web.config.


     <rewrite url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.xml|\.pdf|\.axd|\.css|\.js)(\?.+)?)$" to="$1" processing="stop" />

     <rewrite url="/([0-9]{6})(.*)/(.*)-(.*)" to="~/Detail.aspx?aid=$1" />



The problem can be easily prevented by this rule.


Have a good time...


Aug 14 2009

ASP.Net AJAX Not Working (Full page postback)

Category: Ajax | ASP.NETLatif @ 15:45


After carrying my web application to windows server 2003 R2 from windows  XP - IIS 5.1,  I have encountered a ASP.Net AJAX issue that my page is performing a full page postpage instead of a partial page postback of the expected AJAX page elements.

        I have searched everywhere, and this is the only solution I can find.  I just stumbled upon this page below and I applied what it is saying.  I would like to thank to Neil kilbride for sharing this solution with us.

Solution :

I just added to my web.config file following code to solve the problem.


        <xhtmlConformance mode="Transitional" />


 And also he says thatIf you are having ASP.Net AJAX issues I recommend removing the <xhtmlConformance> section from your web.config file or perhaps set it to Transitional or Strict.


Tags: ,

Jul 27 2009

How can I use ampersand in AppSettings value - app config file

Category: ASP.NETLatif @ 00:28


If you want to put an & (ampersand) character into the value attribute of a key in the appSettings part of the XML .config file(web.config, app.config etc.)

Let's say, you have param like following, (The error will occur if you use like this)


    <add key="MyUrl" value="http://localhost:8080/mysite/summarize?name=testPDF&format=pdf"  />


Solution : 


    <add key="MyUrl" value="http://localhost:8080/mysite/summarize?name=testPDF&amp;format=pdf"  />


use &amp; instead of &

Cause :

It is because of XML rules that the & character is the token for beginning of a reference. For more information

 tot ziens...


Tags: ,

Jul 10 2009

Debugging problem after installing Visual Studio 2008 SP1

Category: ASP.NETLatif @ 14:38


If you cannot debug after installing Visual Studio 2008 SP1, try to download and setup following link.

I encountered this problem today. After installing that hotfix, it is solved.

see you soon...

Tags: ,

Jun 19 2009

Call Crystal report from ASP.Net & Changing connectionInfo of Crystal report at runtime

Category: ASP.NET | Crystal ReportLatif @ 17:57

 Code with descriptions: file.cs



        //Get params from QueryString

        string startdate = context.Request.QueryString["StartDate"];

        string enddate = context.Request.QueryString["EndDate"];

        //Define report format

        context.Response.ContentType = "application/pdf";


        ReportDocument crReport = new ReportDocument();


        //Set the parameters

  crReport.SetParameterValue(0, startdate); //STARTDATE

        crReport.SetParameterValue(1, enddate);//ENDDATE


        //Retrieve Web.config's connection string information

        string connectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);

        string password = builder.Password;

        string username = builder.UserID;

        string dataSource = builder.DataSource;

        string initialCatalog = builder.InitialCatalog;


        //Define new connection for Crystal Report

        CrystalDecisions.Shared.ConnectionInfo connectionInfo = new CrystalDecisions.Shared.ConnectionInfo();

        connectionInfo.DatabaseName = initialCatalog;

        connectionInfo.UserID = username;

        connectionInfo.Password = password;

        connectionInfo.ServerName = dataSource;


        // set report connection for main report

        SetDBLogonForReport(connectionInfo, crReport);

        // set report connection for any subreports

        SetDBLogonForSubreports(connectionInfo, crReport);


        MemoryStream ms = (MemoryStream)crReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);




    catch (System.Threading.ThreadAbortException ex)








 You can see the functions I have used above. I found the functions from

        private void SetDBLogonForReport

          (CrystalDecisions.Shared.ConnectionInfo connectionInfo,

            ReportDocument reportDocument)



            Tables tables = reportDocument.Database.Tables;

            foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)


                TableLogOnInfo tableLogonInfo = table.LogOnInfo;

                tableLogonInfo.ConnectionInfo = connectionInfo;





        private void SetDBLogonForSubreports

          (CrystalDecisions.Shared.ConnectionInfo connectionInfo,

           ReportDocument reportDocument)


            Sections sections = reportDocument.ReportDefinition.Sections;

            foreach (Section section in sections)


                ReportObjects reportObjects = section.ReportObjects;

                foreach (ReportObject reportObject in reportObjects)


                    if (reportObject.Kind == ReportObjectKind.SubreportObject)


                        SubreportObject subreportObject = (SubreportObject)reportObject;

                        ReportDocument subReportDocument =


                        SetDBLogonForReport(connectionInfo, subReportDocument);






Tags: ,

Jun 18 2009

Retrieve individual data from ConnectionString

Category: ASP.NETLatif @ 18:04

   If you want to retrieve data(password ,UserID,DataSource,InitialCatalog) , you can use SqlConnectionStringBuilder (From .NET Framework 2.0, there is System.Data.Common.DbConnectionStringBuilder  and its derived classes (SqlConnectionStringBuilder for SqlServer))

string connectionString = WebConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);

string password = builder.Password;
string username = builder.UserID;
string dataSource = builder.DataSource;
string initialCatalog = builder.InitialCatalog;


Tags: ,

Jun 12 2009


Category: ASP.NET | LINQLatif @ 16:47

LINQ da SQL deki max islemini nasil mi yapariz?

Asagidaki sekilde,

MDDBDataContext dc = new MDDBDataContext();

var lastNumber = (from r in dc.RevenueSharings
                                  select (int?)r.StatementNumber).Max();


SQL server profiler tarafinda asagidaki sekilde goreceksiniz...

SELECT MAX([t0].[StatementNumber]) AS [value]
FROM [dbo].[RevenueSharing] AS [t0]

Tags: , , ,

Jun 11 2009

Problem with Request.Querysting and Plus Sybmol (+)

Category: ASP.NETLatif @ 08:00


Eger GET methodu ile URL den parametre geciriyorsaniz ve parametrenizde arti(+) isareti geciyor ise ASP.NET sayfaniz da bu parametreyi alirken arti(+) isaretinin boslug'a donustugunu goreceksiniz.



Seklinde bir URL iniz varsa

Sayfanizdan Request.QueryString["source"] seklinde almak istediginiz degerin "Speelgoed- -Hobby" seklin de geldigini farkedeceksiniz.

Bunun onune gecmek icin parametreyi asagidaki sekilde alabilirsiniz.

source = System.Web.HttpUtility.UrlEncode(Request.QueryString["source"]);