Jack @ ASP.NET

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘Web’

asp.net error: Operation is not valid due to the current state of the object

ASP.NET requests that have lots of form keys, files, or JSON payload receive an error response from the server. The Application log on the server has a Warning entry with a Source that is a specific version of ASP.NET, and an Event ID of 1309. The event log contains one of the following messages:

Message 1:

Application information:
    Application domain: /LM/W3SVC/1/ROOT/<App Domain>
    Trust level: Medium
    Application Virtual Path: <VDIR Path>
    Application Path: <App Path>
    Machine name: <Machine Name>
Process information:
    Process ID: 0001
    Process name: w3wp.exe
    Account name: IIS APPPOOL\DefaultAppPool
Exception information:
    Exception type: HttpException
    Exception message: The URL-encoded form data is not valid.
   at System.Web.HttpRequest.FillInFormCollection()
   at System.Web.HttpRequest.get_Form()
   at System.Web.HttpRequest.get_HasForm()
   at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
   at System.Web.UI.Page.DeterminePostBackMode()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


Message 2:

Application information:
    Application domain: /LM/W3SVC/1/ROOT/<App Domain>
    Trust level: Medium
    Application Virtual Path: <VDIR Path>
    Application Path: <App Path>
    Machine name: <Machine Name>
Process information:
    Process ID: 0001
    Process name: w3wp.exe
    Account name: IIS APPPOOL\DefaultAppPool
Exception information:
   Exception type: InvalidOperationException
    Exception message: Operation is not valid due to the current state of the object.
   at System.Web.HttpRequest.FillInFilesCollection()
   at System.Web.HttpRequest.get_Files()
   at FileUpload.Page_Load(Object sender, EventArgs e)
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint

 

to resolve this problem, you should change your web.config

<configuration>
  <appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="5000" />
  </appSettings>
</configuration>

Try Expression Web 4 now

Microsoft Expression Web 4 is a professional development and design tool to create modern, standards-based Web sites that use PHP, HTML/XHTML, CSS, JavaScript, ASP.NET or ASP.NET AJAX.
The highlight including:

  • Create standards-based Web sites faster & easier
  • Professional code editor & design surface
  • Make your site stand out with rich graphics support
  • Work with leading industry-standard technologies

What’s new in Expression Web

SuperPreview online service

The Microsoft Expression Web SuperPreview online service is a beta service that extends the capability of SuperPreview to include support for additional browsers and operating systems.

SEO Checker

The SEO Checker feature of Expression Web analyzes your site against the best practices for getting the highest possible search-engine rankings for your site.

You can choose SEO options, display an SEO report, filter the results in the SEO report, and step forward and back through the list of results in the SEO report to see more detail for individual list items.

You can try the 60-day free trail at http://www.microsoft.com/downloads/details.aspx?FamilyID=7b10272b-2f96-4250-aede-3fcfadf26f34

Upgrade or Uninstall of Office 2007 might cause VS 2008 Web designer to hang

On machines with a 64-bit OS, uninstall of Office 2007 will break the VS 2008 web designer.  You will find that the VS designer won’t be able to load, and any attempts to switch to Design View will hang the product.  Note that 32-bit machines are not affected and neither are other VS releases.

The root cause of this problem is that Office 2007 and the VS 2008 web designer both share a component, 32-bit MSXML5.  When Office 2007 uninstalls or gets upgraded, MSXML5 is removed yet Visual Studio still needs it.

If you are affected by this issue, there are workarounds where you may not have to completely reinstall Visual Studio.  However, the steps are different depending on how Office 2007 got removed (uninstall vs. upgrade to Office 2010) and also if you have VWD Express or a full product.

Workaround if you manually uninstalled Office 2007 (i.e. Add/Remove Programs) AND have a non-Express version of VS 2008:

  1. Go to Add/Remove Programs
  2. Uninstall “Microsoft Visual Studio Web Authoring Component
  3. Reinstall “Microsoft Visual Studio Web Authoring Component” -
    • You will need the VS install media: the product DVD or mount an ISO image
    • Go to WCU\WebDesignerCore folder and run WebDesignerCore.exe.
    • Setup does not have UI, so please simply wait about 5 minutes or watch msiexec activity in the Task Manager.
    • Verify that Microsoft Visual Studio Web Authoring Component reappears in Add/Remove Programs.
    • WebDesignerCore.exe installs RTM version.
  4. If your VS 2008 has been updated to SP1, you have to reinstall SP1 to update the Web Authoring Component you installed in Step 3.

