tak - jeg føler mig lidt tumbet lige nu men får fejl.
Kan du hjælpe?
Her er 3 kodestumper som ikke spiller. Det giver fejl på runtime:
Kildekoder nedenfor....
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 26: context.Response.AppendHeader("Content-Disposition", "attachment; filename=YouSee Registrering.txt");
Line 27:
Line 28: string SavedInfo = (string)HttpContext.Current.Session["SaveInfo"];
Line 29:
Line 30: context.Response.Write(SavedInfo);
Source File: c:\Work\Workspace\asunet.webspeed.dk\tmoHandler.ashx Line: 28
Kildekode for tmoHandler.ashx:
<%@ WebHandler Language="C#" Class="tmoHandler" %>
using System;
using System.Collections;
using System.ComponentModel;
using System.Web.SessionState;
public class tmoHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=Registrering.txt");
string SavedInfo = (string)HttpContext.Current.Session["SaveInfo"];
context.Response.Write(SavedInfo);
}
public bool IsReusable
{
get
{
return false;
}
}
}
Kildekode for tmopage.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;
using System.Web.SessionState;
public partial class tmoPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["SaveInfo"] = "Dette er min tekst, der er gemt i en sessionvariabel";
HttpContext.Current.Session["SaveInfo"] = "Dette er min tekst, der er gemt i en sessionvariabel";
}
}
Kildekode for tmopage.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="tmoPage.aspx.cs" Inherits="tmoPage" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<a href="tmoHandler.ashx?id=1">Download</a>
</div>
</form>
</body>
</html>