My favorites | Sign in
Project Home Downloads Wiki Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System.Collections;
using System.Security.Principal;
using System.Web;
using System;
using N2.Engine;

namespace N2.Web
{
/// <summary>
/// A web context wrapper that maps to the web request context for calls in
/// web application scope and thread context when no request has been made
/// (e.g. when executing code in scheduled action).
/// </summary>
public class AdaptiveContext : IWebContext, IDisposable
{
readonly IWebContext thread = new ThreadContext();
readonly IWebContext web = new WebRequestContext();

/// <summary>Gets wether there is a web context availabe.</summary>
public bool IsWeb
{
get { return HttpContext.Current != null; }
}

/// <summary>Returns either the web or the thread context depending on <see cref="IsWeb"/>.</summary>
protected IWebContext CurrentContext
{
get { return IsWeb ? web : thread; }
}

/// <summary>Gets a dictionary of request scoped items.</summary>
public IDictionary RequestItems
{
get { return CurrentContext.RequestItems; }
}

/// <summary>Gets the current user principal (may be null).</summary>
public IPrincipal User
{
get { return CurrentContext.User; }
}

/// <summary>The current request object.</summary>
public HttpRequest Request
{
get { return CurrentContext.Request; }
}

/// <summary>The current response object.</summary>
public HttpResponse Response
{
get { return CurrentContext.Response; }
}

/// <summary>The handler associated with this request.</summary>
public IHttpHandler Handler
{
get { return CurrentContext.Handler; }
}

/// <summary>A page instance stored in the request context.</summary>
public ContentItem CurrentPage
{
get { return CurrentContext.CurrentPage; }
set { CurrentContext.CurrentPage = value; }
}

/// <summary>The template used to serve this request.</summary>
public PathData CurrentPath
{
get { return CurrentContext.CurrentPath; }
set { CurrentContext.CurrentPath = value;}
}

/// <summary>Specifies whether the UrlAuthorizationModule should skip authorization for the current request.</summary>
public bool SkipAuthorization
{
get { return CurrentContext.SkipAuthorization; }
}

/// <summary>The physical path on disk to the requested page.</summary>
public string PhysicalPath
{
get { return CurrentContext.PhysicalPath; }
}

/// <summary>The host part of the requested url, e.g. http://n2cms.com/path/to/a/page.aspx?some=query.</summary>
public Url Url
{
get { return CurrentContext.Url; }
}

/// <summary>Converts a virtual path to an an absolute path. E.g. ~/hello.aspx -> /MyVirtualDirectory/hello.aspx.</summary>
/// <param name="virtualPath">The virtual url to make absolute.</param>
/// <returns>The absolute url.</returns>
public string ToAbsolute(string virtualPath)
{
return CurrentContext.ToAbsolute(virtualPath);
}

/// <summary>Converts an absolute url to an app relative path. E.g. /MyVirtualDirectory/hello.aspx -> ~/hello.aspx.</summary>
/// <param name="virtualPath">The absolute url to convert.</param>
/// <returns>An app relative url.</returns>
public string ToAppRelative(string virtualPath)
{
return CurrentContext.ToAppRelative(virtualPath);
}

/// <summary>Maps a virtual path to a physical disk path.</summary>
/// <param name="path">The path to map. E.g. "~/bin"</param>
/// <returns>The physical path. E.g. "c:\inetpub\wwwroot\bin"</returns>
public string MapPath(string path)
{
return CurrentContext.MapPath(path);
}

/// <summary>Rewrites the request to the given path.</summary>
/// <param name="path">The path to the template that will handle the request.</param>
public void RewritePath(string path)
{
CurrentContext.RewritePath(path);
}

/// <summary>Rewrites the request to the given path.</summary>
/// <param name="path">The path to the template that will handle the request.</param>
/// <param name="query">The query string to rewrite to.</param>
public void RewritePath(string path, string query)
{
CurrentContext.RewritePath(path, query);
}

[Obsolete]
public void TransferRequest(string path)
{
CurrentContext.TransferRequest(path);
}

/// <summary>Calls into HttpContext.ClearError().</summary>
public void ClearError()
{
CurrentContext.ClearError();
}

/// <summary>Disposes request items that needs disposing. This method should be called at the end of each request.</summary>
public void Close()
{
CurrentContext.Close();
}

#region IDisposable Members

void IDisposable.Dispose()
{
Close();
}

#endregion
}
}

Change log

r1503 by cristian.libardo on Nov 15, 2010   Diff
- Removed unecessary IMailSender from
template projects
- Fixed authorization + rewrite issue
(ThreadId=77613) (security model change)
Go to: 
Project members, sign in to write a code review

Older revisions

r1457 by cristian.libardo on Sep 26, 2010   Diff
- Updated MVC content and tweaked
styles
- Fixed redirect to fixclass on MVC
r1422 by cristian.libardo on Sep 7, 2010   Diff
- Applied milicicd's patch #6351:
returnUrl looks ugly
r1252 by cristian.libardo on Mar 14, 2010   Diff
- refactored rewriting mechanism to
simplify asp.net authorization usage
All revisions of this file

File info

Size: 4789 bytes, 159 lines
Powered by Google Project Hosting