Razor / WebMatrix syntax - C # question

In Windows Forms, I can create a class file called "Authentication.cs" with the following code:

public class Authentication
{
    public string Name;

    internal bool Authenticate()
    {
        bool i = false;
        if (Name == "Jason")
        {
            i = true;

        }
        return i;
    }
}

In WebMatrix, I can insert a new class file called "Authentication.cs" and paste the above code.

And in my default.cshtml file, I do this:

<body>
   @{
      Authentication auth = new Authentication();
      if(auth.Authenticated("jasonp"))
      {
         <p>@auth.Authenticated("jasonp");</p>
      }
   }
</body>

But that will not work! It works for a WinForms desktop application, but not in WebMatrix. I do not know why it does not work. Error message:

"Authenticate namespace does not exist. Are you sure you have reference assemblies, etc.?

So then at the top of my default.cshtml file I tried this:

@using Authentication.cs;

This led to the same error!

There is no documentation that I can find anywhere that tells me how to "include" a class file in WebMatrix pages.

Any help is appreciated

Thank!

+3
3

cs App_Code

-

    @{
      Authentication auth = new Authentication();
      if(auth.Authenticated("jasonp"))
      {
         <p>@auth.Authenticated("jasonp");</p>
      }
   }

.

, .dll,

@using NameSpace.Authenication

@{
    Authenticated auth = new Authenicated();

 }

 @if(@auth.Authenticated("jasonp"))
 {
    <p>@auth.Authenticated("jasonp")</p>
 }
+1

, . ; namespace Authentication ? :

@using My.Utils.Authentication.cs;

- ; :

<p>@auth.Authenticated("jasonp")</p>

:

   @{
      var auth = new My.Utils.Authentication();
      if(auth.Authenticated("jasonp"))
      {
         <p>@auth.Authenticated("jasonp")</p>
      }
   }

( : ?)

+2

Create a file called linkRef.cs code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


public class linkRef
{
   public  linkRef() {
        //
        // TODO: Add constructor logic here   
    //
   }
}

Put it in the App_code folder, and then in net net 2012 publish to bin, then download the bin folder

0
source

All Articles