Mixing Forms and Windows Security in ASP.NET --> in VB.net

Hi,

I searched for a mixed Logon (Form and Windows Security) and get some code in c#. I need the code in VB.net. Can anyone help?

I used this code:

 Mixing Forms and Windows Security in ASP.NET

http://msdn2.microsoft.com/en-us/library/ms972958.aspx

Thanks

 ml2h2

0
ml2h2
7/19/2007 7:51:02 AM
asp.net.security 27051 articles. 1 followers. Follow

7 Replies
1249 Views

Similar Articles

[PageSpeed] 18
Get it on Google Play
Get it on Apple App Store

There is no code in the link. If you need help in coding in vb.net from c#, i can assist you.

 

cheers


Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
0
naturehermit
7/19/2007 9:53:21 AM

naturehermit:

There is no code in the link. If you need help in coding in vb.net from c#, i can assist you.

The Code is in only in the .msi-File (Download the source code for this article).

Here are the (I thnik) relevant) codes:

Global.asax.cs:

 

using System;
using System.Web;
using System.Web.SessionState;

namespace Wilson.MixedSecurity 
{
public class Global : System.Web.HttpApplication
{
public const string ReturnUrl = "MixedSecurity.ReturnUrl";

protected void Application_Start(Object sender, EventArgs e) {}
protected void Session_Start(Object sender, EventArgs e) {}
protected void Application_BeginRequest(Object sender, EventArgs e) {}

protected void Application_AuthenticateRequest(Object sender, EventArgs e) {
if (!this.Request.IsAuthenticated) {
int start = this.Request.Path.LastIndexOf("/");
string path = this.Request.Path.Substring(start + 1);
if (path.ToUpper() != "WEBLOGIN.ASPX") {
this.Response.Cookies[Global.ReturnUrl].Value = this.Request.Path;
}
}
}

protected void Application_AuthorizeRequest(Object sender, EventArgs e) {}
protected void Application_EndRequest(Object sender, EventArgs e) {}
protected void Session_End(Object sender, EventArgs e) {}
protected void Application_End(Object sender, EventArgs e) {}
protected void Application_Error(Object sender, EventArgs e) {}
}
} 
 


WebLogin.aspx.cs

 

