Today I am working on a function for tutors to submit messages in the company. To put it bluntly, when a tutor enters for the first time, there is no message, and then the message is added and modified. Of course, this involves the interaction between CS and the front desk, and I implement it through Handler.
Because you want to modify his message, you need to modify it based on his ID. However, generally the company's projects save the user's information after logging in in the session; so there is no doubt that the ID must be obtained based on the ID. I always at first
I can't get the ID, that is, I can't get the ID I want in the cs file. The way I get it is like this: string uid = HttpContext.Current.Session[UserSessionPolicy.SESSION_USERID] as string;
Explain this "UserSessionPolicy.SESSION_USERID", where "UserSessionPolicy" is a class specially used to save user information. Of course, it also saves the user ID, which is the "SESSION_USERID" in the code. When I clicked the submit button, an error like "The object was not referenced to an instance" was reported. Everyone would definitely think that it was not instantiated? That's right, it's just not instantiated, but how to instantiate it in Handler?
As for Session, everyone knows that session is a scope, used to save state, so a namespace must be referenced in Handler. I encountered this problem before
I had such a headache, I solved it today. Today I will write down my morals here and share them with everyone. I hope that in the future, netizens will provide a little help when they encounter the same similar problems.
In my example, the tutor needs to use ID in his message. Can this be done for other users who need to use ID? Generally speaking, the class that processes data through Handler must refer to the name "using System.Web.SessionState;"
space, then that class inherits "IReadOnlySessionState". For example:
code
<%@ WebHandler Language="C#" Class="TeacherInfoHandler" %>using System;using System.Web;using com.rrs.baby.business.Information;using com.rrs.core;using System.Web.Script.Serialization ;using System.Web.SessionState;//Use the ID to be saved in the sessionusing System.Collections;public class TeacherInfoHandler: IHttpHandler, IReadOnlySessionState{ //Method body}
In this TeacherInfoHandler class, you can use the value saved by the session.