Thursday, April 21, 2011

ASP.NET Request.Url is repeating the URL 3 times

I have a HttpHandler that is called whenever an image extension is accessed. This is what I have in the HttpHandler as a simple test:

public void ProcessRequest(HttpContext context)
{    
    context.Response.Write(context.Request.Url.ToString());
    context.Response.End();
}

According to Firebug, the first time the page is refreshed (Ctrl+F5), the URL is shown correctly in the response. However, if I refresh it again (F5), it'll repeat the URL 3 times:

First time:

http://server/image.jpg

Subsequent times:

http://server/image.jpghttp://server/image.jpghttp://server/image.jpg

Does anyone know why this is happening?

From stackoverflow
  • I tried your code and refresh page in different browsers and there is no repeating URL.

    Daniel T. : Turns out I set the wrong ContentType (it was setting it as `image.png?width=250`). Dunno why this would produce 3 times the request URL on a refresh though.

Removing printer marks from a PDF file

Hi,

I need to remove the printer marks from the PDF file. I am using Acrobat 9 Professional to open the PDF. But there is no option of removing the printer marks although there is option to add new printer marks.

I googled and found that there is a third party plugin "Enfocus PitStop" which when installed is added to Adobe Acrobat and provide an option to remove the print marks. But that software is quite costly.

Is there any way I can remove the printer marks programatically or through the Adobe Acrobat 9.0?

Thanks, Praveen

From stackoverflow
  • If you mean registration watermarks, either you have to crack the software (which I am not telling you to do) or you have to buy it. Usually, free pdf writers/editors include a watermark unless you buy the product. If however you wanted a free pdf printer, try CutePDF. I at least think this is what you are asking about.

  • In Acrobat Professional, go to Document > Crop Pages and select "Trim Box" from the dropdown menu. If the document doesn't have this dimension built in, you can also manually enter it.

    You can also edit PDFs in Adobe Illustrator, if available.

Best practice of data validation in enterprise application

Hi, All.

I'm studying e-Commerce like web application. In one case study, I’m in trouble of mass data validation. What is the best practice of that in enterprise application? Thanks!

Here is one scenario: For a cargo system. There is a “Cargo” object, which contains a list of “Good” to be shipped with. Each “Good” have a string field, named “Category”, specifying what kind of “Good” it is. Such as “inflammable”, “Fragile”.

So, there are two chances for the validation to take place. The creation of the object. Or the storage in the database of the object. If we only validate at the storage stage, when some “Good” validation fails, the “Cargo” storage fails too, and the previously stored “Goods” need to be deleted. This is low efficient. If we also validate at the creation stage. There will be duplicated validation logic(a check of foreign key as I stores those “Category” in the database, and a check in the constructor).

From stackoverflow
  • If you are saving multiple records to the database, all the updates should be done at once in a single transaction. So you would validate ALL the objects before saving. If there was an issue during the save you could then rollback the transaction which rolls back all the database updates (ie you dont have to go back and manually delete records)

    Ideally you should validate on the server, before saving data, the server validation should then propagate the validation messages back up to the User/UI. Validation on the Client/UI is also good in that its more responsive and reduces the overhead on the rest of the system.

    Roy : Reaaly thanks! Mark.
    er4z0r : Look for OWASP Web-Develpment Guidelinse. There you will find agreed upon guidelines on topics like validation, access control etc.

Programatically creating nested repeater control

Hello I have dynamically created repeater control as per the msdn article below http://msdn.microsoft.com/en-us/library/0e39s2ck.aspx

I am gerenerating the control in tap panel.

How do I create nested repeater dynamically.

Please help. I know how to create in the aspx page but I want to know how I cna create a nested repeater programatically.

thanks

From stackoverflow

Single Sign 0n between DotNetNuke, Classic ASP app, ASP.NET app

We run multiple apps to provide services to our members at our organization 1. DotNetNuke as CMS 2. Classic ASP custom app for membership management and event management 3. ASP.NET app for providing online learning 4. Wordpress blog

Can somebody please suggest a way to enable Single Sign On in this kind of an environment.

I am looking for a solution which would enable adding any kind of application easily to the SSO in the future.

We host most of the apps, but there are some being hosted outside our environment as well.

All members are customers in different locations.

THanks

From stackoverflow

overriding JTree double-click to prevent node expansion?

It looks like there are 2 default mechanisms to expand a folder node in a JTree. One is to click on the expanded/collapsed icon next to a node. The other way is to double-click on the node itself.