using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Wilson.MixedSecurity
{
public partial class WebLogin : System.Web.UI.Page
{

protected void Page_Load(object sender, System.EventArgs e) {
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e) {
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent() {    

}
#endregion

protected void Login_Click(object sender, System.EventArgs e) {
if (UserName.Text == Password.Text) {
string userName = UserName.Text;
FormsAuthentication.SetAuthCookie(userName, false);

string returnUrl;
if (this.Request.Cookies[Global.ReturnUrl] == null) {
returnUrl = this.Request.ApplicationPath;
}
else {
returnUrl = this.Request.Cookies[Global.ReturnUrl].Value;
}
this.Response.Redirect(returnUrl);
}
}
}
}
 

WinLogin.aspx.aspx.cs

 

using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Wilson.MixedSecurity
{
	public partial class WinLogin : System.Web.UI.Page
	{
		protected void Page_Load(object sender, System.EventArgs e) {
			string userName = this.Request.ServerVariables["LOGON_USER"];
			FormsAuthentication.RedirectFromLoginPage(userName, false);
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e) {
			InitializeComponent();
			base.OnInit(e);
		}
		
		private void InitializeComponent() {    
		}
		#endregion
	}
}

Ciao

 ml2h2

0
ml2h2
7/19/2007 10:08:17 AM

Do you want me to translate all of them in vb.net

?? :P


Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
0
naturehermit
7/19/2007 10:24:43 AM

naturehermit:

Do you want me to translate all of them in vb.net

?? :P

 that should be nice. I have no idea about c#

0
ml2h2
7/19/2007 10:47:21 AM
Imports System
Imports System.Web
Imports System.Web.SessionState

Namespace Wilson.MixedSecurity
	Public Class [Global]
		Inherits System.Web.HttpApplication
		Public Const ReturnUrl As String = "MixedSecurity.ReturnUrl"

		Protected Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
		End Sub
		Protected Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
		End Sub
		Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
		End Sub

		Protected Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
			If Not Me.Request.IsAuthenticated Then
				Dim start As Integer = Me.Request.Path.LastIndexOf("/")
				Dim path As String = Me.Request.Path.Substring(start + 1)
				If path.ToUpper() <> "WEBLOGIN.ASPX" Then
					Me.Response.Cookies([Global].ReturnUrl).Value = Me.Request.Path
				End If
			End If
		End Sub

		Protected Sub Application_AuthorizeRequest(ByVal sender As Object, ByVal e As EventArgs)
		End Sub
		Protected Sub Application_EndRequest(ByVal sender As Object, ByVal e As EventArgs)
		End Sub
		Protected Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
		End Sub
		Protected Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
		End Sub
		Protected Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
		End Sub
	End Class
End Namespace
 
 
Imports System
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Namespace Wilson.MixedSecurity
	Public Partial Class WebLogin
		Inherits System.Web.UI.Page

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		Private Sub InitializeComponent()

		End Sub
		#endregion

		Protected Sub Login_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			If UserName.Text = Password.Text Then
				Dim userName As String = UserName.Text
				FormsAuthentication.SetAuthCookie(userName, False)

				Dim returnUrl As String
				If Me.Request.Cookies([Global].ReturnUrl) Is Nothing Then
					returnUrl = Me.Request.ApplicationPath
				Else
					returnUrl = Me.Request.Cookies([Global].ReturnUrl).Value
				End If
				Me.Response.Redirect(returnUrl)
			End If
		End Sub
	End Class
End Namespace
 
 
 
 
Imports System
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Namespace Wilson.MixedSecurity
	Public Partial Class WinLogin
		Inherits System.Web.UI.Page
		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			Dim userName As String = Me.Request.ServerVariables("LOGON_USER")
			FormsAuthentication.RedirectFromLoginPage(userName, False)
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		Private Sub InitializeComponent()
		End Sub
		#endregion
	End Class
End Namespace
 

Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
0
naturehermit
7/19/2007 12:03:26 PM

Thanks  for the translation.

 But I have a Problem with the code.

The sections with #region ... #endregion don't work at my system. I get a runtime error.

  1. Compiler: BC30681: "#Region" tag have to be closed with  "#End Region"
  2. after using "#End Region" instead of "#EndRegion"
    Compiler: BC30217: String constant Expected
    Line:          #region Web Form Designer generated code

Sorry, I translated the error messages from a german version - so they sound a little bit strange.

Has anyone a hint how I can resolve this problem?

0
ml2h2
7/23/2007 6:41:29 AM

Remove all #region and #endRegion


Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
0
naturehermit
7/23/2007 8:09:20 AM
Reply:

Similar Artilces:

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

converting to vb.net from c#.net authorize.net
authorize.net offered me some sample code when I signed up with them the only problem is the sample code is in c#.net but my page that they type all of their credit card into is vb.net <code><%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <script language="C#" runat="server"> void Page_Load(Object Src, EventArgs E) { myPage.Text = readHtmlPage("https://certification.authorize.net/gateway/transact.dll"); } private String readHtmlPage(string url) { ...

Net:Net:Net::LDAP::FAQ
------_=_NextPart_001_01C6429F.D89AA417 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, Net::LDAP Net::LDAPS Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, ....) password? I don't like to write the secret password to the perl file. Best regards Barbara Wilbert ------_=_NextPart_001_01C6429F.D89AA417-- Wilbert Barbara (CI/OSI) * wrote: > Hello, > > Net::LDAP > Net::LDAPS > > Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, > ......

vb.net vs c#.net vs j#.net
just out of curiousity which looks, acts most like java? i'm still learning trying to used to vb.net but it seems that it was easier to do some stuff with java. C# is Java++ in my opinion. If you have done C or Jave you will prefer C#.Mike Schellenberger - MCAD If you are looking for language similar to java go for J#. However most code samples you find on the net will be in VB.NET and C#....

.NET Windows Forms in .NET Library Model
Hi, I downloaded C# 2.0 Library Model and I see that it does not contain Windows Forms classes (System.Windows.Forms namespace). Is there another library model for this? ...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

About VB.net And VC.net
I am always Programming With VB.net Recently My Teacher ask us to learn Vc or VC.net. I try to learn it and compare it with vb.net, I found it's much too complex than vb. However it is said vc is strongger than vb I want to know Why vc is strongger than vb? and is it hard too learn vc? I am new to asp.net Thanks for man who want to help me! Wuhan, Hubei, China Below links could give some info http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q308470Sreedharhttp://www.w3coder.orgweblog http://weblogs.asp.net/skoganti VisualC is not a language in an of itself...

C#.NET or VB.NET
what lang does everyone prefer? Thanks, Peter Iuvara, MCP It's a very famous debatable question in forums! I would say if you are from Java/C/C++, then C# would be easy to use for you. If you are from ASP/VB, then VB.NET would be easy for you! As long as if you follow CLS, then what ever the language you use, it's going to be the same for CLR!Sreedharhttp://www.w3coder.orgweblog http://weblogs.asp.net/skoganti I would agree with that ... just curious as to what user's on this forum predominantly code in?Thanks, Peter Iuvara, MCP I came from no real programming background, started i...

