gpt4 book ai didi

c# - ASP.NET 网页中的间歇性无效 View 状态错误

转载 作者:太空狗 更新时间:2023-10-29 20:42:00 25 4
gpt4 key购买 nike

故事:

我正在开发一个显示假期(年假、已用假期等...)的图表,用于从组合框中选择一年、业务单位和部门,到目前为止,我对它的工作结果感到满意...但是如果在执行此操作一段时间后在这些部门之间切换,我会收到这个奇怪的错误...*

The state information is invalid for this page and might be corrupted.

[No relevant source lines]


所以我向下滚动了一下,找到了这个

[ViewStateException: Invalid viewstate. 
Client IP: ::1
Port: 27968
Referer: http://localhost/HolidayTracker/Report/VacationChart.aspx
Path: /HolidayTracker/Report/VacationChart.aspx
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
ViewState: ....

所以我检查了我的 View 状态,但没有发现错误或其他问题......

        private HtBusinessUnit selectedBU
{
get
{
return (HtBusinessUnit)ViewState["selectedBu"];

}
set
{
ViewState["selectedBu"] = value;
}
}
private HtDepartment selectDep
{
get
{
return (HtDepartment)ViewState["selectedDep"];
}
set
{
ViewState["selectedDep"] = value;
}
}
private string selectedYear
{
get
{
return ViewState["selectedYear"] != null ? ViewState["selectedYear"].ToString() : "";
}
set
{
ViewState["selectedYear"] = value;
}
}

这是错误信息

[ArgumentException: Invalid token for impersonation - it cannot be duplicated.]
System.Security.Principal.WindowsIdentity.CreateFromToken(IntPtr userToken) +3597947
System.Security.Principal.WindowsIdentity..ctor(SerializationInfo info) +187
System.Security.Principal.WindowsIdentity..ctor(SerializationInfo info, StreamingContext context) +51

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.SerializationInvoke(IRuntimeMethodInfo method, Object target, SerializationInfo info, StreamingContext& context) +0
System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context) +298
System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder) +45
System.Runtime.Serialization.ObjectManager.DoFixups() +230
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +137
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +186
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream) +15
System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +1873
System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +334
System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +420
System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +432
System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +420
System.Web.UI.ObjectStateFormatter.Deserialize(Stream inputStream) +139

[ArgumentException: The serialized data is invalid.]
System.Web.UI.ObjectStateFormatter.Deserialize(Stream inputStream) +203
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose) +481
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter2.Deserialize(String serializedState, Purpose purpose) +8
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose) +40
System.Web.UI.HiddenFieldPageStatePersister.Load() +127

