I thought I'd post an update on my issue. It turns out that my problem had
nothing to do with the proxy settings.
I inherit my aspx page from a base class of type
"InitializedThr eadCulturePage" . This is a class (derived from
System.Web.UI.P age) that sets up the Thread Culture settings depending on a
user language choice (stored in a cookie).
I tried my code with a brand new "WebForm1.a spx" with no code in the
code-behind and had no problems. The next thing I tried was to inherit this
new WebForm1 from "InitializedThr eadCulturePage" and I received the 500
response code.
Here is the page code:
using System;
using System.Resource s;
namespace MyPage.Web.UI
{
/// <summary>
/// Base class for other pages in this application that require the
/// CultureInfo to be set on the current thread. Pages should
/// inherit from this class if they require this functionality.
///
/// This class also provides a method to retrieve the ResourceManager
/// for a particular page. In order to use this functionality, users
/// must create a resource file with the same filename as the web page,
/// minus the .aspx extension. Thus, if a page is named WebForm.aspx,
/// the user would create a file in the Resources folder called
/// WebForm.resx. Then, when you call the GetPageResource Manager
/// method, simply pass in the name WebForm in order to get the
/// appropriate resource set.
/// </summary>
public class InitializedThre adCulturePage : System.Web.UI.P age
{
private ResourceManager m_pageResourceM anager;
/// <summary>
/// Constructor that adds an event handler for the page's Load
/// event. The event handler will initialize the current thread's
/// CultureInfo appropriately.
/// </summary>
public InitializedThre adCulturePage()
{
this.Load += new System.EventHan dler(this.Page_ Load);
}
/// <summary>
/// Returns the page's resource manager. The baseName parameter
/// should match the name of the resource file in the Resources
/// directory. That is, if a resource exists named WebForm.resx,
/// the parameter supplied should be "WebForm".
/// </summary>
/// <remarks>
/// This method assumes that all resources are stored in satellite
/// assemblies with the neutral resources residing in the currently
/// executing assembly. Also, this method assumes that all resource
/// files are placed in the Resources directory before compilation.
/// </remarks>
/// <param name="baseName" >
/// The name of the resource set to retrieve. This name will match
/// the name of the resource file in the Resources directory.
/// </param>
/// <returns>
/// A ResourceManager object containing the specified resource set.
/// </returns>
protected ResourceManager GetPageResource Manager(string baseName)
{
if (m_pageResource Manager == null)
{
m_pageResourceM anager = new ResourceManager (
"MyPage.Web.UI. Resources." + baseName,
System.Reflecti on.Assembly.Get ExecutingAssemb ly());
}
return m_pageResourceM anager;
}
// This event handler will initialize the current thread's CultureInfo
// by looking for a cookie in the page that specifies the desired locale.
// If this cookie exists, the CultureInfo will be created using that
// locale. If not, then this event handler will retrieve the locale
// specified by in the HTTP header and use that to create the CultureInfo
// object.
// As a side effect, if a cookie exists, the cookie's expiration date
// will be reset.
private void Page_Load(objec t sender, System.EventArg s e)
{
System.Web.Http Cookie languageCookie =
Request.Cookies[WebConstants.Se lectedLanguageP arameterName];
string locale = Request.UserLan guages[0];
if (languageCookie != null)
{
locale = languageCookie. Value;
// Update the expiry date on the cookie.
languageCookie. Expires =
DateTime.Now.Ad dYears(WebConst ants.CookieExpi rationLength);
}
// Set the culture info for the current thread.
System.Threadin g.Thread.Curren tThread.Current UICulture =
System.Threadin g.Thread.Curren tThread.Current Culture =
System.Globaliz ation.CultureIn fo.CreateSpecif icCulture(local e);
if (languageCookie != null)
{
Response.Cookie s.Add(languageC ookie);
}
}
}
}
Any ideas as to why this doesn't work when creating a WebRequest
programmaticall y?
Thanks in advance.
"Terry" wrote:
THANK YOU! That's a great little tool!
Now, I am running into an issue trying to use it with VS.NET 2003. When I
debug the web app and get a couple levels deep in the navigation, I get an
error saying that I have too many connections to the web server. (HTTP 403.9
- Access Forbidden: Too many users are connected Internet Information
Services). Sometimes I get an error directly from Fiddler about too many
socket connections as well. I found mention of this on the Fiddler forum
here: http://www.bayden.com/bbs/viewtopic.php?t=253
I have a corporate ISA proxy that requires NTLM authentication. I am using
Fiddler's "Require Authentication" , but after reading the forums, it looks as
though I won't be able to use Fiddler because of NTLM authentication hop
limitations. Is this correct?
I tried the setting suggested on the blog
(System.Net.Glo balProxySelecti on.Select = new
System.Net.WebP roxy("127.0.0.1 ", 8888);) but Fiddler never seems to catch any
requests when I'm debugging in VS.NET (although the request goes through just
fine. I did see mention of this in the forum as well).
Anyway, in all of my messing around with Fiddler, I was able to pinpoint the
problem as the proxy settings in my WebRequest.
Thanks again for the tool suggestion!
"Scott Allen" wrote:
Does the page depend on any sort of client header being sent to indicate
the locale?
You might want to compare what the browser is sending over HTTP versus your
program with a tool like Fiddler [1]. These problems usually come down to
different headers or POST values.
[1] http://www.fiddlertool.com/fiddler/
--
Scott
http://www.OdeToCode.com/blogs/scott/
Hello,
I am trying to get a response for an .aspx page in my current project
(same virtual directory) by using WebRequest.GetR esponse but I keep
getting a exception with "500 Internal server error" in the exception
message.
I am able to do this fine with another .aspx page that has no
code-behind. The page that has code-behind throws the exception.
What I am doing is getting the .aspx response, reading the stream,
replacing pre-determined tags with app data, and then sending the HTML
as an email body, but I only have problems getting the response. The
other logic works fine (based on experience with the other, working
page).
I am trying to get the response from a page that has server label
controls whose text is set by the code-behind depending on the culture
set in the web app.
I'm quite confused as I thought I should be able to call
WebRequest.GetR esponse on any page that I can load manually in
Internet Explorer (which, in this case, is true).
Here is the code in question:
System.Net.WebR equest req =
System.Net.WebR equest.Create(a pplicationRootU RL
+ ResponseEmailSo urceFileName);
req.Credentials = System.Net.Cred entialCache.Def aultCredentials ;
System.Net.WebR esponse resp = req.GetResponse ();
The page's code-behind is:
public class ResponseEmailTe mplate : InitializedThre adCulturePage
{
private const string BaseResourceNam e = "ResponseEmailT emplate";
protected System.Web.UI.W ebControls.Labe l lblPartiesInvol ved;
protected System.Web.UI.W ebControls.Labe l lblAmountClaime d;
protected System.Web.UI.W ebControls.Labe l lblMatterNumber ;
protected System.Web.UI.W ebControls.Labe l lblRespondingLa wyer;
protected System.Web.UI.W ebControls.Labe l lblDescription;
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
LocalizePage();
}
private void LocalizePage()
{
ResourceManager rsm =
this.GetPageRes ourceManager(Ba seResourceName) ;
// Localize labels.
lblPartiesInvol ved.Text = rsm.GetString(" Label.PartiesIn volved");
lblAmountClaime d.Text = rsm.GetString(" Label.AmountCla imed");
lblMatterNumber .Text = rsm.GetString(" Label.MatterNum ber");
lblRespondingLa wyer.Text = rsm.GetString(" Label.Respondin gLawyer");
lblDescription. Text = rsm.GetString(" Label.Descripti on");
}