VB.Net To C#.Net
Hello... Since Last from 1 year i had develope web application in using vb.net now i want to transfer from vb.net to c#.net so what should i do to transform to c# language any link or book related to me through i can easily understand and coding using c# in a short time... Thanks~ Mark As Answer If UseFull ~Kaushal. Hi, you can read the specifications of the language. You're already familiar with .NET and how to program in an OO manner thanks to your experience with vb.net. The only thing you need to learn is the new syntax of C#. You can also convert parts of your v...

vb .net or c# .net
I currently develop websites using php but have been requested to develop a site using asp.net. The question I have is for someone who knows php would it be better to transition to vb.net or c#.net? Thanks, Fr. Robert C# -> There is a converter that will transition about 60% or more of your PHP code to C#. Plus C# is closer to PHP than VB.NET.Jason N. GaylordASPInsider and Microsoft MVPhttp://jasongaylord.com...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

Upgrade VB.net 2002 to VB.net 2003
Hi, i want to upgrade VB.net 2002 to VB.net 2003.what is the procedure?Uninstall 2002 and Install 2003 or something else? VB.net 2003 includes Framework 1.1 or i will install it separately?thanx in advance ...

Post form with data to a external site (.net 1.1 vb.net)
Hi I have now been googling for hours and I can not find a answer. :-( I am programming a e-shop (.net 1.1) and what I want to achive is: Customer fillout form, clicks on the Pay button then should the following thing happen: 1. Form date is saved to the database ( normal vb.net code ) 2. The data that should be posted to the external form is create from the saved data   ( normal vb.net code ) 2. A post is done to an external site with created data as "post" data and then user is redirected to this site. Thanks   Christian   Use the System.Net.HttpWebRequest...

Problems while porting .Net framework 1.0 (VB.Net) application to .Net Framework 1.1
Hello,   I have a ASP.Net web application,written in VB.Net,developed on .Net Framework 1.0 .I am trying to port it on to .Net framework 1.1.   For achieving this,I follow the following steps-   1.Open the project using the .vbproj file. 2.I am prompted with the conversion message "Do you want to convert the solution and all projects to .Net framework  1.1....." 3.I click "Yes" 4.I assume that the project is now converted. 5.I build the project & try to run it. 6.I get the following error -     Server Error in '/Consert.Net' Application. ...

WS-Security with VS.NET 2005 Web Service and .NET 1.1 Client
We ship a webservices client piece into the field which is required to run on the .NET 1.1 version of the framework, this is defined by our business people and cannot change. We would like to work with .NET 2.0 in VS.NET 2005 for the backend Web Service piece. We are able to get the 2 to communicate fine and it is not a problem. The issue now is that we need to introduce security through WS-Security. I have not been able to find much information about interop between the 2 environments and WS-Security and cannot get the security elements to be invoked in VS.NET 2005. Currently we are trying ...

Web resources about - Mixing Forms and Windows Security in ASP.NET --> in VB.net - asp.net.security

Krebs on Security
The House Financial Services Committee is slated to hold a hearing this Friday on the impact of cyber heists against small- to mid-sized businesses. ...

Security Middle East - Latest news from the Middle East.
Security Middle East is a news portal for the entire security industry, focussed specifically on latest security news from the Middle East. Security ...

Information Security News, IT Security News & Expert Insights: SecurityWeek.Com
IT Security News and Information Security News, Cyber Security, Network Security, Enterprise Security Threats, Cybercrime News and more. Information ...

Committee on National Security Systems - Wikipedia, the free encyclopedia
The National Security Telecommunications and Information Systems Security Committee (NSTISSC) was established under National Security Directive ...

'No more hostages' as security forces comb Mali hotel
Mali state television reports that at least 27 people were killed in assault on Radisson Blu Hotel. Malian, French and US security forces have ...

U.S. HTC One A9 to receive November security update imminently [Updated]
November security patch should get technical approval today and roll out immediately to U.S. unlocked A9s.

​Republican candidates talk religion, security at Iowa forum
CBS News ​Republican candidates talk religion, security at Iowa forum CBS News DES MOINES, Iowa Republican presidential candidates gathered ...

Lord of the Paranoids: New Yahoo security exec on protecting a billion-plus accounts
Bob Lord, Yahoo's new security chief, will lead a team called the Paranoids. Like all security executives, he has a tough job.

Patty Murray introduces Social Security expansion bill for women
Here’s further evidence of how far the debate on Social Security has come among elected Democrats in the last few years: Sen. Patty Murray, part ...

‘Before I Fall’ Adds Liv Hewson; Gabriella Wright Joins ‘Security’
Liv Hewson has joined the cast of director Ry Russo-Young's young adult fantasy-drama Before I Fall , the adaptation of the YA novel by Lauren ...

Resources last updated: 11/22/2015 5:51:37 AM