I asked this question in the DataDynamics forum earlier today. I thought that maybe I'd get some sort of response here at SO.
I am trying to get the WebViewer up and running in my ASP.NET MVC application.
I am attempting to render the webviewer in the controller (webViewer.RenderControl(htmlTextWriter) and then put the results into ViewData and display the report in my view. I dont' even know if this is the correct way to go about this. Any help would be greatly appreciated.
Controller code:
public ActionResult Display()
{
CurrentReport = new DetailedReport { ReportData = new DetailedData() { Repository = _repository } };
var webViewer = new WebViewer();
CurrentReport.Run();
webViewer.ID = "WebViewer1";
webViewer.Visible = true;
webViewer.ViewerType = ViewerType.HtmlViewer;
webViewer.Width = Unit.Percentage(100);
webViewer.Report = CurrentReport;
var stringWriter = new StringWriter();
var htmlTextWriter = new HtmlTextWriter(stringWriter);
webViewer.RenderBeginTag(htmlTextWriter);
webViewer.RenderControl(htmlTextWriter);
webViewer.RenderEndTag(htmlTextWriter);
ViewData["WebViewer"] = stringWriter.ToString();
return View();
}
Display.aspx code:
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%# Register assembly="ActiveReports.Web, Version=5.2.1013.2, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" namespace="DataDynamics.ActiveReports.Web" tagprefix="ActiveReportsWeb" %>
<%# Import Namespace="xxxx.Core"%>
<asp:Content ID="Content1" ContentPlaceHolderID="ClientAdminContent" runat="server">
<%=ViewData["WebViewer"] %>
</asp:Content>
Error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 60: var htmlTextWriter = new HtmlTextWriter(stringWriter);
Line 61: webViewer.RenderBeginTag(htmlTextWriter);
Line 62: webViewer.RenderControl(htmlTextWriter);
Line 63: webViewer.RenderEndTag(htmlTextWriter);
Line 64:
Source File: C:\Projects\xxxx\xxxx\app\xxxx.Web.Controllers\ReportsController.cs Line: 62
****Update:****
Based on the answer by scott (thank you) my controller now looks like this:
public ActionResult Display()
{
ViewData["Report"] = new DetailedReport { ReportData = new DetailedReport { ReportData = new DetailedData() { Repository = _repository } };
return View();
}
And my view looks like this: (I have no code behind files for my views).
<%
var report = (ActiveReport3) ViewData["Report"];
report.Run();
WebViewer1.Report = report;
%>
<ActiveReportsWeb:WebViewer ID="WebViewer1" runat="server" Height="100%" Width="100%" ViewerType="AcrobatReader" />
I watch it go through debugger, and it seems to correctly step through the Details section, putting values into my fields. But after all is done, I get the message "No Report Specified." I'm hoping that I really don't have to use a codebehind file on my view because I'm not using them anywhere else. I have also debugged to verify that report.Document.Pages.Count > 0. I have put the code block both above and below the WebViewer control (don't think that really matters). Any additional thoughts?
****Update #2:****
I ended up using the answer found here: Alternative to using the OnLoad event in an ASP.Net MVC View? in combination with scott's excellent answer below. It was a timing thing with generating and binding the report to the control. So my View looks like this in the end... (where Model.Report is an ActiveReport3)
<script runat="server">
private void Page_Load(object sender, EventArgs e)
{
var report = Model.Report;
report.Run();
WebViewer1.Report = report;
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ClientAdminContent" runat="server">
<ActiveReportsWeb:WebViewer ID="WebViewer1" runat="server" Height="100%" Width="100%" ViewerType="AcrobatReader" />
</asp:Content>
Thanks for everyone's help!
We have investigated this internally and found the following solution. You can add the WebViewer to a View normally. There is no need for the complicated low-level interaction code in your example. Instead, just add the WebViewer to your aspx view normally. In our sample the WebViewer was added as follows:
<ActiveReportsWeb:WebViewer ID="WebViewer1" runat="server" Height="100%" Width="100%" ViewerType="AcrobatReader" />
That is enough to get the WebViewer working on the view.
In the controller we specified an ActiveReport as follows:
ViewData["Report"] = new SampleReport();
In the codebehind of the View we hook the report to the view:
WebViewer1.Report = ViewData["Report"] as ActiveReport3;
Then the tricky part begins. There are some IHttpHandlers used by ActiveReports when running under ASP.NET for some of the viewer types such as AcrobatReader / PDF. To ensure our handlers are working you must get ASP.NET MVC routing to allow them to process as normal. Luckily it is easy to do so. Just add the following line of code to the Global.asax.cs file:
routes.IgnoreRoute("{*allarcachitems}", new { allarcachitems = #".*\.ArCacheItem(/.*)?" });
That will ignore the route. Note that according to my reading there may be problems since ASP.NET routing seems to allow only a single "catch all" route like this. Therefore, if you have multiple of these IgnoreRoute commands and or you have any problems with a .axd file, you'll need to modify the constraints dictionary argument to accomidate the .axd as well as .ArCacheItem.
For more information see the following article: http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx
You can download the full sample from our forums at http://www.datadynamics.com/forums/ShowPost.aspx?PostID=121907#121907
Scott Willeke
Data Dynamics / GrapeCity
For anyone else having this issue and using IIS7 Make sure you add the Active reports handlers under the <handlers> section not <httpHandlers>.
<add name="RPX" verb="*" path="*.rpx" type="DataDynamics.ActiveReports.Web.Handlers.RpxHandler, ActiveReports.Web, Version=6.1.2814.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff"/>
<add name="ActiveReport" verb="*" path="*.ActiveReport" type="DataDynamics.ActiveReports.Web.Handlers.CompiledReportHandler, ActiveReports.Web, Version=6.1.2814.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff"/>
<add name="ArCacheItem" verb="*" path="*.ArCacheItem" type="DataDynamics.ActiveReports.Web.Handlers.WebCacheAccessHandler, ActiveReports.Web, Version=6.1.2814.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff"/>
I thought i had the IgnoreRoute setup improperly because I was getting 404 errors. However I was following the tutorial given by ActiveReports which has them in the IIS6 section instead of IIS7.
Related
Report Viewer Preview displays empty, but Export and Print work fine.
I'm just about at my wits' end over this. I'm needing to make changes to an existing SSRS Report, and while all of the pieces seem to be doing their job, the final result is an empty report, even through the Report Viewer is fetching the right data for the report. (footnote:The report was called "ByGroup", but I'm changing pieces of it to "ByFields" to ensure that the existing report could still function on its own. This may be the cause of some of the issues, but I've tried to be careful to avoid that.)
The project uses Data Tables declared in a separate .xsd file held in the App_Code folder of a website. The data table calls a stored procedure, and the columns are all present, and the Fill and GetData methods are in place. Using the Data Table "Preview Data" option, we can verify that the Data Table is correct, and returns the correct data. We can provide more data to this end if it is relevant.
Our report's .aspx file has the correct Register tag for Report Viewer 14:
<%# Register assembly="Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
We are using an ObjectDataSource that links to the TableAdapter definition:
<asp:ObjectDataSource ID="EventListingByGroup_DataInstance" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="AEMSReports.dsAEMSReportsTableAdapters.AEMSReports_056_EventListingByFieldsTableAdapter">
The <SelectParameters> element accurately declares all of the parameters to feed the stored procedure.
The ReportViewer is defined as follows:
<rsweb:ReportViewer ID="rvEventListingByGroup" runat="server" Font-Names="Verdana"
Font-Size="8pt" Height="100%" Width="850px" AsyncRendering="False"
ClientIDMode="AutoID" InternalBorderColor="204, 204, 204" InternalBorderStyle="Solid"
InternalBorderWidth="1px" ToolBarItemBorderStyle="Solid" ToolBarItemBorderWidth="1px"
ToolBarItemPressedBorderColor="51, 102, 153" ToolBarItemPressedBorderStyle="Solid" ToolBarItemPressedBorderWidth="1px"
ToolBarItemPressedHoverBackColor="153, 187, 226" >
<LocalReport ReportPath="reports\Counts_Listings\EventListingByFields056.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="EventListingByGroup_DataInstance" Name="dsAEMSReports_AEMSReports_056_EventListingByFields" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
In the .aspx.cs Page_Load routine, we have this code:
if (!IsPostBack)
{
// Set hidden fields on the form for the Select parameters...
tbFromDate.Text = Request.Form["txtFromDate"].Trim();
// ...clip...
rvEventListingByGroup.Attributes.Add("style", "margin-bottom: 30px;");
rvEventListingByGroup.Visible = true;
string[] path = HttpContext.Current.Request.Url.AbsolutePath.Split('/');
string reportPath = "";
int length = path.Length;
for (int i = 1; i < length - 1; i++)
{
if (path[i] == "Reports")
{
for (int j = i; j < length - 1; j++)
{
reportPath += path[j] + "/";
}
}
}
rvEventListingByGroup.LocalReport.ReportPath = reportPath + "EventListingByGroup056.rdlc";
rvEventListingByGroup.LocalReport.Refresh();
}
Our report's .rdlc looks like this:
and the resulting output looks like this:
I have verified using SQL Server Profiler that when the Report Viewer loads the page, it is calling SQL Server with the correct parameters to return all of the necessary data, but the data isn't rendering on the page. I know there are no footers, nor are there any settings to manage paging, so it will always read "1 of 1" until I fix that, but what I'm expecting is a long page of (in our test case) 150 rows worth of raw data.
Can anyone offer suggestions as to what I could have missed in this?
Thank you so much in advance. We thought this would be a simple change, but since our Report Writer (staff member) left, we're on the hook for getting these changes made, in short order, without the requisite skills to back it up...
I found my answer, thanks to this link from social.msdn. I added SizeToReportContent="true" to my ReportViewer declaration in the .aspx file, and the output now rendered correctly in the Previewer. Without it, no content rendered, afterwards, it was all there!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
We are using new ASP.NET Web forms template in new VS 2012. Because we had some problems on IIS, with this error:
"System.Web.HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. ---> System.Web.UI.ViewStateException: Invalid viewstate."
Then we made this changes to web.config:
<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" enableViewStateMac="false" > ... </pages>
but, then we got the error: "Validation of Anti-XSRF token failed."
We then commented all the code in Site.Master.cs, regarding Anti-XSRF token validation (because site is used on intranet), however now we cannot login using IE (in Chrome and Firefox works), because after login (which is succesfull in log), it redirects to login page again, but the user is logged in.
UPDATE
I tried all of the solutions from here and it doesn't work: http://blogs.msdn.com/b/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx. Lastly, I tried also with: in web.config, but then i get the error: System.InvalidOperationException: Validation of Anti-XSRF token failed. Still, there is no solution.
UPDATE 2
Is there a proper way to disable Anti-XSRF token validation in new ASP.NET Web Forms template project ?
Instead of disactivaving all the security features of ASP.NET (which is NOT advised at all), you should rather focus on solving the actual error.
System.Web.HttpException (0x80004005): Validation of viewstate MAC failed is a common error. To solve it, you have to define a machinekey to use in your web.config file. This is usually due to the fact that you have two different keys across postback. Defining one in the web.config will most likely solve the issue (do not forget to reactivate security features like viewstate encryption).
You can generate one here: http://aspnetresources.com/tools/machineKey
See this post for an example: https://stackoverflow.com/a/6260201/375304 (but do NOT use the same key).
Also, have look at this link, it might be helpful to understand ASP.NET security features related to the machinekey.
http://msdn.microsoft.com/en-us/library/ff649308.aspx
UPDATE: If any of this doesn't work, try the following (source):
Another solution based on #3 above, special thanks to Alex for posting
this in the comments below. He wrote a small class called BasePage
that fixes the issues, so you just have to extend your page from
BasePage instead of Page:
public class BasePage : Page
{
private static string[] aspNetFormElements = new string[]
{
"__EVENTTARGET",
"__EVENTARGUMENT",
"__VIEWSTATE",
"__EVENTVALIDATION",
"__VIEWSTATEENCRYPTED",
};
protected override void Render(HtmlTextWriter writer)
{
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
base.Render(htmlWriter);
string html = stringWriter.ToString();
int formStart = html.IndexOf("<form");
int endForm = -1;
if (formStart >= 0)
endForm = html.IndexOf(">", formStart);
if (endForm >= 0)
{
StringBuilder viewStateBuilder = new StringBuilder();
foreach (string element in aspNetFormElements)
{
int startPoint = html.IndexOf("<input type=\"hidden\" name=\"" + element + "\"");
if (startPoint >= 0 && startPoint > endForm)
{
int endPoint = html.IndexOf("/>", startPoint);
if (endPoint >= 0)
{
endPoint += 2;
string viewStateInput = html.Substring(startPoint, endPoint - startPoint);
html = html.Remove(startPoint, endPoint - startPoint);
viewStateBuilder.Append(viewStateInput).Append("\r\n");
}
}
}
if (viewStateBuilder.Length > 0)
{
viewStateBuilder.Insert(0, "\r\n");
html = html.Insert(endForm + 1, viewStateBuilder.ToString());
}
}
writer.Write(html);
}
}
I've got the AjaxFileUpload control working just fine -- it uploads, and on completion calls the server-side code to move the files around, works just fine, etc etc etc.
What I'm worried about are potential server-side errors, and how to hand back some sort of warning to the user. Not an Ajax error, but something on the server-side code.
Now, I've got log4net running just fine, and it's called in my error-trapping code and merrily dumping logs when I hard-code an error.
But that doesn't tell the users anything.
RegisterStartupScript doesn't seem to be a valid solution, because there's no PostBack that would allow it to operate (same as my first attempt at populating fields. doh!).
Now, I can shove some JS into the ClientUploadComplete or ClientUploadCompleteAll to do a PostBack... but that doesn't seem right, and it would require that server-side error-messages be queued-up for display. Plus, it clears out the AjaxFileUpload display of what has been uploaded.
All the error-handling I've seen regarding these controls is for Ajax errors.
Is there anything for server-side issues that allows for easy feedback to the user?
Am I even barking up the right trees?
UPDATE Using the pointers # Yuriy's other answer I've got the following working:
Onn the server side:
protected void OnUploadComplete(object sender, AjaxFileUploadEventArgs e)
{
try
{
// does something with the uploaded files that _might_ fail
}
catch (Exception ex)
{
var ce = Logger.LogError(ex);
var msg = string.Format("{{ 'id': '{0}', 'message': '{1}'}}",
ce.ErrorId, ce.Message);
e.PostedUrl = msg;
}
}
(The Logger dumps the complete exception into a log4net log, and returns an error-number and consumer-friendly message to contact support)
Back on the page, the AjaxFileUpload control is configured to call the JS when complete:
<asp:AjaxFileUpload runat="server" ID="Uploader" MaximumNumberOfFiles="10"
OnUploadComplete="OnUploadComplete"
OnClientUploadComplete="AjaxFileUpload1_OnClientUploadComplete"/>
And the javascript:
<script type="text/javascript">
function AjaxFileUpload1_OnClientUploadComplete(sender, args) {
var errText = args.get_postedUrl();
if (!errText) return; // only process if populated
var errinfo = Sys.Serialization.JavaScriptSerializer.deserialize(errText);
if (errinfo && errinfo.id && errinfo.message) {
var idEl = document.getElementById('errnbr');
var msgEl = document.getElementById('errmsg');
if (idEl && msgEl) {
idEl.innerHTML = errinfo.id;
msgEl.innerHTML = errinfo.message;
}
}
}
</script>
which populates the following:
<div class="failureNotification" id="ErrorDisplay" runat="server">
<span id="errnbr"><asp:Literal ID="ErrorNumber" runat="server"></asp:Literal></span>
<span id="errmsg"><asp:Literal ID="FailureText" runat="server"></asp:Literal></span>
</div>
Although AjaxFileUploadState enumeration include Failed member I can't find any case where it used.
So there are two solutions available I believe.
The first is to tweak ACT project to add setters to State and StatusMessage properties of AjaxFileUploadEventArgs class and handle values of these properties on client in raiseUploadComplete function of Sys.Extended.UI.AjaxFileUpload.Control class and onUploadCompleteHandler of Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 class.
Or you can pass custom JSON to client via AjaxFileUploadEventArgs.PostedUrl property, deserialize it on client in OnClientUploadComplete handler and show error message if any. Please check this question for sample of usage PostedUrl property: getting asynfileupload controls file name on button click
I've got an ASP.NET webserver with IIS 7.
My authentication code (forms authentication) is as follows on the login page:
var isAuthenticated = Membership.ValidateUser(usernameTextBox.Text, passwordTextBox.Text);
if (isAuthenticated)
{
FormsAuthentication.RedirectFromLoginPage(usernameTextBox.Text, true);
}
else
{
var customValidator = new CustomValidator();
customValidator.IsValid = false;
customValidator.ErrorMessage = GetLocalResourceObject("LoginFailed.ErrorMessage").ToString();
customValidator.ValidationGroup = "AllValidators";
Page.Validators.Add(customValidator);
}
And on another page I display the username:
if (HttpContext.Current.User.Identity != null &&
!string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
{
string authenticatedUsername = HttpContext.Current.User.Identity.Name;
return "authenticatedUsername=" + authenticatedUsername;
}
else
{
return null;
}
My issue is that if me and one of my colleagues login at the same time with different login names (and different accounts), the accounts are set OK (we see different items) but one of the names is set to the other logged in user.
So if I login with username foo and my colleague with username bar, we will both be logged in with our respective accounts but either I will see the user name bar or he will see my username foo on the page.
I've seen some other accounts of strange behaviour of the ASP.NET authentication and they claimed it was fixed by disabling the output cache feature. It didn't work for me.
Any help appreciated, I've got no idea how to track the issue.
In the end the issue was with my code. I wanted to disable caching for the page and used the following
<%# OutputCache Duration="1" NoStore="true" VaryByParam="none" %>
which seemed to work and was mostly correct.
It wasn't complete though and the full version is
<%# OutputCache Duration="1" NoStore="true" Location="None" VaryByParam="none" %>
which works.
A posteriori it's fairly obvious waht happened. Although the client won't store the page, ASP will do so for one second if the Location isn't set to None.
The documentation on MSDN was really confusing form me for that topic.
I'm trying to implement something similar to this or this.
I've created a user control, a web service and a web method to return the rendered html of the control, executing the ajax calls via jQuery.
All works fine, but if I put something in the user control that uses a relative path (in my case an HyperLink with NavigateUrl="~/mypage.aspx") the resolution of relative path fails in my developing server.
I'm expecting:
http://localhost:999/MyApp/mypage.aspx
But I get:
http://localhost:999/mypage.aspx
Missing 'MyApp'...
I think the problem is on the creation of the Page used to load the control:
Page page = new Page();
Control control = page.LoadControl(userControlVirtualPath);
page.Controls.Add(control);
...
But I can't figure out why....
EDIT
Just for clarity
My user control is located at ~/ascx/mycontrol.ascx
and contains a really simple structure: by now just an hyperlink with NavigateUrl like "~/mypage.aspx".
And "mypage.aspx" really resides on the root.
Then I've made up a web service to return to ajax the partial rendered control:
[ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class wsAsynch : System.Web.Services.WebService
{
[WebMethod(EnableSession = true)]
public string GetControl(int parma1, int param2)
{
/* ...do some stuff with params... */
Page pageHolder = new Page();
UserControl viewControl = (UserControl)pageHolder.LoadControl("~/ascx/mycontrol.ascx");
Type viewControlType = viewControl.GetType();
/* ...set control properties with reflection... */
pageHolder.Controls.Add(viewControl);
StringWriter output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, false);
return output.ToString();
}
}
The html is correctly rendered, but the relative path in the NavigateUrl of hyperlink is incorrectly resolved, because when I execute the project from developing server of VS2008, the root of my application is
http://localhost:999/MyApp/
and it's fine, but the NavigateUrl is resolved as
http://localhost:999/mypage.aspx
losing /MyApp/ .
Of Course if I put my ascx in a real page, instead of the pageHolder instance used in the ws, all works fine.
Another strange thing is that if I set the hl.NavigateUrl = Page.ResolveUrl("~/mypage.aspx") I get the correct url of the page:
http://localhost:999/MyApp/mypage.aspx
And by now I'll do that, but I would understand WHY it doesn't work in the normal way.
Any idea?
The problem is that the Page-class is not intented for instantiating just like that. If we fire up Reflector we'll quickly see that the Asp.Net internals sets an important property after instantiating a Page class an returning it as a IHttpHandler. You would have to set AppRelativeTemplateSourceDirectory. This is a property that exists on the Control class and internally it sets the TemplateControlVirtualDirectory property which is used by for instance HyperLink to resolve the correct url for "~" in a link.
Its important that you set this value before calling the LoadControl method, since the value of AppRelativeTemplateSourceDirectory is passed on to the controls created by your "master" control.
How to obtain the correct value to set on your property? Use the static AppDomainAppVirtualPath on the HttpRuntime class. Soo, to sum it up... this should work;
[WebMethod(EnableSession = true)]
public string GetControl(int parma1, int param2)
{
/* ...do some stuff with params... */
var pageHolder = new Page() { AppRelativeTemplateSourceDirectory = HttpRuntime.AppDomainAppVirtualPath };
var viewControl = (UserControl)pageHolder.LoadControl("~/ascx/mycontrol.ascx");
var viewControlType = viewControl.GetType();
/* ...set control properties with reflection... */
pageHolder.Controls.Add(viewControl);
var output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, false);
return output.ToString();
}
The tildy pust the path in the root of the app, so its going to produce a the results you are seeing. You will want to use:
NavigateUrl="./whatever.aspx"
EDIT:
Here is a link that may also prove helpful...http://msdn.microsoft.com/en-us/library/ms178116.aspx
I find the /MyApp/ root causes all sorts of issues. It doesn't really answer your question 'why is doesn't work the normal way', but do you realize you can get rid of the /MyApp/ and host your website at http:/localhost/...?
Just set Virtual Path in the website properties to '/'.
This clears everything up, unless of course you are trying to host multiple apps on the development PC at the same time.
It might be that the new page object does not have "MyApp" as root, so it is resolved to the server root as default.
My question is rather why it works with Page.ResolveUrl(...).
Maybe ResolveUrl does some more investigation about the location of the usercontrol, and resolves based on that.
Weird, I recreated the example. The hyperlink renders as <a id="ctl00_hlRawr" href="Default.aspx"></a> for a given navigation url of ~/Default.aspx. My guess is that it has something to do with the RequestMethod. On a regular page it is "GET" but on a webservice call it is a "POST".
I was unable to recreate your results with hl.NavigateUrl = Page.ResolveUrl("~/mypage.aspx")
The control always rendered as <a id="ctl00_hlRawr" href="Default.aspx"></a> given a virtual path. (Page.ResolveUrl gives me "~/Default.aspx")
I would suggest doing something like this to avoid the trouble in the future.
protected void Page_Load(object sender, EventArgs e)
{
hlRawr.NavigateUrl = FullyQualifiedApplicationPath + "/Default.aspx";
}
public static string FullyQualifiedApplicationPath
{
get
{
//Return variable declaration
string appPath = null;
//Getting the current context of HTTP request
HttpContext context = HttpContext.Current;
//Checking the current context content
if (context != null)
{
//Formatting the fully qualified website url/name
appPath = string.Format("{0}://{1}{2}{3}",
context.Request.Url.Scheme,
context.Request.Url.Host,
(context.Request.Url.Port == 80 ? string.Empty : ":" + context.Request.Url.Port),
context.Request.ApplicationPath);
}
return appPath;
}
}
Regards,
It is hard to tell what you are trying to achieve without posting the line that actually sets the Url on of the HyperLink, but I think I understand your directory structure.
However, I have never run into a situation that couldn't be solved one way or another with the ResolveUrl() method. String parsing for a temporary path that won't be used in production is not recommended because it will add more complexity to your project.
This code will resolve in any object that inherits from page (including a usercontrol):
Page page = (Page)Context.Handler;
string Url = page.ResolveUrl("~/Anything.aspx");
Another thing you could try is something like this:
Me.Parent.ResolveUrl("~/Anything.aspx");
If these aren't working, you may want to check your IIS settings to make sure your site is configured as an application.