[ViewStateException: Invalid viewstate.
Client IP: ::1
Port: 27795
Referer: http://localhost/HolidayTracker/Report/VacationChart.aspx
Path: /HolidayTracker/Report/VacationChart.aspx
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
ViewState: /wEPDwULLTE2OTYyMjA5MzkPFgQeCnNlbGVjdGVkQnUy1p4BAAEAAAD/////AQAAAAAAAAAMAgAAAElIb2xpZGF5VHJhY2tlckRhdGEsIFZlcnNpb249MS4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsDAMAAABVU3lzdGVtLkRhdGEuRW50aXR5LCBWZXJzaW9uPTQuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OQUBAAAAKEhvbGlkYXlUcmFja2VyLkRhdGEuTW9kZWwuSHRCdXNpbmVzc1VuaXQFAAAAD19CdXNpbmVzc1VuaXRJZAVfTmFtZQ9fT3JnYW5pc2F0aW9uSWQbRW50aXR5T2JqZWN0K19yZWxhdGlvbnNoaXBzF0VudGl0eU9iamVjdCtfZW50aXR5S2V5AAEABAQICDNTeXN0ZW0uRGF0YS5PYmplY3RzLkRhdGFDbGFzc2VzLlJlbGF0aW9uc2hpcE1hbmFnZXIDAAAAFVN5c3RlbS5EYXRhLkVudGl0eUtleQMAAAACAAAAFAAAAAYEAAAABUZTLUlTDgAAAAkFAAAACQYAAAAFBQAAADNTeXN0ZW0uRGF0YS5PYmplY3RzLkRhdGFDbGFzc2VzLlJlbGF0aW9uc2hpcE1hbmFnZXICAAAABl9vd25lcg5fcmVsYXRpb25zaGlwcwQDKEhvbGlkYXl...]

[HttpException (0x80004005): The state information is invalid for this page and might be corrupted.]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +198
System.Web.UI.HiddenFieldPageStatePersister.Load() +266
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +88
System.Web.UI.Page.LoadAllState() +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6704
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +245
System.Web.UI.Page.ProcessRequest() +72
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +58
ASP.report_vacationchart_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\holidaytracker\ad68c354\56d80455\App_Web_k5s5ajkf.1.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

这是我的 Global.asax.cs

namespace HolidayTracker {
public class Global : System.Web.HttpApplication {

void Application_Start(object sender, EventArgs e) {
// Code that runs on application startup

}

void Application_End(object sender, EventArgs e) {
// Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e) {
// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e) {
// Code that runs when a new session is started
if (HttpContext.Current.User != null && HttpContext.Current.User is HtUser)
{
HtUser user = (HtUser)HttpContext.Current.User;
Session["UserId"] = user.UserId;

Session["User"] = user.LastName+" "+user.FirstName ;


if (user.HtDepartments.Any() && user.HtDepartments.SingleOrDefault().HtBusinessUnit != null)
{
int BusinessUnitId = user.HtDepartments.First().HtBusinessUnit.BusinessUnitId;
Session["BusinessUnnitId"] = BusinessUnitId;
}


}
}

void Session_End(object sender, EventArgs e) {
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.

//if (Session["UserId"] == null)
//{
// Response.ClearContent();
// Response.Write("Not agine");
// Response.End();
//}
//else
//{
// Response.Write(Session["UserId"].ToString());
//}
}

protected void WindowsAuthentication_OnAuthenticate(Object source, WindowsAuthenticationEventArgs e)
{
if (Request.Cookies.Get(Constants.AUTHORIZATION_COOKIE_NAME) != null)
return;

String strUserIdentity;
FormsAuthenticationTicket formsAuthTicket;
HttpCookie httpCook;
String strEncryptedTicket;
AdLookup adLookup = new AdLookup();

strUserIdentity = e.Identity.Name;

bool loggedIn = false;
String email = null;
String role = null;

email = strUserIdentity;
HtUser userInfo = null;
if (email != null && email != "")
{
userInfo = HtUser.GetByLogin(e.Identity, email);

if (userInfo != null && userInfo.UserName.Length > 0)
{
loggedIn = true;
role = HtUser.GetUserRoleString(userInfo);
}
//Checks if user is in domain
else
{
userInfo = adLookup.GetAdUserByUsername(HtUser.getUserNameFromDomainString(email));
if (userInfo != null && userInfo.UserName.Length > 0)
{
loggedIn = true;
role = UserRoles.User;
}
}
}
//}

if (loggedIn)
{
formsAuthTicket = new FormsAuthenticationTicket(1, email, DateTime.Now,
DateTime.Now.AddMinutes(60), false, role);
strEncryptedTicket = FormsAuthentication.Encrypt(formsAuthTicket);
httpCook = new HttpCookie(Constants.AUTHORIZATION_COOKIE_NAME, strEncryptedTicket);
Response.Cookies.Add(httpCook);
HttpContext.Current.User = userInfo;
}
else
{
HttpContext.Current.User = null;
}
}

}
}

我你需要更多的东西随时问我!!

感谢帮助和快速回答

最佳答案

哦,我认为这不是什么大问题,但我强烈建议您只用“正常”解决方案替换您的 View 状态,只需使用 Rad Combo 框中的值,这样更容易,但可以肯定的是,这不是真正的解决方案你的问题是因为我看到它真的很奇怪我没有在这里看到错误,对我来说这对我来说似乎一切都好。但如果将更新后的代码连同一些评论发回给您。

如果您有任何问题,请随时提出!¨

PS:如果你找到解决方案,请联系我!!

关于c# - ASP.NET 网页中的间歇性无效 View 状态错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15410910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com