How to create a classic asp page for using the asp.net mvc core 6 component/widget ?

mehmood tekfirst 771 Reputation points
2022-11-28T07:17:36.98+00:00

Hi,

Hi,

I had developed an application in Asp.Net MVC Core 6 (.Net 6). Now I need to use the classic asp page to call my asp.net mvc core 6 components/widget.

If I use simple .html page then everything is working as expected but when I rename the page with extension .asp then browser throw this error.

Please see below

264662-image.png

If you want to see my files hierarchy then please look into the below picture

264608-image.png

and this is the actual rental.asp page source.

<!DOCTYPE html>  
<html lang=en>  
<head>  
    <meta charset="UTF-8">  
    <meta name="viewport" content="width=device-width, initial-scale=1.0">  
    <title>test.</title>  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
</head>  
<body>    
  
    <div id="wrapper">  
            <!-- Main Content -->  
            <div class="maincontentwrapper" style="overflow:auto;">  
                <div class="maincontenthome">  
                    <div class="page-information">  
                        <br /><br />  
                              <div id="CarWidget">  
                                  <script>  
                                      function loadCarWidget() {                                            
                                          var getcurrentPagePath = window.location.href;  
                                          if (getcurrentPagePath) {  
                                              $.ajax(  
                                                  {  
                                                      url: "https://localhost:7177/paramvehicle?path=" + getcurrentPagePath, type: "GET", dataType: 'text'  
                                                      , success: function (result) {  
                                                          //debugger;  
                                                          $("#CarWidget").html(result);  
                                                      },  
                                                      error: function (jqXHR, exception) {  
                                                          var msg = '';  
                                                          if (jqXHR.status === 0) {  
                                                              msg = 'Not connect.\n Verify Network.';  
                                                          } else if (jqXHR.status == 404) {  
                                                              msg = 'Requested page not found. [404]';  
                                                          } else if (jqXHR.status == 500) {  
                                                              msg = 'Internal Server Error [500].';  
                                                          } else if (exception === 'parsererror') {  
                                                              msg = 'Requested JSON parse failed.';  
                                                          } else if (exception === 'timeout') {  
                                                              msg = 'Time out error.';  
                                                          } else if (exception === 'abort') {  
                                                              msg = 'Ajax request aborted.';  
                                                          } else {  
                                                              msg = 'Uncaught Error.\n' + jqXHR.responseText;  
                                                          }  
                                                          $('#CarWidget').html(msg);  
                                                      },  
                                                  });  
                                          }  
                                      };  
                                      loadCarWidget();  
                                  </script>  
                              </div>                          
                    </div>  
                </div>  
            </div>  
        </div>  
</body>  
</html>  

What are the steps which are required to use classic asp pages in this way ?
Please correct me and guide me.
Thank You

Developer technologies ASP.NET ASP.NET Core
{count} votes

1 answer

Sort by: Most helpful
  1. mehmood tekfirst 771 Reputation points
    2022-11-30T13:07:01.543+00:00

    Sure, I added following in my Widget source

    What I did is to keep a flag in appsettings.json ?

    {  
      "Logging": {  
        "LogLevel": {  
          "Default": "Information",  
          "Microsoft": "Warning",  
          "Microsoft.Hosting.Lifetime": "Information"  
        }  
      },  
      "AllowedHosts": "*",  
      "CustomSettings": {     
        "IsDeploymentMode": "local"  
      }  
    }  
    

    Added in Index.cshtml view

      string isLocal = @Configuration["CustomSettings:IsDeploymentMode"];  
    
    @section Scripts{  
        <script type="text/javascript">         
            var isLocal = '@isLocal';  
         
        </script>  
    }  
    

    and added these lines in my JavaScript plugin

     let localPathUrl = new URL(appPath);                 
     let enquiryPathUrl = localPathUrl.pathname.replace(isLocal !== "local" ? 'rental.asp' : 'rental.html', '');  
     window.location = enquiryPathUrl;  
    

    This work for both my local machine/project and for QA server.

    I just need to change for Live Server

     "IsDeploymentMode": "live"  
    

    Thank you everyone


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.