Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8210375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:03:28+00:00 2026-06-07T10:03:28+00:00

I am trying to post the data to cross domain. It works fine if

  • 0

I am trying to post the data to cross domain. It works fine if the form is not using runat=”server” and its giving 500 internal error while posting when the form is using runat=”server”.

Upon debugging, I identified that the problem is with auto generated __viewstate code on the page. Please find the below code.

Clientside HTML implementation:

<%@ Page Language="C#" CodeFile="Sample.aspx.cs" Inherits="Sample" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta charset="utf-8">
    <title>Untitled Page</title>
    <link href="FileUpload.css" rel="stylesheet" type="text/css" />

   <script id="template-upload" type="text/x-tmpl">
    </script>
    <script id="template-download" type="text/x-tmpl">
    </script>

    <script src="../../test/FileUpload/jQueryv1.6.2.js"></script>
    <script src="fileupload-js/jquery.ui.widget.js"></script>
    <script src="fileupload-js/tmpl.min.js"></script>
    <script src="fileupload-js/jquery.fileupload.js"></script>
    <script src="fileupload-js/jquery.fileupload-ui.js"></script>
    <script src="fileupload-js/locale.js"></script>
    <script src="fileupload-js/main.js"></script>    
</head>
<body>
<form id="fileupload" method="POST" runat="server">
    <CCAB.Web:FileUpload runat="server"/>
</form>
</body>
</html>

Serverside code:

public partial class SaveFile : System.Web.UI.Page
{
    private void Page_Load(object sender, System.EventArgs e)
    {
        Response.AddHeader("Access-Control-Allow-Origin", "*")

        if (Request.HttpMethod == "GET" || Request.HttpMethod == "HEAD")
        {

            Response.Write("GET Success");
        }
        else
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                string filename = Request.Files[i].FileName;
                Request.Files[i].SaveAs(@"\\dev2\\share$\\Anna\\test\\" + filename);
                Response.Write(filename);
            Response.Write("Success");
            }

        }
    }
}

Could you please help me in how to ignore the hidden viewstate code from client side or ignore the response viewstate in server side.

Many Thanks
Anna

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:03:29+00:00Added an answer on June 7, 2026 at 10:03 am

    I have found the solution for this problem. Please find below

    public class BasePage : Page
    
    {
    
      private static string[] aspNetFormElements = new string[] 
    
      { 
    
        "__EVENTTARGET",
    
        "__EVENTARGUMENT",
    
        "__VIEWSTATE",
    
        "__EVENTVALIDATION",
    
        "__VIEWSTATEENCRYPTED",
    
      };
    
    
    
      protected override void Render(HtmlTextWriter writer)
    
      {
    
        StringWriter stringWriter = new StringWriter();
    
        HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
    
        base.Render(htmlWriter);
    
        string html = stringWriter.ToString();
    
        int formStart = html.IndexOf("<form");
    
        int endForm = -1;
    
        if (formStart >= 0)
    
          endForm = html.IndexOf(">", formStart);
    
    
    
        if (endForm >= 0)
    
        {
    
          StringBuilder viewStateBuilder = new StringBuilder();
    
          foreach (string element in aspNetFormElements)
    
          {
    
            int startPoint = html.IndexOf("<input type=\"hidden\" name=\"" + element + "\"");
    
            if (startPoint >= 0 && startPoint > endForm)
    
            {
    
              int endPoint = html.IndexOf("/>", startPoint);
    
              if (endPoint >= 0)
    
              {
    
                endPoint += 2;
    
                string viewStateInput = html.Substring(startPoint, endPoint - startPoint);
    
                html = html.Remove(startPoint, endPoint - startPoint);
    
                viewStateBuilder.Append(viewStateInput).Append("\r\n");
    
              }
    
            }
    
          }
    
    
    
          if (viewStateBuilder.Length > 0)
    
          {
    
            viewStateBuilder.Insert(0, "\r\n");
    
            html = html.Insert(endForm + 1, viewStateBuilder.ToString());
    
          }
    
        }
    
    
    
        writer.Write(html);
    
      }
    
    }
    

    Please find more info on this page : http://blogs.msdn.com/b/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx

    Many Thanks
    Anna

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to POST some multipart form data to my server using a Browser
I'm trying to send post data between pages with Post. Not a form -
im trying to POST (cross domain) some data to a jersey web service and
I am trying to post data from PHP to Server which is built in
Trying to post JSON data to Spring controller.. Not working at all JSP Code:
If my POST data from a form submission = John Doe, and I'm trying
i am trying to post data via HTTP Post using name value key pair.
I'm trying to post data to URL by using Android App. URL : parameters:
I am trying to post data from InfoPath using the WebServiceConnection, to a WFC
i am new to android development. i am trying to post data to server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.