Workaround if you manually uninstalled Office 2007 (i.e. Add/Remove Programs) AND have Visual Web Developer Express 2008:

  1. Go to Add/Remove Programs  
  2. Uninstall “Microsoft Visual Studio Web Authoring Component
  3. Reinstall Visual Web Developer Express 2008/SP1
    (SP1 for Express is not a separate install thus the need to reinstall the entire product)

Interview Questions on asp.net

  • Whats MSIL, and why should my developers need an appreciation of it if at all? MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL. asp.net-design-logo
  • Which method do you invoke on the DataAdapter control to load your generated dataset with data? The .Fill() method
  • Can you edit data in the Repeater control? No, it just reads the information from its data source
  • What base class do all Web Forms inherit from? The Page class.
  • Name two properties common in every validation control? ControlToValidate property and Text property.
  • What tags do you need to add within the asp:datagrid tags to bind columns manually? Set AutoGenerateColumns Property to false on the datagrid tag
  • How can you provide an alternating color scheme in a Repeater control? Use the AlternatingItemTemplate
  • What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control? You must set the DataSource property and call the DataBind method.
  • What tag do you use to add a hyperlink column to the DataGrid? <asp:HyperLinkColumn>
  • What is the transport protocol you use to call a Web service? SOAP is the preferred protocol.
  • True or False: A Web service can only be written in .NET? False
  • What does WSDL stand for? (Web Services Description Language)
  • Explain what a diffgram is, and a good use for one? The DiffGram is one of the two XML formats that you can use to render DataSet object contents to XML. For reading database data to an XML file to be sent to a Web Service.
  • Which template must you provide, in order to display data in a Repeater control? ItemTemplate
  • Convert a Web Site Project to a Web Application Project

    Open and Verify your Visual Studio Web Site Project
    Before converting your WSP to a WAP, you should open it in Visual Studio and verify that is it working correctly.  This will help prevent the need to research errors that have nothing to do with the conversion process.

    1. In the File menu, click Open Web Site.
    2. The Open Web Site dialog box is displayed.
    3. Select the project folder that you want to open, and then click Open.
    4. In the Build menu, click Build Web Site.
    5. In the Debug menu, click Start Debugging. Alternatively, you can press F5.
    6. Verify your project compiles and runs as expected

    Create a new, empty Visual Studio WAP
    A good strategy for converting a WSP to a WAP is to create a new, blank Visual Studio Web Application Project in a separate directory, but in the same solution. This avoids changing any part of the existing Web site files. It also allows you to copy existing functionality and files into the new WAP easily, within the same Visual Studio instance.

    1. In the File menu, click Add, and then click New Project.
    2. The Add New Project dialog box is displayed.
    3. In the Installed Templates section of the Add New Project dialog box, expand the language that you want to use, and then select Web to display the Web-related templates.
    4. Select Empty ASP.NET Web Application.
    5. Type values for Name, Location, and then click OK to create the Web Application Project.
    6. After the project has been created, delete the Web.config file that is created automatically.

    WSPandWAP

    Set Project / Assembly References
    If the WSP required additional project or assembly references, you need to add them to the WAP. You can see the list of default references associated with the new (empty) Visual Studio Web Application Project under the References node in Solution Explorer.

    1. In the Solution Explorer, make sure Show All Files is turned on.
    2. In the Solution Explorer, right-click References, and then click Add Reference.
    3. The Add Reference dialog box is displayed.
    4. Select the reference that you have already added in the Web Site Project and then click OK.
    5. Note: To help prevent errors, add references to the Web Application Project for assemblies that existed in the \bin folder of the WSP.

    AddRef

    Copy and Convert the App_Code folder from the Web Site Project to the Web Application Project
    In WSPs, the files in the App_Code folder are all compiled together and then referenced (automatically) as a “dll” by all other files in the WSP. In WAPs, this is not the case. All code is compiled together as one .dll. I’ve found that copying the App_Code folder over first and converting it to the WAP model helps to head off some dependency issues which could arise if one copied the entire site, converted, and then tried to compile.

    1. In the Solution Explorer, copy the entire App_Code folder from the WSP to the WAP
    2. In the Solution Explorer, select the WAP’s root node; right-click, select Convert to Web Application
    3. You will see our standard Convert to Web Application confirmation dialog.  Select “Yes” to this dialog.
    4. The App_Code folder should now be renamed to Old_App_Code folder
    5. Note: Do NOT name it back. As mentioned above, in the WAP model all code will be compiled into one assembly. At runtime, ASP.NET doesn’t know what type of project model you have created and will take anything in the “App_Code” folder and create a dynamic assembly for it, thereby causing “could not load type” exceptions as there would be duplicate types exists in two assemblies (the one for the VS web application and the one for App_Code).  Learn more about why App_Code folder does not work well with WAPs.
    6. Compile the WAP
    7. If you see an error, the most likely causes are:
      1. Missing assembly reference. See the section above to add missing references to your project.
      2. Files marked with Build Action = Content instead of Build Action = Compile. Any file you want compiled should be marked as such.
      3. To set the Build Action property:
        1. Select the file in the Solution Explorer
        2. Press F4 (Brings up the File’s Property Grid)
        3. Look at the Build Action property. Change as necessary.

    converttowap

    Copy and Convert the remaining Files and Folders from the WSP to the WAP
    Once your Old_App_Code folder is compiled (by compiling your WAP in the step above), your WAP will have an assembly in the \bin directory. This will make it easier for the remaining files you are copying over to successfully compile, especially if they reference or use code in the files contained within that folder.

    1. Select the remaining files / folders from the WSP project and copy them into the WAP.
    2. Make sure not to copy the App_Code folder again.
    3. In the Solution Explorer, right click the root node of the WAP and select Convert to Web Application.
      1. Don’t worry, this won’t affect (or try to reconvert) any files or the Old_App_Code folder you have already converted.
    4. Note: This will cause VS to automatically generate a .designer.cs (or .vb) file for each page, user-control, and master page in the project. Additionally, each .aspx/.ascx will be modified to use the ‘Codebehind’ instead of the ‘CodeFile’ attribute in the Page directive.
      1. Example of the ‘CodeFile’ to ‘Codebehind’ change
        1. WSP file:  <%@ Page Title=”Home Page” Language=”C#” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
        2. Converted WAP file:  <%@ Page Title=”Home Page” Language=”C#” Inherits=”_Default” Codebehind=”Default.aspx.cs” %>

    convertedfiles

    Compile your WAP
    After all the files have been added and converted, you should build your project again to see if there are any compilation errors. At this point, some of the most likely causes of errors are:

    1. Code files set with Build Action = Content. These should be changed to Compile. Refer to the above section.
    2. Missing project or assembly references. See above for steps for adding project or assembly references.
    3. Class name collisions. In the WSP model, each .aspx and associated codefile was compiled together as a separate, individual unit. Therefore, one could have files such as foo\widget.ascx.cs and bar\widget.ascx.cs where the classes were the same. Once these files are moved to a WAP and all compiled together, class name collisions occur with errors something like, “has multiple definitions with identical signatures”. If this occurs, unique class names should be created.

    Run your WAP
    After completing the above steps and you have a WAP which successfully compiles, you are ready to try running your application. One of the most common problems I’ve seen encountered is the “Unknown server tag ‘SomeTag: Control’ (as it applies to user controls and such)”. This can be corrected in one of two ways.

    1. Add or modify the register directive on the page that is using the control. This will only register it for this specific page.
      1. <%@ Register Namespace”namespace the control is in” TagPrefix=”SomeTag” Assembly=”Name of dll compiled into the \bin folder” %>
    2. Register the control in the Web.config, making it available to all pages in the project
      1. In the <pages><controls> section add the following:
      2. <add tagPrefix=”SomeTag” namespace=”namespace the control is in” assembly=” Name of dll compiled into the \bin folder” />