I am receiving the below error from a very simple web application ran directly from Visual Studio 2010 with framework 4.0.
Server Error in '/' Application.
Validation of viewstate MAC failed. If this application is hosted by a
Web Farm or cluster, ensure that configuration specifies
the same validationKey and validation algorithm. AutoGenerate cannot
be used in a cluster.
Here is my application files
web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<!--<machineKey validationKey="08367F8C07194695F9714CB86778E9031DFAC34ECAE8DE9944CE7E765EB8B6F56D0DDE9C95639F01DF94597D4FFFF42BFCDB0A71544755C70683D6B95D3D3E5B" decryptionKey="DF5FA3F9EA83B31D9BF1381539CD90E3D4AEA74FEE490E5C1B0A160A4CCA7DA2" validation="SHA1" decryption="AES" />-->
<pages enableViewState="false"></pages>
</system.web>
</configuration>
Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test.Default" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" method="post" action="info.aspx">
<div>
<input type="hidden" name="data" value="this is post data" />
<input type="submit" name="Submit" value="Submit" />
</div>
</form>
</body>
</html>
info.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Test
{
public partial class info : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string x = Request.Form["data"];
}
}
}
I tried all possible solutions given over internet but in vain.
Added machine key {not worked}
Added enableViewState="false" {not worked}
I am desperately trying to understand why this behaviour?
Have you tried using ASP.net proper hidden as opposed to input?
<asp:HiddenField ID="data" value="this is post data" runat="server" />
Related
Why does my Cache object contain a single entry containing the following? Shouldn't it be empty? And if not, obviously there is this ugly default value in the Cache object...how do I remove it? I haven't added anything to the Cache object, yet it contains this item below.
__System.Web.WebPages.Deployment__C:\Users\Danny\Documents\Visual Studio 2010\Projects\LearningAOP\WebAppCachingII\WebAppCachingII\***C:\Users\Danny\Documents\Visual Studio 2010\Projects\LearningAOP\WebAppCachingII\WebAppCachingII\
Here is my ASP.NET code-behind, the markup has a single bulleted list control;
using System;
using System.Collections;
using System.Linq;
using System.Web.UI.WebControls;
namespace WebAppCachingII
{
public partial class CachingDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
foreach (DictionaryEntry cacheditem in Cache)
{
var concatstring = cacheditem.Key + "***" + cacheditem.Value;
listOfCacheItems.Items.Add(new ListItem(concatstring));
}
}
}
}
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="CachingDemo.aspx.cs" Inherits="WebAppCachingII.CachingDemo" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:BulletedList ID="listOfCacheItems" runat="server" /> </div>
</form>
</body>
</html>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<caching>
<outputCache enableOutputCache="false" />
</caching>
</system.web>
</configuration>
i have a very simple websote just for experimentation.
On my local machine it works but when i put it on the server i get "Server Error in '/' Application.Runtime Error "
defaul.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="_default"%>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<defaultDocument>
<files>
<clear />
<add value="default.aspx" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
But when i change the aspx file it works (i've removed:CodeFile="default.aspx.cs" and Inherits="_default")
<%# Page Language="C#" AutoEventWireup="true"%>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Turns out that if i remove the System.Linq from my aspx.cs file the site does work.
Is the Framework version correct for the application pool on the server?
You've stated that it works if you remove System.Linq which could point at the Framework version being incorrect on the application pool
The other thing to check is to make sure you're not running sites built on different version of the .Net framework in the same application pool as they will kill each other and you'll get the dreaded "Server Error in '/' Application. Runtime Error"
Please check two dlls must be in your Bin folder on the server
1) System.Web.Extensions.dll
2) System.Web.Extensions.Design.dll
I am seeing this error:
Unable to cast object of type 'System.Web.Profile.DefaultProfile' to type 'ProfileCommon'.
on following code:
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(TextUsername.Text, true);
I am not sure why...
Agree with theChrisKent.It's look like problem in the web.config
Check out the following example for,How to get ProfileCommon object in asp.net
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="GetProfile" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
User Name:<asp:TextBox ID="txtUserName" runat="server"/>
<asp:Button ID="cmdGet" runat="server" OnClick="cmdGet_Click" Text="Get Profile" /><br />
<asp:Label ID="lbl" runat="server" Text=""/>
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class GetProfile : System.Web.UI.Page
{
protected void cmdGet_Click(object sender, EventArgs e)
{
ProfileCommon profile = Profile.GetProfile(txtUserName.Text);
if (profile.LastUpdatedDate == DateTime.MinValue)
{
lbl.Text = "No user match found.";
}
else
{
lbl.Text = "This user lives in " + profile.FirstName;
}
}
}
File: Web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<profile>
<properties>
<add name="FirstName" type="String" serializeAs="Binary"/>
<add name="LastName" type="String" serializeAs="Xml"/>
<add name="DateOfBirth" type="DateTime" serializeAs="String"/>
</properties>
</profile>
</system.web>
</configuration>
EDIT
This example only work when the project type is website.If you want to use ProfileCommon object in Web Application then go through the following link
Converting Profile Object Code
EDIT -II
As per your comment,Following link might help you
ASP.NET Profiles in Web Application Projects
Check your web.config if no <profile /> section is defined, ASP.NET creates a profile object of type DefaultProfile which can cause your error.
The above only applies to Web Sites and not Web Applications. Since you have indicated you are using a Web Application you should be aware:
Visual Studio does NOT generate ProfileCommon objects for Web Applications
You have to access your profile properties using ProfileBase.GetPropertyValue(PropertyName)
So you can get a property like this (example from below article):
DateTime DOB = Convert.ToDateTime(HttpContext.Current.Profile.GetPropertyValue("DateOfBirth"));
See this article for more information/examples: http://weblogs.asp.net/anasghanem/archive/2008/04/12/the-differences-in-profile-between-web-application-projects-wap-and-website.aspx
I have to use a ckeditor in my application but I dont know how to write the
# Register Assembly="" Namespace="" TagPrefix="" %>
From where I could get the assembly?
In web.config section you can write:
<add tagPrefix="FredCK" namespace="FredCK.CKEditor" assembly="FredCK.CKEditor, Culture=neutral, PublicKeyToken=9ef91de3e191403a" />
Actually, best is not to use the ASP.NET CKEditor control but use CKEditor directly. The control is outdated (version 3.6 instead of 4.1) and not necessary. Basically, use a multiline textbox and make it of the class CKEditor. Don't forget to add the ckEditor.js to the head section:
web.config
<configuration>
<system.web>
<httpRuntime requestValidationMode="2.0"/>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>
Test.aspx
<!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 runat="server">
<title>ckeditor test page</title>
<script src="ckeditor/ckeditor.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<p>
<asp:TextBox class="ckeditor" ID="CkeditorTextBox" runat="server" TextMode="MultiLine" Columns="80" Rows="10">
Hi
</asp:TextBox>
</p>
<p>
<asp:Button ID="SubmitButton" runat="server" onclick="SubmitButton_Click" Text="Submit" />
</p>
</form>
</body>
</html>
Test.aspx.cs
using System;
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SubmitButton_Click(object sender, EventArgs e) {
string CkEditorText = CkeditorTextBox.Text;
//add some processing here
}
}
There is a nice asp.net wrapper control for the ckeditor: http://cksource.com/forums/viewtopic.php?f=11&t=15882
The answer will be
scrpt type = "text/javascript" src = "ckeditor/ckeditor.js"....close script
//ckeditor is the folder that you have created in your application.
script type="text/javascript"
window.onload = function()
{
debugger
vartxtDemo = document.getElementByID('<%txtDemo.ClientID%');
CKEDITOR.replace(txtDemo);
}...//close the script
but before that make a ckeditor folder in your application and paste the contents that you have downloaded,
I've never used either of these 2 controls before and I'm stuck with no visible rendering of the page (compiles and runs but produces nothing); I have no code behind file with this simple asp.net page and I am using Visual Studio 2008:
<%# Page Language="C#" AutoEventWireup="true"
CodeBehind="Index.aspx.cs" Inherits="zList.Index" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="CategoryList" runat="server"
DataSourceID="Categories">
<LayoutTemplate>
<ol>
<asp:PlaceHolder runat="server" ID="itemPlaceholder">
</asp:PlaceHolder>
</ol>
</LayoutTemplate>
<ItemTemplate>
<li><%# Eval("AttrDesc")%></li>
</ItemTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>
<asp:sqldatasource runat="server" id="Categories"
ConnectionString="<%$ ConnectionStrings:ZIPeeeConnectionString2 %>"
SelectCommand="SELECT AttrID,AttrDesc FROM dbo.tblAttributes1">
</asp:sqldatasource>
Here is the connection string section from web.config (I have tried both connection strings separately and they both result in nothing rendered):
<connectionStrings>
<add name="ZIPeeeConnectionString" connectionString="Data Source=MOJITO;Initial Catalog=ZIPeee;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name="ZIPeeeConnectionString2" connectionString="Data Source=MOJITO;Initial Catalog=ZIPeee;User ID=sa;Password=" providerName="System.Data.SqlClient"/>
</connectionStrings>
I am getting no runtime errors and no errors during the build. The simple query works fine from SQL Query Analyzer (i.e. SQL Server 2000). Any ideas?
EDIT-UPDATE:
Here is what I have in my .ASPX.CS code behind file and I cannot get the debugger to stop on the breakpoint on the .DataBind method:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace zList
{
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CategoryList.DataBind(); // breakpoint set here but debugger won't stop here
}
}
}
By the way, I fired up SQL Profiler and it appears the SQL select is not even being fired against
the server. As I said, the page is empty - just this junk when I scrape it via View Page Source:
<!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><title></title></head>
<body>
<form name="form1" method="post" action="Index.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjAyMTkwMzQ3OQ9kFgQCAw9kFgICAQ8UKwACDxYEHgtfIURhdGFCb3VuZGceC18hSXRlbUNvdW50Av////8PZGRkAgUPD2QPEBYDZgIBAgIWAxYCHg5QYXJhbWV0ZXJWYWx1ZWQWAh8CZBYCHwJkFgMCAwIDAgNkZBgBBQxDYXRlZ29yeUxpc3QPZ2TCuhjvuwDRjaGJssTwiDXpAv/fdw==" />
</div>
<div>
</div>
</form>
</body>
</html>
I think the only thing wrong with this code is the placement of the sqldatasource. Can you place it inside the tag.
If that doesnt work, can you change your listview definition to
<asp:ListView ID="CategoryList" runat="server">
and then change your page load code to
CategoryList.DataSource = Categories;
CategoryList.DataBind();
You should be able to hit the debugger
As a last option, can you also check whether the connectionstrings is placed within the Configuration tag in web.config.