473,322 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Response is not available in this context

1
I am new in asp.net.I want to redirect to Home.aspx page but I am getting this error message:"System.Web.HttpException: Response is not available in this context" in the line of Response.Redirect("Home.aspx"); Any idea on solving this?


Expand|Select|Wrap|Line Numbers
  1. private void comRFID_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
  2. {
  3.    System.Diagnostics.Debug.WriteLine("comRFID_DataReceived");
  4.     comRFID.Read(hex, 0, hex.Length);
  5.     //Send_Beep();
  6.     System.Diagnostics.Debug.WriteLine("hex[0].ToString()");
  7.     System.Diagnostics.Debug.WriteLine("hex[1].ToString()");
  8.     System.Diagnostics.Debug.WriteLine("hex[2].ToString()");
  9.     System.Diagnostics.Debug.WriteLine("hex[3].ToString()");
  10.     System.Diagnostics.Debug.WriteLine("hex[4].ToString()");
  11.     System.Diagnostics.Debug.WriteLine("hex[5].ToString()");
  12.     System.Diagnostics.Debug.WriteLine("hex[6].ToString()");
  13.     System.Diagnostics.Debug.WriteLine("hex[7].ToString()");
  14.     System.Diagnostics.Debug.WriteLine("hex[8].ToString()");
  15.     System.Diagnostics.Debug.WriteLine("hex[9].ToString()");
  16.     System.Diagnostics.Debug.WriteLine("hex[10].ToString()");
  17.     System.Diagnostics.Debug.WriteLine("hex[11].ToString()");
  18.  
  19.     string[] strCard1 = { "2", "12", "18", "128", "4", "0", "149", "124", "243", "50", "224", "243" };
  20.     //byte[] bytes = { hex[0], hex[1], hex[2], hex[3], hex[4], hex[5], hex[6], hex[7], hex[8], hex[9], hex[10], hex[11] };
  21.     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() };
  22.  
  23.     if ((strbuffer[11].ToString() == strCard1[11]))
  24.     {
  25.         UserID = "0000";
  26.         Send_Beep();
  27.         System.Diagnostics.Debug.WriteLine(("UserId: " + UserID));
  28.         comRFID.Close();
  29.         Response.Redirect("Home.aspx");
  30.         //Server.Execute("Home.aspx");
  31.         //HttpContext.Current.Response.Redirect("Home.aspx");
  32.         //Server.Transfer("Home.aspx", true);
  33.     }
  34.     else
  35.     {
  36.         Response.Write("<script>alert('Card Undefined, Please Register Your Card.');</script>");
  37.         Send_cmd();
  38.     }
Attached Images
File Type: png 1.PNG (62.3 KB, 363 views)
Feb 21 '17 #1
1 3421
Frinavale
9,735 Expert Mod 8TB
Where is this code located?

When developing in asp.net you have to keep in mind that there is a life cycle involved. If you are at a point in the life cycle where the HTTP Context is not available, then you can't use it.
Feb 21 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jack Wright | last post by:
Dear All, I would like to read the processModel from machine.config. The following is code I have writte Dim hConfig As Object = ConfigurationSettings.GetConfig("system.web/processModel") But if...
1
by: Sascha Kuhl | last post by:
I'm working on a piece of code that sets a cookie, depending on the some Session State values in the PreRequestHandlerExecute event of my App. The code works on my development machine (Windows...
5
by: Pepehammer | last post by:
Exception Details: System.Web.HttpException: Response is not available in this context. Source Error: Line 16: '---------- // SUB : WriteString Line 17: Public Sub WriteString(SayItNow as...
1
by: rao | last post by:
Hi I am generating unique xml files and deleting them in page_unload event. Application responds properly in normal conditions. When I keep clicking on url that invoke the page several times the...
0
by: Rahul_Borade | last post by:
Hi, I have one project which is made in VS 2003 now I have conveted it into Whidbey. The project contais many crystal report files. On all pages, those which contains Crystal report Viewer...
1
by: kingski | last post by:
I have a web page (Asp.net 2.0, vs2005) in which there is this construction: <img src="/pages/showimage.aspx"> In global.asax I access sessions in Application_PreRequestHandlerExecute event. ...
0
by: gunjanhshah | last post by:
Hello My system reports the following application event log. The log is due to my web application which is built upon asp.net and sql server 2000 and uses Active directory users to authenticate....
3
by: doofy | last post by:
I'm trying to create a custom control which would be a treeview which populates itself with table and field details from a database. I need to be able to call up a form to enter the server/db...
2
by: maniishkumar | last post by:
I am writing a string as Response.Write("Hello world"); on Page_UnLoad() event. I am using ASP.NET with C#. When I execute this error and run the application I found this error that Response...
10
BeemerBiker
by: BeemerBiker | last post by:
I get that error message when trying to do a "Response.write()". I undoubtedly set up my classes wrong. My workaround is to put the offending code in each codebehind page. I would like to put the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.