aspx.vb webform redirect to aspx.cs webform in another project within the same solution...and back a

  • Thread starter Thread starter Hazzard
  • Start date Start date
H

Hazzard

after developing in vb, I would like to utilize a login page and code behind
and helper files from a c# project.

i realize I can't add cs files to my vb project but is there a way to
redirect from a startup file immediately on Page_Load to the login.aspx with
the login.aspx.cs code behind after adding that c# project to the solution?
After authentication, I would like to redirect back to my asp.net vb based
project files.

thanks,
greg
 
Hi Greg,

Thanks for posting in the community!
Based on my understanding, you've a certain ASP.NET web page designed via
C#(using codebehind page class). Now, you are dealing with a VB.NET web
project and want to resue the C# based page. Since we can't use
multi-lanugage in a single project, you'd like to create a separate C#
webproject to hold the C# web page and let the page in different web
project navgiator to each other, yes?
If there is anything I misunderstood, please feel free to let me know.

As for this problem, here are my suggestions:
1. Every ASP.NET web project is actually a separate web application from
each other which has its own resources and intrinsic objects such as
AppliationState, SessionState.. They're very important things for a web
app. So If you put the C# page in a different web project, there'll cause
some problems if you'd like to share session or application state data
between them.

2. If you just want to reuse the page in the VB.NET project, here are two
means to still use it:
1) There are some web links where provide the service to translate the C#
code to vb.net or the contrary, if you only have not much pages to convert
or the code is not so complex, it is ok to translate them into vb.net. Here
is a web link to a convert service:
#C# to VB.NET Translator
http://authors.aspalliance.com/aldotnet/examples/translate.aspx

2) Since the ASP.NET web page is actually inherits from the codebehind page
class(if you use codebehind). You may find the "inherits=..." in the aspx
file's @page directive as below:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Index.aspx.vb"
Inherits="Codebehindclass's full name"%>

In fact, we can sepcify a page derived from an existing class avaliable in
the project(as long as we have referenced the class's assembly in our
project). Thus, we can create a C# class library project and compiled the
c# codebehind page class into a single assembly(dll) and then reference the
assembly in the VB.NET project. For example, we define the C# page class
named "MyCsPages.LoginPage", then we can specify a page in the VB.NET web
app to use the c# page class as below:
<%@ Page Language="vb" AutoEventWireup="false"
Inherits="MyCsPages.LoginPage"%>

Notice that no code-behind needed because we use a page class in a external
assembly as the page's parent class.
How do you think of this means? And here is a tech article in MSDN on
ASP.NET web page code model:

#Web Forms Code Model
http://msdn.microsoft.com/library/en-us/vbcon/html/vbconWebFormsCodeModel.as
p?frame=true

Please check out the above suggestions. If you feel anything unclear,
please feel free to post here.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Greg hi,

is that you ?

Technically you can use redirect but I wouldn't recommend doing so, its
better to write the page using vb.net.
1) The redirection from login page will return to a new instance of the
calling page.
2) You can transfer data between them just by using query string (it
better to use Form to transfer back to the calling page).
3) Redirect actually return to the client and redirect to the specified
address on the server. You are also moving across application domain.

If you want to create page that will serve both VB and C# applications
you can create your own base page with any language that you want that
handle login logic then create derived c# and VB visual pages to be used
in C# and VB projects.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Thank you Natty,

Yes, this is me! I hope you are doing fine!

I am interested in what you said;
If you want to create page that will serve both VB and C# applications
you can create your own base page with any language that you want that
handle login logic then create derived c# and VB visual pages to be used
in C# and VB projects.

I am not exactly clear what you mean by that.

I think you were right to recommend a rewrite of the C# into VB since most
of the project code is vb.net. I have done that before but sometimes I have
to ask myself why. It turns out it is more bothersome to handle the
redirects and an additional virtual iis instance than it is to rewrite. When
I thought more about it, I realized I was beginning to create the same kind
of bad solution I have often inherited from others in the past who were too
lazy to do it correctly to begin with.

Off to catch the ferry..... thx...... -greg
 
Thank you Steven. I am going to read this more carefully and I will remark
at that point. thx again. -greg
 
Steven,

Thank you for the link to the C# to VB Translator tool !!! Thanks to Alex
Lowe for providing that !

That makes all the difference in the world!

Greg
 
And thank you for the idea of using codebehind and referencing a dll which I
could create with the C# code. That is another option.
You gave me some ideas and I can decide which makes the most sense. For less
than a dozen or so methods, translate. For more, create the dll and
reference it. How does that sound for a rule of thumb?
-greg
 
Hi Greg,

Thanks for your followup. As for the using C# created class lib in VB.NET
project as reference, this is a very good approach which demonstrate the
multi-language interoperability. In fact, in dotnet each compact language
will be compiled into MSIL(Microsoft Intermedia language) which makes
multi-language can work with each other on component level. Do you think
so? Here are some tech articles on the related feature of dotnet:

#The Microsoft Intermediate Language: Not Just for TurboGeeks
http://msdn.microsoft.com/library/en-us/dnhcvs03/html/vs03k1.asp?frame=true

#Writing CLS-Compliant Code
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwritingcls-complia
ntcode.asp?frame=true

#Common Type System Overview
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcommontypesystemov
erview.asp?frame=true

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Back
Top