LoginController와 RegisterController라는 두 개의 컨트롤러가 있고 'public static string Encrypt (string toEncrypt, bool useHashing)'함수가 RegisterController에 정의되어 있습니다 .LoginController에서 동일한 이름을 어떻게 호출 할 수 있습니까?
var result= new RegisterController().Encrypt(newpass, true);
코드를 사용 했지만 결과 : 오류 4 멤버 'AP.WebApp.Controllers.RegisterController.Encrypt (string, bool)'은 인스턴스 참조로 액세스 할 수 없습니다. 대신 유형 이름으로 한정
상속으로이 문제를 해결할 수 있습니다.
예:
public abstract class BaseController : Controller
{
//Common functionality between controllers go here
protected static string Encrypt(string toEncrypt, bool useHashing)
{
//Your content
}
}
public class LoginController : BaseController //not Controller anymore
{
//Encrypt is now available
//...Your controller methods here
}
public class RegisterController : BaseController //not Controller anymore
{
//Encrypt is now available
//...Your controller methods here
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다