Solved

Redirect to a page in other folder

Posted on 2010-08-27
12
514 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

733 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