Tuesday, April 17, 2012

How to validate website address in javascript

gvalidate website address javascript by using Regular Expression in asp.net

Script block:
========

<script type="text/javascript">
        function ValidateWebsiteAddress() {
            var url = document.getElementById('<%=txtWebsiteAddress.ClientID %>').value;
     var urlIsValid =       ValidateWebAddress(url);      alert("Website Address is valid?:" +urlIsValid );
            return urlIsValid ;
        }
    

 function ValidateWebAddress(url) {
           var webSiteUrlExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
           if (webSiteUrlExp.test(url)) {
               return true;
           }
           else {
               return false;
           }
       }


    </script>

.aspx File
======

  <asp:TextBox runat="server" ID="txtWebsiteAddress"></asp:TextBox>
  <asp:Button runat="server" OnClientClick="return ValidateWebsiteAddress()"  Text="Validate WebsiteAddress"/>
 
Demo:
=====



Tuesday, April 10, 2012

How to read/write clipboard data in cross browser?


Copy To Clipboard (in FireFox)

clipboarddata.setdata firefox


The following script block will allows you to access clipboard in all browsers(i.e: IE, Firefox,Chrome, Safari).

    <script type="text/javascript">

  function CopyTest(copyString) {

            if (window.clipboardData) {
                //This Code block will be executed in IE(Microsoft Internet Explorer)
                window.clipboardData.setData("Text", meintext);
            }
            else if (window.netscape) {

                //Enabling Security alert and based on security alert confirmation accessing the clip board
                netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

                // Creating Instance to the Clipboard class and inheriting the "nsIClipboard" interface which is used to copy data into clip board
                var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
                if (!clip) return;

                // Creating Instance to the transferable class and inheriting the "nsITransferable" interface which is used to transfer data
                var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
                if (!trans) return;

                // Specifying content type ex:'text/unicode' or 'html'
                trans.addDataFlavor('text/unicode');

                //Creating two objects first object used to store input string and another object is used to store  length of the string
                var str = new Object();
                var len = new Object();

                // Creating Instance to the supports-string class and inheriting the "nsISupportsString" interface which is used to copy data into clip board
                var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
                str.data = copyString;
                trans.setTransferData("text/unicode", str, copyString.length * 2);
                var clipid = Components.interfaces.nsIClipboard;

                if (!clip) return false;
                clip.setData(trans, null, clipid.kGlobalClipboard);

            }
        }
</script>

Demo:


Download Clip board Data Sample

Thursday, April 5, 2012

System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.


Server Error in '/' Application.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

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:

[SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Reflection.Assembly._GetType(String name, Boolean throwOnError, Boolean ignoreCase) +0
   System.Web.UI.NamespaceTagNameToTypeMapper.GetControlType(String tagName, IDictionary attribs, Boolean throwOnError) +209
   System.Web.UI.TagPrefixTagNameToTypeMapper.System.Web.UI.ITagNameToTypeMapper.GetControlType(String tagName, IDictionary attribs) +210
   System.Web.UI.MainTagNameToTypeMapper.GetControlType2(String tagName, IDictionary attribs, Boolean fAllowHtmlTags) +242
   System.Web.UI.MainTagNameToTypeMapper.GetControlType(String tagName, IDictionary attribs, Boolean fAllowHtmlTags) +17
   System.Web.UI.RootBuilder.GetChildControlType(String tagName, IDictionary attribs) +22
   System.Web.UI.ControlBuilder.CreateChildBuilder(String filter, String tagName, IDictionary attribs, TemplateParser parser, ControlBuilder parentBuilder, String id, Int32 line, VirtualPath virtualPath, Type& childType, Boolean defaultProperty) +119
   System.Web.UI.TemplateParser.ProcessBeginTag(Match match, String inputText) +605
   System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding) +1334


Version Information: Microsoft .NET Framework Version:2.0.50727.4963; ASP.NET Version:2.0.50727.4971 



Solution:
=======

          

If your accessing virtual path from network please change the Identity to "Network Service:


The easy way out is just to go back to using Network Service as an application pool identity instead of the ApplicationPoolIdentity used by IIS 7.5. However, this undermines the new security enforcements that the IIS team has created, and kind of defeats the purpose of using IIS 7.5 as opposed to IIS 7.


If  your hosting an web application within local IIS and virtual path referenced to your local system then use "Local System" as Identity 


It will be work fine..........
 

HTTP Error 500.19 - Internal Server Error

HTTP Error 500.19 - Internal Server Error


The requested page cannot be accessed because the related configuration data for the page is invalid.

 

Detailed Error Information
ModuleIIS Web Core
NotificationBeginRequest
HandlerNot yet determined
Error Code0x80070021
Config ErrorThis configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
Config File\\?\C:\inetpub\wwwroot\TestSite\web.config
Requested URLhttp://192.168.1.5:8081/
Physical PathC:\inetpub\wwwroot\TestSite
Logon MethodNot yet determined
Logon UserNot yet determined

 

Solution: You need to enable the following features to the IIS server.  Here is one more step involved in enabling ASP.Net on your Windows Vista machine. Follow the procedure in previous article to get to Panel for Windows Program and enable the appropriate sections under Internet Information Services > World Wide Web Services > Application Development Features. If you enable ASP, ASP.Net, Server Side Includes etc., your settings may look like the following image.

IIS7 ASP.Net configuration

 

Wednesday, April 4, 2012

Could not load file or assembly ‘AjaxControlToolkit’ or one of its dependencies.

Could not load file or assembly ‘AjaxControlToolkit’ or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0×80070057 (E_INVALIDARG))

If you are working with the Ajax Control Toolkit, sometimes the AjaxControlToolkit assembly will become corrupted in your Temporary ASP.NET Files folder. Here are a set of steps that might help you get back up and running. This is only relevant to developing with the built in web server, Cassini.
But first, here is the scenario.
Last Friday, my computer crashed while I was working on a project which references the AJAX Control Toolkit assembly.
After my computer restarted, I opened the project in Visual Studio 2008. I launched the default web page and I received the following error:
Could not load file or assembly ‘AjaxControlToolkit’ or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0×80070057 (E_INVALIDARG))
I tried closing and reopening the project; I even restarted my computer, but none of these efforts were successful.
I deleted and re-added the AjaxControlToolkit assembly reference, but still no dice.
Here are the steps that I found which worked for me:
  1. Close Visual Studio
  2. Open the Temporary ASP.NET Files folder and delete its contents.
    • If the OS is Windows Vista, then the folder is%LocalAppData%\Temp\Temporary ASP.NET Files
    • If the OS is Windows XP, then the folder is%WINDIR%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
  3. Restart Visual Studio
  4. Open the project
Source: Joshua Johnson Blog