Question

I want to use Response.Write() in VB.NET to redirect to relative Url. I am using the following code:

EDIT:

Response.Write(("account/msgbox.aspx?action=account&status=" & Convert.ToInt16(eAccountStatus).ToString))

Response.Write(("~/account/msgbox.aspx?action=account&status=" & Convert.ToInt16(eAccountStatus).ToString))

and

Response.Write(("/account/msgbox.aspx?action=account&status=" & Convert.ToInt16(eAccountStatus).ToString))

return the same in my case.

My application error event handler reports that the url being formed is invalid.

Here is what i am getting:

http://localhost:14154/~/http:/localhost:14154/account/msgbox.aspx?action=account&status=6

instead of this

http:/localhost:14154/account/msgbox.aspx?action=account&status=6

Response.Clear() before Response.Write() does nothing.

I cannot use/switch to Response.Redirect() now before the whole project uses Response.Write() and choosing to use Response.Redirect() will render all code useless that is written after Response.Write calls.

I just need clear the base url that is being appended somehow. Please let me know how may i achieve this.

Thanks you.

P.S: This code was working fine previously. Some developer made a change and now the Response.Write() is NOT causing the redirects as described above.

EDIT

Stack Trace:

System.Web.HttpException (0x80004005): The file '/~/account/msgbox.aspx' does not exist. at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) at System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) ::1 Details: http:// localhost:14154/~/account/msgbox.aspx?action=account&status=6

Was it helpful?

Solution 2

OK i solved the problem using this. Although i still need to understand how this works. but anyways i am posting it for anyone that run into similar problem.

Here is my new code.

Response.Write(("../account/msgbox.aspx?action=account&status=" & Convert.ToInt16(eAccountStatus).ToString))

OTHER TIPS

It looks like the code that sets baseUrl is setting it twice. If you can't find that, you could kludge this code onto it:

Response.Write((baseUrl.replace("http://localhost:14154/~/http:/localhost:14154/", _
    "http://localhost:14154/") & "account/msgbox.aspx?action=account&status=" & _ 
    Convert.ToInt16(eAccountStatus).ToString))

You are better-off fixing it at the origin (where baseUrl is being set).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top