---
title: "How to call classic ASP from ASP.NET MVC5 controller?"  
description: "How to call classic ASP from ASP.NET MVC5 controller?"  
author: "Mark M"  
published: 2014-11-03  
updated: 2014-11-03  
canonical: https://www.mindstick.com/forum/2494/how-to-call-classic-asp-from-asp-dot-net-mvc5-controller  
category: "asp.net"  
tags: ["c#", "asp.net mvc", "http request"]  
reading_time: 3 minutes  

---

# How to call classic ASP from ASP.NET MVC5 controller?

## Hi Guys

I am migrating an old [classic](https://yourviews.mindstick.com/story/4536/10-best-classic-cars-brands) asp [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) over to [ASP.NET](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder), but as it is such a big old thing I am doing it in pieces. So I am at a stage where I need them to work together. The files for both classic asp and .NET are all in the same project. The old classic asp project uses [Session variables](https://www.mindstick.com/forum/386/retreive-data-from-bo-object-to-session-variables) (the new .NET project doesn't), so I am attempting to call a classic ASP page to do that.

## This is the classic asp "bridge":

```
<%'This file has global functions '%><%Dim userId : userId =CStr(Request.QueryString("userId"))Dim username : username =Cstr(Request.QueryString("username"))Dim objAccess : Set objAccess = new clsAccessDim objDb : Set objDb =  new clsDatabaseDim objUser : Set objUser = new clsUserDim objLogin : Set objLogin = new clsLoginDim objEntity : Set objEntity = new clsEntity'Set user session etc.if(Request.QueryString("function") ="session") then        Dim userRecord : Set userRecord =objUser.GetUserById(userId)     Dim rsEntity : Set rsEntity =objEntity.GetById(userRecord("EntityId"))    'Login classic asp : Sets the session variables.
               Call objLogin.LoginUser(userRecord, username,rsEntity) 'Kill the session i.e. Log outelseif(Request.QueryString("function") = "kill")
then    Session.Contents.RemoveAll()    Session.Abandon()       Response.Write("Session Killed")End if%>
```

However, I am having real problems being able to call this from the .NET [Controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) and get the session variables stored. I tried with a FileWebRequest:\

```
private void SetClassicASPSessionVars(ApplicationUser user)        {            try           
{                string url = "~/members/includes/classes/aspbridge.asp" + "?function=session&userId=" +
Url.Encode(user.UserId.ToString()) + "&username=" +Url.Encode(user.UserName);                Uri serverUri = new Uri(url);               
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverUri);               
request.Method = "POST";                 using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())               
{                   
StreamReader reader = new StreamReader(response.GetResponseStream());                    var content =reader.ReadToEnd();               
}           
}             catch (WebException we)           
{          
     throw new InvalidOperationException("Error logging in user to classic asp system. User: " + user.UserId + ".
Exception: " + we);           
}        }
```

\

This only read the file and didn't [execute](https://www.mindstick.com/interview/49/how-can-i-execute-a-php-script-using-command-line) the script, so it only returned the [source code](https://www.mindstick.com/forum/33476/pls-send-me-source-code-for-changing-passward-in-asp-dot-net-i-tried-so-much-from-google-but-its-not-workining) and didn't create the session variables.

## I've also tried with HttpWebRequest:

```
try           
{                string url= "/members/includes/classes/aspbridge.asp" + "?function=session&userId=" +
Url.Encode(user.UserId.ToString()) + "&username=" +Url.Encode(user.UserName);                Uri serverUri= new Uri(url, UriKind.Absolute);               
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverUri);   
            request.Method= "POST";                 using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())               
{                   
StreamReader reader = new StreamReader(response.GetResponseStream());                    var content= reader.ReadToEnd();               
}           
}             catch (WebException we)           
{                throw new InvalidOperationException("Error
logging in user to classic asp system. User: " +user.UserId + ". Exception: " + we);           
}
```

However, I get the error: Invalid URI: The format of the URI could not be determined.

Can someone please offer me some [guidance](https://answers.mindstick.com/qa/94097/which-missile-was-developed-under-a-p-j-abdul-kalam-s-guidance) how I can get the .NET controller to call the classic ASP page.

Thanks

## Replies

### Reply by Barbara Jones

The reason you're getting the URI error is because `WebRequest` does not send to requests to relative paths to your application, instead it needs an absolute path. It basically needs to reach URL's as a standard web browser would.

Therefore, make sure your URL has a full path/host:

```
string url = "http://localhost/members/includes/classes/aspbridge.asp" + "?function=session&userId=" + Url.Encode(user.UserId.ToString()) + "&username=" + Url.Encode(user.UserName);
```

\

I used `localhost` here as an example. You would want to set the host to the same host as the calling script obviously.


---

Original Source: https://www.mindstick.com/forum/2494/how-to-call-classic-asp-from-asp-dot-net-mvc5-controller

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
