C# ASP.NET in-page code not telling me 'Response' does not exist
I have some code in umbraco that is ru开发者_C百科n and creates a javascript file for looking up their IP and sending them to the correct site for their language, now this works but I'm trying to add an override system into it so a user of the site can force themselves out of the redirect using cookies but for some reason when I try to write the response it tells me that the Response local variable can't be used before it is set
<%@ Master Language="C#" MasterPageFile="/umbraco/masterpages/default.master" AutoEventWireup="true" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<script runat="server">
string getOutput(){
HttpCookieCollection MyCookieColl;
HttpCookie MyCookie;
MyCookieColl = Request.Cookies;
MyCookie = MyCookieColl["override"];
try{
if(MyCookieColl["override"].Value == "overridden"){
HttpCookie cookie = new HttpCookie("override");
cookie.Value = "overridden" ;
DateTime dtNow = DateTime.Now;
TimeSpan tsMinute = new TimeSpan(0, 0, 10, 0);
cookie.Expires = dtNow + tsMinute;
Response.Cookies.Add(cookie);
return "";
}
}catch(Exception e){
}
try{
if(Request.Form["overide"] == "overridden"){
HttpCookie cookie = new HttpCookie("override");
cookie.Value = "overridden" ;
DateTime dtNow = DateTime.Now;
TimeSpan tsMinute = new TimeSpan(0, 0, 10, 0);
cookie.Expires = dtNow + tsMinute;
Response.Cookies.Add(cookie);
return "";
}
}catch(Exception e){
}
[[[TRIMMED CODE NOT NEED BELOW WORKS]]]]
</script>
<%=getOutput()%>
</asp:Content>
Have you tried using HttpContext.Current.Response ?
Using "Response"
out of the box like that probably requires a directive import.
精彩评论