Is there a way to stop this 2nd mechanism? I would like to override the double-click on a node so it does something (updates another display to show statistics on the node being double-clicked), and would like it to not expand/collapse the tree node. (just to be clear: I don't want to prevent the node from being expanded/collapsed, I just want to require the user to click on the expanded/collapsed icon.) How can I do this?

From stackoverflow
  • From the relevant API page, you would do something like this:

    JTree tree = new JTree();
    tree.setToggleClickCount(0);
    

    This means you must use 0 clicks to expand a tree node, effectively disabling double click. This will not interfere with other methods of tree expansion.

    Jason S : thanks !
  • Call setToggleClickCount(0) on the JTree

    This will effectively disable expanding on double-click.

Wednesday, April 20, 2011

'JQuery' is undefined

I am working on a ASP.net project created with local file system settings. I am using MVC and Jquery. Jquery is working fine when I run the application in debug mode i.e. in ASP.net Development server. I am trying to host the application in IIS 7. In hosted mode, it does not recognize Jquery and gives scripting error 'Jquery is undefined'. The locations of the script files is unchanged in both modes. Can anybody have any clue what can be the reason and how to solve this.

My code look like this;

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script src="../../Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>

<script src="../../Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>

<script src="../../Scripts/jquery-1.2.6.js" type="text/javascript"></script>

<!-- YUI Styles -->
<link href="../../Content/reset.css" rel="stylesheet" type="text/css" />
<link href="../../Content/fonts.css" rel="stylesheet" type="text/css" />
<link href="../../Content/grids.css" rel="stylesheet" type="text/css" />
<!-- /YUI Styles -->
<link href="../../Content/knowledgebase.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
    //this hides the javascript warning if javascript is enabled
    (function($) {
        $(document).ready(function() {
            $('#jswarning').hide();
        });
    })(jQuery);
</script>

<asp:ContentPlaceHolder ID="ScriptContent" runat="server" />

....

From stackoverflow
  • This usually occurs when you have malformed HTML or JavaScript.

  • If there's no errors in your javascript (eg: missing brackets), then it's either not including the jQuery file, or you're trying to run some code which relies on jQuery before that file has loaded.

    Raja : How came its working fine on Asp.net application server
  • Try using Firebug 'Net' tab to see if the file gets loaded.

    You can also configure Firebug to fail on all errors and see when the error happens as compared to when jQuery gets loaded.

    MrBoJangles : I did what you said. I neglected to add the latest jQuery to the project. Thanks!
  • Jquery?!
    You mean jQuery?

    Javascript is case-sensitive. Jquery is not the same as jQuery.

    Raja : its JQuery is undefined. The case is fine and its working on ASP.net application server.
    EndangeredMassa : The case should be "jQuery" not "JQuery". But if it works on test, this isn't the issue.
  • For me, this error typically occurs when there is a true Javascript error in some of my code. This prevents the jQuery.js file from being fully parsed. Look in the Error Console in Firebug, Safari or another debugging-friendly browser.

  • After Using the FIrebug, I found out the files were not found as the relative path for the files doesn;t work. TO resolve the problem, we should use the Url.Content Method to reslove the path. For example:

    <script src="<%= Url.Content("~/Scripts/jquery-1.2.6.js")%>" type="text/javascript"></script>
    
    Pim Jager : You should encode the opening character for the script tag in this character from < to <
    Will Dean : It would be good to mark Andrey's answer as accepted...
    Kip : Why didn't the relative path work though? Care to explain what was different?
  • You could also try letting Google host jQuery for you:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
    

    This will avoid having to worry about the relative path to the script, avoid load on your server, and will be faster for users (who probably already have it in their browser's cache somewhere).

  • Common mistakes is that other Jquery Scripts are included first(Jquery.validation.js) before the Jquery.js

  • Raja is right, URL.Content works.

    <script src="<%= Url.Content("~/Scripts/jquery-1.2.6.js")%>" type="text/javascript"></script>
    

    Further, to prevent yourself from getting surprised at the moment you are migrating your application to an IIS server, don't use web development server but use IIS when developing.

    You can use IIS directly from visual studio by editing the the web properties:

    • Go to the tab 'Web'
    • Check 'Use Local IIS Web server'
    • Click 'Create Virtual Directory'
    • Go to the IIS Manager to disable anonymous access in the created virtual directory if applicable.
  • If all else fails, make sure the file has the right permissions set. This just happened to me!

    You can either right click the file in your directory and set the permission there, or just create another .js file in Visual Studio and copy and paste the contents over. Worked like a charm. :)

  • try

    <script src="<%= ResolveUrl("~/Scripts/jquery-1.2.6.js")%>" type="text/javascript"></script>
    
  • The path is wrong. Double check it.

  • 0 I do not know whether you guys found the solution to your problem or not. I was facing the same problem and going nuts to figure out why do I get "jQuery is undefined" error on the plugins i use. I tried all the solutions i get from the internet but no luck at all.

    But, suddenly something splash on my mind that may be the script files should be in order. So, I moved the jquery referece to first position and everything start working like charm.

    Remember guys, if you're using any plugins with jquery, make sure you use the folloing order of setting reference to those fiels.

    1.reference to the jquery library 2.reference to the other subsequent plug-in (dependant) libraries and so on...

    e.g.: 1. "script src="js/jquery-1.3.2.min.js" type="text/javascript"... 2. "script src="js/jqDnR.min.js" type="text/javascript"... 3. "script src="js/jquery.jqpopup.min.js" type="text/javascript"... 4. "script src="js/jquery.bgiframe.min.js" type="text/javascript"...

    Always make sure you must put the jquery reference to first and then the subsequent libraries.

    Hope, this solves your problem especially when you use with MasterPages. Its very strange that it works no matter what order you use when you don't use MasterPages but when you do, then it somehow requres the proper order.

    Good luck and happy coding,

    Vincent D'Souza

    John Fischer : Solved my problem. Thanks!
  • To elaborate on the "text/javascript" answer, "application/javascript" will work in firefox and load jQuery just fine. It won't, however, load the file in IE. Use "text/javascript":

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script>
    
  • To add my problem/solution to this long list...

    I was using Windows 2003 to test the site in IE7. The site came up fine but jQuery didn't run at all. So I went straight to the http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js and found that ajax.googleapis.com was not on the list of safe sites. After adding *.googleapis.com everything worked fine. Silly oversight, but maybe this will help someone else in a similar situation.

  • Vincent D'Souza's solution worked out. Thanks.

  • Vincent D'Souza,

    You are absolutely right ! The order matters ! It solved my error 'jQuery' is undefined.

    Thanks!