Solved

Redirect to a page in other folder

Posted on 2010-08-27
12
506 Views
Last Modified: 2012-05-10
Hi all,

How can I run the command Redirect to a page in another folder?

Clarifying. Suppose that I have a AA folder that contains the BB and CC subfolders. One ASP.NET page located in the directory and BB need redirect to another page in the folder CC. What is the correct command to do it?

It may be a simple question, but I'm struggling to solve it.

Thanks, Marcelo Camarate
0
Comment
Question by:Marcelo Camarate
  • 6
  • 6
12 Comments
 
LVL 30

Expert Comment

by:MlandaT
ID: 33546883
You could just start all redirects from the application root:

Response.Redirect("~/AA/CC/Page.aspx")

The special character "~" tells ASP.NET to just start from the root of the applicaiton which solves the problem
0
 

Author Comment

by:Marcelo Camarate
ID: 33547624
Hi MlandaT,

Thanks for your reply.

Sorry but, In the first message, I have not explained right my problem.

I am developing applications in ASP.NET using VB 2005. When I put the subfolders in the same Visual Studio (VS) project, all works OK. But, as my solution is composed of several systems, for organization reasons, I decided divide them into various designs VS. And that's my problem. When I redirect a page of another VS project don't work.

For a better understanding of my problem, I am attaching a small VS solution as an example.When I press the button "Go to Folder1 in the Same VS Project" on the Main Page, the browser goes to the page. But when I press the button "Go to other VS Project", a error window is shown, like below the image attached.

Can You help me, please?

Regards, Marcelo Camarate
RedirectTest.zip
Error.jpg
0
 
LVL 30

Expert Comment

by:MlandaT
ID: 33548400
For now... delete the <authentication mode="Windows" line in ALL web.config files from the SUB applications. I understand exactly what you are trying to do here. I do it a lot (in commercially deployed applications). For the error message in the image above, there are a few things you will need to keep in mind:

1) It is allowed to have more than a single web.config in an application, however, some settings cannot be put into the sub folder web.config files. They have to be in the main web.config.

2) You need to think about the "\bin" folders... when your applicaiton redirects to a sub folder application, .NET will expect to find ALL the necessary DLLs in the \bin folder of the topmost web application. Now, in order to get around this, you will need to add folders to the probingPath http://msdn.microsoft.com/en-us/library/823z9h8w.aspx

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="plugins;dependencies"/>
    </assemblyBinding>
  </runtime>
</configuration>

3) You will need to keep in mind that when in your sub-applicaitons, the "~" will behave differenty... it will refer to the topmost folder...

I haven't yet downloaded your sample app yet. I'll do that shortly.
0
 

Author Comment

by:Marcelo Camarate
ID: 33550694
hi MlandaT,

Thank ypu for your reply.

In relationship of your second orientation about the necessity of inclusion "probing privatePath"  parameters, what web.config file I need add it? The existent in the subfoldes, the topmost folder or all?

Regards, Marcelo Camarate
0
 
LVL 30

Expert Comment

by:MlandaT
ID: 33552422
Sorry for the late response... you need to add it to the topmost.
0
 

Author Comment

by:Marcelo Camarate
ID: 33553535
Hi MlandaT,

Thank you for your reply. I made your recommended changes in the topmost web.config file, but still occured an error, as the image attached.

I am attaching a new version of my VS solution example already with the changes in web.config file. Could you make a big favor? Download it, check what I'm doing wrong, and then return it changed? I appreciate it a lot.

Regards, Marcelo Camarate
Error.jpg
RedirectTest.zip
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 30

Expert Comment

by:MlandaT
ID: 33556398
Oops! I forgot to tell you one other extremely important bit... in all the *.aspx, *.ascx pages in the sub project, you will need to include this line right at the top:

<%@ Assembly Name="Project1" %>

I have done that in the project you sent and it's now working perfectly.
Redirect.zip
0
 

Author Comment

by:Marcelo Camarate
ID: 33557222
Hi MlandaT,

Thank you for your reply. It worked OK.

But, as my intention is to deployed commercial applications, will have more of a project subfolder. So, I changed the example solution to include one more project. And this is my current problems.

On the main page, when a call the Project 1, works OK. But, when I call the Project 2, gives the error "Could not load file or assembly 'Project2' or one of its dependencies. The system cannot find the file specified". I included the first line <%@ Assembly Name="Project2" %> in the Default.aspx file Project 2.

Please, what is my error now?

Regards, Marcelo Camarate
Redirect.zip
0
 
LVL 30

Expert Comment

by:MlandaT
ID: 33557341
<probing privatePath="Project1\bin"/>

should now include Project2

<probing privatePath="Project1\bin;Project2\bin"/>

I am unfortunately not aware of any other mechanisms to avoid having to do this apart from:

1) Copying all the files from the \bin folders of the sub applications into the topmost \bin folder (this actaully works quite well)
2) You should be able to create subfolders in the topmost \bin folder if you want to maintain segregation of the various individual project's files (I havent tried this)

3) You could also investigate the possibility of setting the probingPath programmatically... although much of my research indicated that this was not feasible since the probingPath is loaded right at the start of the loading of the appdomain and could not be modified... however... I did limited research on this and perhaps there are methods to achieve this.
0
 

Author Comment

by:Marcelo Camarate
ID: 33558169
Hi MlandaT,

I really forgot to add the Project2/bin folder in the "probing privatePath" parameter in the web.config file, and this mechanism isn't a problem for me.

But, have another problem with this mechanism. I don't know why, but the Sub Page_Load is not running when I pressing the buttons that called  Project 1 or Project 2 pages. That is, the pages are loaded without execute the Page_Load.

To demonstrate this problem, I am attaching the sample VS solution with a message about it.

Regards, Marcelo Camarate
Redirect.zip
0
 
LVL 30

Accepted Solution

by:
MlandaT earned 500 total points
ID: 33558487
Mine seems to be working.... Look here... I only now made it display the time in your label in the Page_Load. You will see that the time changes. I only changed Default.aspx.vb in first project.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.Label1.Visible = True
        Label1.Text = "Page Load was called at: " & Now.ToString("dd/MMM/yyyy HH:mm:ss")

    End Sub


Works like a charm!
RedirectTest.zip
0
 

Author Comment

by:Marcelo Camarate
ID: 33571805
Hi MlandaT,

Thanks for your reply.

Was not working before because I forgotten to publish the project. Now everything is working OK.

Again, thank you very much for your help. It was essential to solve my problem.

Regards, Marcelo Camarate
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Tabcontrol Caption? 1 24
JavaScript error 1 34
Form design in vb.net 7 20
Getfiles in vb.net 28 22
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now