G
Guest
Hello,
I am trying to get a response for an .aspx page in my current project (same
virtual directory) by using WebRequest.GetResponse 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.GetResponse 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.WebRequest req = System.Net.WebRequest.Create(applicationRootURL
+ ResponseEmailSourceFileName);
req.Credentials = System.Net.CredentialCache.DefaultCredentials;
System.Net.WebResponse resp = req.GetResponse();
The page's code-behind is:
public class ResponseEmailTemplate : InitializedThreadCulturePage
{
private const string BaseResourceName = "ResponseEmailTemplate";
protected System.Web.UI.WebControls.Label lblPartiesInvolved;
protected System.Web.UI.WebControls.Label lblAmountClaimed;
protected System.Web.UI.WebControls.Label lblMatterNumber;
protected System.Web.UI.WebControls.Label lblRespondingLawyer;
protected System.Web.UI.WebControls.Label lblDescription;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
LocalizePage();
}
private void LocalizePage()
{
ResourceManager rsm = this.GetPageResourceManager(BaseResourceName);
// Localize labels.
lblPartiesInvolved.Text = rsm.GetString("Label.PartiesInvolved");
lblAmountClaimed.Text = rsm.GetString("Label.AmountClaimed");
lblMatterNumber.Text = rsm.GetString("Label.MatterNumber");
lblRespondingLawyer.Text = rsm.GetString("Label.RespondingLawyer");
lblDescription.Text = rsm.GetString("Label.Description");
}
I am trying to get a response for an .aspx page in my current project (same
virtual directory) by using WebRequest.GetResponse 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.GetResponse 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.WebRequest req = System.Net.WebRequest.Create(applicationRootURL
+ ResponseEmailSourceFileName);
req.Credentials = System.Net.CredentialCache.DefaultCredentials;
System.Net.WebResponse resp = req.GetResponse();
The page's code-behind is:
public class ResponseEmailTemplate : InitializedThreadCulturePage
{
private const string BaseResourceName = "ResponseEmailTemplate";
protected System.Web.UI.WebControls.Label lblPartiesInvolved;
protected System.Web.UI.WebControls.Label lblAmountClaimed;
protected System.Web.UI.WebControls.Label lblMatterNumber;
protected System.Web.UI.WebControls.Label lblRespondingLawyer;
protected System.Web.UI.WebControls.Label lblDescription;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
LocalizePage();
}
private void LocalizePage()
{
ResourceManager rsm = this.GetPageResourceManager(BaseResourceName);
// Localize labels.
lblPartiesInvolved.Text = rsm.GetString("Label.PartiesInvolved");
lblAmountClaimed.Text = rsm.GetString("Label.AmountClaimed");
lblMatterNumber.Text = rsm.GetString("Label.MatterNumber");
lblRespondingLawyer.Text = rsm.GetString("Label.RespondingLawyer");
lblDescription.Text = rsm.GetString("Label.Description");
}