summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-09-15 22:15:14 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2010-09-15 22:25:37 -0700
commitd4477a5d0020ada7b4d13469ad4908860edcb39a (patch)
tree0d68d386bf983952dd38fd85580de468117388e2
parent51f1c6b78e53cc06a0e6900ee28a03805f484b20 (diff)
downloadDotNetOpenAuth-d4477a5d0020ada7b4d13469ad4908860edcb39a.zip
DotNetOpenAuth-d4477a5d0020ada7b4d13469ad4908860edcb39a.tar.gz
DotNetOpenAuth-d4477a5d0020ada7b4d13469ad4908860edcb39a.tar.bz2
Added a provider model to substitute in a means for obtaining URLs that download embedded resource streams.
This unblocks dasBlog in their pursuit of a non-Page ASP.NET pipeline.
-rw-r--r--src/DotNetOpenAuth/Configuration/DotNetOpenAuth.xsd19
-rw-r--r--src/DotNetOpenAuth/Configuration/DotNetOpenAuthSection.cs14
-rw-r--r--src/DotNetOpenAuth/DotNetOpenAuth.csproj1
-rw-r--r--src/DotNetOpenAuth/IEmbeddedResourceRetrieval.cs22
-rw-r--r--src/DotNetOpenAuth/Mvc/OpenIdHelper.cs77
-rw-r--r--src/DotNetOpenAuth/Strings.Designer.cs11
-rw-r--r--src/DotNetOpenAuth/Strings.resx5
-rw-r--r--src/DotNetOpenAuth/Util.cs35
8 files changed, 134 insertions, 50 deletions
diff --git a/src/DotNetOpenAuth/Configuration/DotNetOpenAuth.xsd b/src/DotNetOpenAuth/Configuration/DotNetOpenAuth.xsd
index fda2aaf..9c0ab77 100644
--- a/src/DotNetOpenAuth/Configuration/DotNetOpenAuth.xsd
+++ b/src/DotNetOpenAuth/Configuration/DotNetOpenAuth.xsd
@@ -878,6 +878,25 @@
</xs:attribute>
</xs:complexType>
</xs:element>
+ <xs:element name="webResourceUrlProvider">
+ <xs:annotation>
+ <xs:documentation>
+ The type that implements the DotNetOpenAuth.IEmbeddedResourceRetrieval interface
+ to instantiate for obtaining URLs that fetch embedded resource streams.
+ Primarily useful when the System.Web.UI.Page class is not used in the ASP.NET pipeline.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="optional">
+ <xs:annotation>
+ <xs:documentation>
+ The fully-qualified name of the type that implements the IEmbeddedResourceRetrieval interface.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="xaml" type="xs:string" use="optional" />
+ </xs:complexType>
+ </xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
diff --git a/src/DotNetOpenAuth/Configuration/DotNetOpenAuthSection.cs b/src/DotNetOpenAuth/Configuration/DotNetOpenAuthSection.cs
index 117a542..409fca9 100644
--- a/src/DotNetOpenAuth/Configuration/DotNetOpenAuthSection.cs
+++ b/src/DotNetOpenAuth/Configuration/DotNetOpenAuthSection.cs
@@ -40,6 +40,11 @@ namespace DotNetOpenAuth.Configuration {
private const string ReportingElementName = "reporting";
/// <summary>
+ /// The name of the &lt;webResourceUrlProvider&gt; sub-element.
+ /// </summary>
+ private const string WebResourceUrlProviderName = "webResourceUrlProvider";
+
+ /// <summary>
/// Initializes a new instance of the <see cref="DotNetOpenAuthSection"/> class.
/// </summary>
internal DotNetOpenAuthSection() {
@@ -116,5 +121,14 @@ namespace DotNetOpenAuth.Configuration {
this[ReportingElementName] = value;
}
}
+
+ /// <summary>
+ /// Gets or sets the type to use for obtaining URLs that fetch embedded resource streams.
+ /// </summary>
+ [ConfigurationProperty(WebResourceUrlProviderName)]
+ internal TypeConfigurationElement<IEmbeddedResourceRetrieval> EmbeddedResourceRetrievalProvider {
+ get { return (TypeConfigurationElement<IEmbeddedResourceRetrieval>)this[WebResourceUrlProviderName] ?? new TypeConfigurationElement<IEmbeddedResourceRetrieval>(); }
+ set { this[WebResourceUrlProviderName] = value; }
+ }
}
}
diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
index c9900ea..15aa698 100644
--- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj
+++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
@@ -301,6 +301,7 @@ http://opensource.org/licenses/ms-pl.html
<Compile Include="Configuration\HostNameOrRegexCollection.cs" />
<Compile Include="Configuration\HostNameElement.cs" />
<Compile Include="Configuration\XriResolverElement.cs" />
+ <Compile Include="IEmbeddedResourceRetrieval.cs" />
<Compile Include="InfoCard\ClaimType.cs" />
<Compile Include="InfoCard\InfoCardImage.cs" />
<Compile Include="InfoCard\InfoCardStrings.Designer.cs">
diff --git a/src/DotNetOpenAuth/IEmbeddedResourceRetrieval.cs b/src/DotNetOpenAuth/IEmbeddedResourceRetrieval.cs
new file mode 100644
index 0000000..b9a6fd0
--- /dev/null
+++ b/src/DotNetOpenAuth/IEmbeddedResourceRetrieval.cs
@@ -0,0 +1,22 @@
+//-----------------------------------------------------------------------
+// <copyright file="IEmbeddedResourceRetrieval.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth {
+ using System;
+
+ /// <summary>
+ /// An interface that provides URLs from which embedded resources can be obtained.
+ /// </summary>
+ public interface IEmbeddedResourceRetrieval {
+ /// <summary>
+ /// Gets the URL from which the given manifest resource may be downloaded by the user agent.
+ /// </summary>
+ /// <param name="someTypeInResourceAssembly">Some type in the assembly containing the desired resource.</param>
+ /// <param name="manifestResourceName">Manifest name of the desired resource.</param>
+ /// <returns>An absolute URL.</returns>
+ Uri GetWebResourceUrl(Type someTypeInResourceAssembly, string manifestResourceName);
+ }
+}
diff --git a/src/DotNetOpenAuth/Mvc/OpenIdHelper.cs b/src/DotNetOpenAuth/Mvc/OpenIdHelper.cs
index 193e445..a83f3bf 100644
--- a/src/DotNetOpenAuth/Mvc/OpenIdHelper.cs
+++ b/src/DotNetOpenAuth/Mvc/OpenIdHelper.cs
@@ -30,16 +30,14 @@ namespace DotNetOpenAuth.Mvc {
/// Emits a series of stylesheet import tags to support the AJAX OpenID Selector.
/// </summary>
/// <param name="html">The <see cref="HtmlHelper"/> on the view.</param>
- /// <param name="page">The page being rendered.</param>
/// <returns>HTML that should be sent directly to the browser.</returns>
- public static string OpenIdSelectorStyles(this HtmlHelper html, Page page) {
+ public static string OpenIdSelectorStyles(this HtmlHelper html) {
Contract.Requires<ArgumentNullException>(html != null);
- Contract.Requires<ArgumentNullException>(page != null);
Contract.Ensures(Contract.Result<string>() != null);
StringWriter result = new StringWriter();
- result.WriteStylesheetLink(page, OpenId.RelyingParty.OpenIdSelector.EmbeddedStylesheetResourceName);
- result.WriteStylesheetLink(page, OpenId.RelyingParty.OpenIdAjaxTextBox.EmbeddedStylesheetResourceName);
+ result.WriteStylesheetLink(OpenId.RelyingParty.OpenIdSelector.EmbeddedStylesheetResourceName);
+ result.WriteStylesheetLink(OpenId.RelyingParty.OpenIdAjaxTextBox.EmbeddedStylesheetResourceName);
return result.ToString();
}
@@ -47,25 +45,22 @@ namespace DotNetOpenAuth.Mvc {
/// Emits a series of script import tags and some inline script to support the AJAX OpenID Selector.
/// </summary>
/// <param name="html">The <see cref="HtmlHelper"/> on the view.</param>
- /// <param name="page">The page being rendered.</param>
/// <returns>HTML that should be sent directly to the browser.</returns>
- public static string OpenIdSelectorScripts(this HtmlHelper html, Page page) {
- return OpenIdSelectorScripts(html, page, null, null);
+ public static string OpenIdSelectorScripts(this HtmlHelper html) {
+ return OpenIdSelectorScripts(html, null, null);
}
/// <summary>
/// Emits a series of script import tags and some inline script to support the AJAX OpenID Selector.
/// </summary>
/// <param name="html">The <see cref="HtmlHelper"/> on the view.</param>
- /// <param name="page">The page being rendered.</param>
/// <param name="selectorOptions">An optional instance of an <see cref="OpenIdSelector"/> control, whose properties have been customized to express how this MVC control should be rendered.</param>
/// <param name="additionalOptions">An optional set of additional script customizations.</param>
/// <returns>
/// HTML that should be sent directly to the browser.
/// </returns>
- public static string OpenIdSelectorScripts(this HtmlHelper html, Page page, OpenIdSelector selectorOptions, OpenIdAjaxOptions additionalOptions) {
+ public static string OpenIdSelectorScripts(this HtmlHelper html, OpenIdSelector selectorOptions, OpenIdAjaxOptions additionalOptions) {
Contract.Requires<ArgumentNullException>(html != null);
- Contract.Requires<ArgumentNullException>(page != null);
Contract.Ensures(Contract.Result<string>() != null);
if (selectorOptions == null) {
@@ -92,7 +87,7 @@ window.openid_trace = {1}; // causes lots of messages";
OpenIdRelyingPartyAjaxControlBase.EmbeddedAjaxJavascriptResource,
OpenId.RelyingParty.OpenIdAjaxTextBox.EmbeddedScriptResourceName,
};
- result.WriteScriptTags(page, scriptResources);
+ result.WriteScriptTags(scriptResources);
if (selectorOptions.DownloadYahooUILibrary) {
result.WriteScriptTags(new[] { "https://ajax.googleapis.com/ajax/libs/yui/2.8.0r4/build/yuiloader/yuiloader-min.js" });
@@ -163,10 +158,10 @@ window.openid_trace = {1}; // causes lots of messages";
}});";
blockBuilder.WriteLine(
blockFormat,
- MessagingUtilities.GetSafeJavascriptValue(page.ClientScript.GetWebResourceUrl(typeof(OpenIdRelyingPartyControlBase), OpenIdTextBox.EmbeddedLogoResourceName)),
- MessagingUtilities.GetSafeJavascriptValue(page.ClientScript.GetWebResourceUrl(typeof(OpenIdRelyingPartyControlBase), OpenId.RelyingParty.OpenIdAjaxTextBox.EmbeddedSpinnerResourceName)),
- MessagingUtilities.GetSafeJavascriptValue(page.ClientScript.GetWebResourceUrl(typeof(OpenIdRelyingPartyControlBase), OpenId.RelyingParty.OpenIdAjaxTextBox.EmbeddedLoginSuccessResourceName)),
- MessagingUtilities.GetSafeJavascriptValue(page.ClientScript.GetWebResourceUrl(typeof(OpenIdRelyingPartyControlBase), OpenId.RelyingParty.OpenIdAjaxTextBox.EmbeddedLoginFailureResourceName)),
+ MessagingUtilities.GetSafeJavascriptValue(Util.GetWebResourceUrl(typeof(OpenIdRelyingPartyControlBase), OpenIdTextBox.EmbeddedLogoResourceName)),
+ MessagingUtilities.GetSafeJavascriptValue(Util.GetWebResourceUrl(typeof(OpenIdRelyingPartyControlBase), OpenId.RelyingParty.OpenIdAjaxTextBox.EmbeddedSpinnerResourceName)),
+ MessagingUtilities.GetSafeJavascriptValue(Util.GetWebResourceUrl(typeof(OpenIdRelyingPartyControlBase), OpenId.RelyingParty.OpenIdAjaxTextBox.EmbeddedLoginSuccessResourceName)),
+ MessagingUtilities.GetSafeJavascriptValue(Util.GetWebResourceUrl(typeof(OpenIdRelyingPartyControlBase), OpenId.RelyingParty.OpenIdAjaxTextBox.EmbeddedLoginFailureResourceName)),
selectorOptions.Throttle,
selectorOptions.Timeout.TotalMilliseconds,
MessagingUtilities.GetSafeJavascriptValue(selectorOptions.TextBox.LogOnText),
@@ -183,7 +178,7 @@ window.openid_trace = {1}; // causes lots of messages";
MessagingUtilities.GetSafeJavascriptValue(selectorOptions.TextBox.AuthenticationFailedToolTip));
result.WriteScriptBlock(blockBuilder.ToString());
- result.WriteScriptTags(page, OpenId.RelyingParty.OpenIdSelector.EmbeddedScriptResourceName);
+ result.WriteScriptTags(OpenId.RelyingParty.OpenIdSelector.EmbeddedScriptResourceName);
Reporting.RecordFeatureUse("MVC " + typeof(OpenIdSelector).Name);
return result.ToString();
@@ -193,20 +188,18 @@ window.openid_trace = {1}; // causes lots of messages";
/// Emits the HTML to render an OpenID Provider button as a part of the overall OpenID Selector UI.
/// </summary>
/// <param name="html">The <see cref="HtmlHelper"/> on the view.</param>
- /// <param name="page">The page being rendered.</param>
/// <param name="providerIdentifier">The OP Identifier.</param>
/// <param name="imageUrl">The URL of the image to display on the button.</param>
/// <returns>
/// HTML that should be sent directly to the browser.
/// </returns>
- public static string OpenIdSelectorOPButton(this HtmlHelper html, Page page, Identifier providerIdentifier, string imageUrl) {
+ public static string OpenIdSelectorOPButton(this HtmlHelper html, Identifier providerIdentifier, string imageUrl) {
Contract.Requires<ArgumentNullException>(html != null);
- Contract.Requires<ArgumentNullException>(page != null);
Contract.Requires<ArgumentNullException>(providerIdentifier != null);
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(imageUrl));
Contract.Ensures(Contract.Result<string>() != null);
- return OpenIdSelectorButton(html, page, providerIdentifier, "OPButton", imageUrl);
+ return OpenIdSelectorButton(html, providerIdentifier, "OPButton", imageUrl);
}
/// <summary>
@@ -214,32 +207,28 @@ window.openid_trace = {1}; // causes lots of messages";
/// allowing the user to enter their own OpenID.
/// </summary>
/// <param name="html">The <see cref="HtmlHelper"/> on the view.</param>
- /// <param name="page">The page being rendered.</param>
/// <param name="imageUrl">The URL of the image to display on the button.</param>
/// <returns>
/// HTML that should be sent directly to the browser.
/// </returns>
- public static string OpenIdSelectorOpenIdButton(this HtmlHelper html, Page page, string imageUrl) {
+ public static string OpenIdSelectorOpenIdButton(this HtmlHelper html, string imageUrl) {
Contract.Requires<ArgumentNullException>(html != null);
- Contract.Requires<ArgumentNullException>(page != null);
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(imageUrl));
Contract.Ensures(Contract.Result<string>() != null);
- return OpenIdSelectorButton(html, page, "OpenIDButton", "OpenIDButton", imageUrl);
+ return OpenIdSelectorButton(html, "OpenIDButton", "OpenIDButton", imageUrl);
}
/// <summary>
/// Emits the HTML to render the entire OpenID Selector UI.
/// </summary>
/// <param name="html">The <see cref="HtmlHelper"/> on the view.</param>
- /// <param name="page">The page being rendered.</param>
/// <param name="buttons">The buttons to include on the selector.</param>
/// <returns>
/// HTML that should be sent directly to the browser.
/// </returns>
- public static string OpenIdSelector(this HtmlHelper html, Page page, params SelectorButton[] buttons) {
+ public static string OpenIdSelector(this HtmlHelper html, params SelectorButton[] buttons) {
Contract.Requires<ArgumentNullException>(html != null);
- Contract.Requires<ArgumentNullException>(page != null);
Contract.Requires<ArgumentNullException>(buttons != null);
Contract.Ensures(Contract.Result<string>() != null);
@@ -252,13 +241,13 @@ window.openid_trace = {1}; // causes lots of messages";
foreach (SelectorButton button in buttons) {
var op = button as SelectorProviderButton;
if (op != null) {
- h.Write(OpenIdSelectorOPButton(html, page, op.OPIdentifier, op.Image));
+ h.Write(OpenIdSelectorOPButton(html, op.OPIdentifier, op.Image));
continue;
}
var openid = button as SelectorOpenIdButton;
if (openid != null) {
- h.Write(OpenIdSelectorOpenIdButton(html, page, openid.Image));
+ h.Write(OpenIdSelectorOpenIdButton(html, openid.Image));
continue;
}
@@ -294,16 +283,14 @@ window.openid_trace = {1}; // causes lots of messages";
/// Emits the HTML to render a button as a part of the overall OpenID Selector UI.
/// </summary>
/// <param name="html">The <see cref="HtmlHelper"/> on the view.</param>
- /// <param name="page">The page being rendered.</param>
/// <param name="id">The value to assign to the HTML id attribute.</param>
/// <param name="cssClass">The value to assign to the HTML class attribute.</param>
/// <param name="imageUrl">The URL of the image to draw on the button.</param>
/// <returns>
/// HTML that should be sent directly to the browser.
/// </returns>
- private static string OpenIdSelectorButton(this HtmlHelper html, Page page, string id, string cssClass, string imageUrl) {
+ private static string OpenIdSelectorButton(this HtmlHelper html, string id, string cssClass, string imageUrl) {
Contract.Requires<ArgumentNullException>(html != null);
- Contract.Requires<ArgumentNullException>(page != null);
Contract.Requires<ArgumentNullException>(id != null);
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(imageUrl));
Contract.Ensures(Contract.Result<string>() != null);
@@ -327,7 +314,7 @@ window.openid_trace = {1}; // causes lots of messages";
h.RenderBeginTag(HtmlTextWriterTag.Img);
h.RenderEndTag();
- h.AddAttribute(HtmlTextWriterAttribute.Src, page.ClientScript.GetWebResourceUrl(typeof(OpenIdSelector), OpenId.RelyingParty.OpenIdAjaxTextBox.EmbeddedLoginSuccessResourceName));
+ h.AddAttribute(HtmlTextWriterAttribute.Src, Util.GetWebResourceUrl(typeof(OpenIdSelector), OpenId.RelyingParty.OpenIdAjaxTextBox.EmbeddedLoginSuccessResourceName));
h.AddAttribute(HtmlTextWriterAttribute.Class, "loginSuccess");
h.AddAttribute(HtmlTextWriterAttribute.Title, "Authenticated as {0}");
h.RenderBeginTag(HtmlTextWriterTag.Img);
@@ -351,7 +338,7 @@ window.openid_trace = {1}; // causes lots of messages";
/// </summary>
/// <param name="writer">The writer to emit the tags to.</param>
/// <param name="scriptUrls">The locations of the scripts to import.</param>
- private static void WriteScriptTags(this TextWriter writer, IEnumerable<string> scriptUrls) {
+ private static void WriteScriptTagsUrls(this TextWriter writer, IEnumerable<string> scriptUrls) {
Contract.Requires<ArgumentNullException>(writer != null);
Contract.Requires<ArgumentNullException>(scriptUrls != null);
@@ -364,28 +351,24 @@ window.openid_trace = {1}; // causes lots of messages";
/// Writes out script tags that import a script from resources embedded in this assembly.
/// </summary>
/// <param name="writer">The writer to emit the tags to.</param>
- /// <param name="page">The page being rendered.</param>
/// <param name="resourceName">Name of the resource.</param>
- private static void WriteScriptTags(this TextWriter writer, Page page, string resourceName) {
+ private static void WriteScriptTags(this TextWriter writer, string resourceName) {
Contract.Requires<ArgumentNullException>(writer != null);
- Contract.Requires<ArgumentNullException>(page != null);
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(resourceName));
- WriteScriptTags(writer, page, new[] { resourceName });
+ WriteScriptTags(writer, new[] { resourceName });
}
/// <summary>
/// Writes out script tags that import scripts from resources embedded in this assembly.
/// </summary>
/// <param name="writer">The writer to emit the tags to.</param>
- /// <param name="page">The page being rendered.</param>
/// <param name="resourceNames">The resource names.</param>
- private static void WriteScriptTags(this TextWriter writer, Page page, IEnumerable<string> resourceNames) {
+ private static void WriteScriptTags(this TextWriter writer, IEnumerable<string> resourceNames) {
Contract.Requires<ArgumentNullException>(writer != null);
- Contract.Requires<ArgumentNullException>(page != null);
Contract.Requires<ArgumentNullException>(resourceNames != null);
- writer.WriteScriptTags(resourceNames.Select(r => page.ClientScript.GetWebResourceUrl(typeof(OpenIdRelyingPartyControlBase), r)));
+ writer.WriteScriptTagsUrls(resourceNames.Select(r => Util.GetWebResourceUrl(typeof(OpenIdRelyingPartyControlBase), r)));
}
/// <summary>
@@ -407,14 +390,12 @@ window.openid_trace = {1}; // causes lots of messages";
/// Writes a given CSS link.
/// </summary>
/// <param name="writer">The writer to emit the tags to.</param>
- /// <param name="page">The page being rendered.</param>
/// <param name="resourceName">Name of the resource containing the CSS content.</param>
- private static void WriteStylesheetLink(this TextWriter writer, Page page, string resourceName) {
+ private static void WriteStylesheetLink(this TextWriter writer, string resourceName) {
Contract.Requires<ArgumentNullException>(writer != null);
- Contract.Requires<ArgumentNullException>(page != null);
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(resourceName));
- WriteStylesheetLink(writer, page.ClientScript.GetWebResourceUrl(typeof(OpenIdRelyingPartyAjaxControlBase), resourceName));
+ WriteStylesheetLinkUrl(writer, Util.GetWebResourceUrl(typeof(OpenIdRelyingPartyAjaxControlBase), resourceName));
}
/// <summary>
@@ -422,7 +403,7 @@ window.openid_trace = {1}; // causes lots of messages";
/// </summary>
/// <param name="writer">The writer to emit the tags to.</param>
/// <param name="stylesheet">The stylesheet to link in.</param>
- private static void WriteStylesheetLink(this TextWriter writer, string stylesheet) {
+ private static void WriteStylesheetLinkUrl(this TextWriter writer, string stylesheet) {
Contract.Requires<ArgumentNullException>(writer != null);
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(stylesheet));
diff --git a/src/DotNetOpenAuth/Strings.Designer.cs b/src/DotNetOpenAuth/Strings.Designer.cs
index 70b9fb2..1461f83 100644
--- a/src/DotNetOpenAuth/Strings.Designer.cs
+++ b/src/DotNetOpenAuth/Strings.Designer.cs
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
-// Runtime Version:4.0.30104.0
+// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -79,6 +79,15 @@ namespace DotNetOpenAuth {
}
/// <summary>
+ /// Looks up a localized string similar to The current IHttpHandler is not one of types: {0}. An embedded resource URL provider must be set in your .config file..
+ /// </summary>
+ internal static string EmbeddedResourceUrlProviderRequired {
+ get {
+ return ResourceManager.GetString("EmbeddedResourceUrlProviderRequired", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to No current HttpContext was detected, so an {0} instance must be explicitly provided or specified in the .config file. Call the constructor overload that takes an {0}..
/// </summary>
internal static string StoreRequiredWhenNoHttpContextAvailable {
diff --git a/src/DotNetOpenAuth/Strings.resx b/src/DotNetOpenAuth/Strings.resx
index a7f080d..4b78664 100644
--- a/src/DotNetOpenAuth/Strings.resx
+++ b/src/DotNetOpenAuth/Strings.resx
@@ -126,4 +126,7 @@
<data name="ConfigurationXamlReferenceRequiresHttpContext" xml:space="preserve">
<value>The configuration XAML reference to {0} requires a current HttpContext to resolve.</value>
</data>
-</root>
+ <data name="EmbeddedResourceUrlProviderRequired" xml:space="preserve">
+ <value>The current IHttpHandler is not one of types: {0}. An embedded resource URL provider must be set in your .config file.</value>
+ </data>
+</root> \ No newline at end of file
diff --git a/src/DotNetOpenAuth/Util.cs b/src/DotNetOpenAuth/Util.cs
index 8a18ef8..0317c4d 100644
--- a/src/DotNetOpenAuth/Util.cs
+++ b/src/DotNetOpenAuth/Util.cs
@@ -11,6 +11,10 @@ namespace DotNetOpenAuth {
using System.Net;
using System.Reflection;
using System.Text;
+ using System.Web;
+ using System.Web.UI;
+
+ using DotNetOpenAuth.Configuration;
using DotNetOpenAuth.Messaging;
/// <summary>
@@ -24,6 +28,11 @@ namespace DotNetOpenAuth {
internal const string DefaultNamespace = "DotNetOpenAuth";
/// <summary>
+ /// The web.config file-specified provider of web resource URLs.
+ /// </summary>
+ private static IEmbeddedResourceRetrieval embeddedResourceRetrieval = DotNetOpenAuthSection.Configuration.EmbeddedResourceRetrievalProvider.CreateInstance(null, false);
+
+ /// <summary>
/// Gets a human-readable description of the library name and version, including
/// whether the build is an official or private one.
/// </summary>
@@ -154,6 +163,32 @@ namespace DotNetOpenAuth {
}
/// <summary>
+ /// Gets the web resource URL from a Page or <see cref="IEmbeddedResourceRetrieval"/> object.
+ /// </summary>
+ /// <param name="someTypeInResourceAssembly">Some type in resource assembly.</param>
+ /// <param name="manifestResourceName">Name of the manifest resource.</param>
+ /// <returns>An absolute URL</returns>
+ internal static string GetWebResourceUrl(Type someTypeInResourceAssembly, string manifestResourceName) {
+ Page page;
+ IEmbeddedResourceRetrieval retrieval;
+
+ if (embeddedResourceRetrieval != null) {
+ Uri url = embeddedResourceRetrieval.GetWebResourceUrl(someTypeInResourceAssembly, manifestResourceName);
+ return url != null ? url.AbsoluteUri : null;
+ } else if ((page = HttpContext.Current.CurrentHandler as Page) != null) {
+ return page.ClientScript.GetWebResourceUrl(someTypeInResourceAssembly, manifestResourceName);
+ } else if ((retrieval = HttpContext.Current.CurrentHandler as IEmbeddedResourceRetrieval) != null) {
+ return retrieval.GetWebResourceUrl(someTypeInResourceAssembly, manifestResourceName).AbsoluteUri;
+ } else {
+ throw new InvalidOperationException(
+ string.Format(
+ CultureInfo.CurrentCulture,
+ Strings.EmbeddedResourceUrlProviderRequired,
+ string.Join(", ", new string[] { typeof(Page).FullName, typeof(IEmbeddedResourceRetrieval).FullName })));
+ }
+ }
+
+ /// <summary>
/// Manages an individual deferred ToString call.
/// </summary>
/// <typeparam name="T">The type of object to be serialized as a string.</typeparam>