Reputation: 3
I am using the following code to open a second web form using first web form in asp.net C# :
private void Next_frm()
{
if ((UserID == ""))
{
}
else
{
Response.Redirect("product.aspx");
}
}
but this causing the error : An unhandled exception of type 'System.Web.HttpException' occurred in System.Web.dll:Response is not available in this context.
What should I do?
Calling from this form:
private void comRFID_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{ System.Diagnostics.Debug.WriteLine("comRFID_DataReceived");
comRFID.Read(hex, 0, hex.Length);
Send_Beep();
string[] strCard1 = { "2", "12", "18", "128", "4", "0", "149", "124", "243", "50", "224", "243" };
string[] strbuffer = { hex[0].ToString(), hex[1].ToString(), hex[2].ToString(), hex[3].ToString(), hex[4].ToString(), hex[5].ToString(), hex[6].ToString(), hex[7].ToString(), hex[8].ToString(), hex[9].ToString(), hex[10].ToString(), hex[11].ToString() };
if ((strbuffer[11].ToString() == strCard1[11]))
{
UserID = "1234";
Send_Beep();
System.Diagnostics.Debug.WriteLine(("UserId: " + UserID));
comRFID.Close();
Next_frm();
}
else
{
Response.Write("<script>alert('Card Undefined, Please Register Your Card.');</script>");
Send_cmd();
}
}
Upvotes: 0
Views: 933
Reputation: 52210
Looking at this prototype....
private void comRFID_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
...I'm guessing that this method handles the event when a frame is received over a serial port.
As you probably know, web server communications typically occur via an HTTP request that initiates an ASP.NET request instance. When this occurs, ASP.NET constructs an HttpContext object and populates it with information about the request (e.g. the HttpRequest itself, and its Url and QueryString properties). It then dispatches the request to whatever handler you have mapped to the URL (typically a System.Web.Page object, or in MVC a Controller object).
When an event is raised outside of an HTTP request, there is no HTTP context. You can detect this condition by using this code:
bool contextExists = (HttpContext.Current != null);
An HttpContext would make no sense if there is no HTTP request. If anything, there would be a "serial port context" which you would have to implement yourself.
Anyway, in the absence of an HTTP request, there is no HttpContext and therefore no HttpResponse. That is why it is not available in this context.
I am not sure what you are trying to accomplish. If you are trying to get some device connected via serial port to access a page, you will need to write some code that executes on that device.
Upvotes: 1