Programing

ASP.NET MVC 5는 WebMatrix SimpleMembershipProvider와 호환되지 않습니까?

lottogame 2020. 11. 9. 07:37
반응형

ASP.NET MVC 5는 WebMatrix SimpleMembershipProvider와 호환되지 않습니까?


ASP.NET MVC 4 및 Web API에서 빌드 된 기존 응용 프로그램이 있습니다. 사이트의 관리자 부분은 Simple Membership을 사용합니다. 추가 된 새로운 기능 중 일부를 활용하기 위해 응용 프로그램을 MVC 5 / Web API 2로 업그레이드하는 데 관심이 있습니다. 그러나 호환되지 않는 것 같습니다.

특히 NuGet의 RC 패키지를 내 솔루션의 프로젝트 중 하나에 설치하고 web.config 정보를 업데이트 한 후WebSecurity.InitializeDatabaseConnection() 다음 예외를 제외하고 를 호출하는 줄에서 시작하는 동안 애플리케이션이 종료되기 시작합니다 .

[MethodAccessException: Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.OnConnectionOpened(System.Object, WebMatrix.Data.ConnectionEventArgs)' to access security critical method 'System.Web.WebPages.HttpContextExtensions.RegisterForDispose(System.Web.HttpContextBase, System.IDisposable)' failed.]
   WebMatrix.WebData.PreApplicationStartCode.OnConnectionOpened(Object sender, ConnectionEventArgs e) +70
   WebMatrix.Data.Database.OnConnectionOpened() +70
   WebMatrix.Data.Database.EnsureConnectionOpen() +51
   WebMatrix.Data.Database.QueryValue(String commandText, Object[] args) +63
   WebMatrix.WebData.DatabaseWrapper.QueryValue(String commandText, Object[] parameters) +13
   WebMatrix.WebData.SimpleMembershipProvider.GetUserId(IDatabase db, String userTableName, String userNameColumn, String userIdColumn, String userName) +206
   WebMatrix.WebData.SimpleMembershipProvider.ValidateUserTable() +87

업그레이드 하지 않은 Simple Membership을 사용하는 동일한 솔루션의 다른 프로젝트는 계속 정상적으로 작동합니다.

더 많은 정보를 얻기 위해 인터넷 검색을하면 물론 해당 예외에 대한 많은 히트가 나타나지만 WebMatrix에만 국한된 것은 아닙니다.

FWIW : Microsoft가 (아직 또 다른) 멤버십 및 ID 솔루션 을 도입했다는 것을 알고 있지만 기존 Simple Membership 테이블과 함께 사용할 방법이 없거나 기존 사용자 데이터 모두에 대한 원활한 마이그레이션 경로가없는 한 실제로는 옵션이 아닙니다. 우리를 위해.

업데이트 (10 월 11 일)

방금 앱의 현재 트렁크를 새로 확인하여 다시 시도했습니다. Visual Studio 2012를 사용하고 있지만 기존 프로젝트를 업그레이드하기 위해 MS의 지침을 따랐습니다. MVC 5 / Web API 2 / EF 6으로 업데이트 한 후 앱이 정상적으로 실행되었습니다.

web.config제거 할 에 명시적인 신뢰 요구 사항이 없습니다 . 나는의 코드를 추가 한 이 질문Global.asax.cs, 그리고 앱이 (VS에서 불과 F5-ED IIS 익스프레스에서) 완전 신뢰로 실행되고 있는지보고합니다.

에 동일한 호출을 다시 추가하면 InitializeDatabaseConnection()똑같은 예외로 죽기 시작합니다.

솔루션 (10 월 28 일)

금요일부터 @Kevin의 업데이트에서 솔루션을 시도해 보니 작동한다는 것을 알았습니다. 관련이없는이 패키지를 추가하면 이러한 보안 문제를 해결할 수 있다는 것이 정말 이상 했습니다 . 솔루션에서 패키지를 제거하고 계속 작동 한 후에 더욱 이상 했습니다 .

무슨 일이 일어 났는지 자세히 살펴보면, 나는 깨달았다 그 이유는이 수정 동작은 매우 간단합니다 Microsoft.AspNet.WebHelpers패키지 내 솔루션에 추가 된 두 개의 종속성이 : Microsoft.AspNet.WebPages.DataMicrosoft.AspNet.WebPages.WebData. Microsoft는 WebMatrix 클래스를 새 패키지로 이동했습니다.

그래서 헬퍼 패키지를 추가하면 문제가 해결되었습니다. 그 이유는 무엇을 하느냐가 아니라 손상된 어셈블리의 업데이트 된 버전이 내 솔루션에 추가 되도록 했기 때문 입니다. 초기 비 호환성에 대한 해결책은 NuGet에서 다른 모든 항목을 업데이트 할 때 이러한 새 패키지를 설치하는 것입니다.

Install-Package Microsoft.AspNet.WebPages.WebData

업데이트 (2015 년 5 월 13 일)

이 된 나에게 제안 당신은 수동으로 두 번째 새 패키지를 설치해야 할 수도 있습니다 :

Install-Package Microsoft.AspNet.WebPages.Data

패키지는 첫 번째 패키지 의 명시 적 종속성 이고 NuGet은 둘 다 설치할 수있을만큼 스마트해야 하므로 필요 하지 않습니다 . 당신이 얻을하지만 빌드 할 때 오류 , 또는 NuGet가 종속성을 추가 표시되지 않습니다, 그것은 당신을 도움이 될 수 있습니다.


WebMatrix는 MVC 5와 호환됩니다.

내가 한 일은 빈 MVC 5 프로젝트를 가져 와서 MVC 애플리케이션에서 SimpleMembership분리 하는 오픈 소스 프로젝트 인 SimpleSecurity를 사용하여 WebMatrix SimpleMembershipProvider를 여기에 통합하는 것이 었습니다 . 지금까지 데이터베이스를 만들고 시드하고 로그인 및 로그 아웃 할 수있었습니다. 이 참조 애플리케이션에 이메일 확인 및 다양한 테스트와 같은 다른 기능을 추가 할 계획입니다. 완료되면 SimpleSecurity 프로젝트에 소스 코드를 게시합니다.

추측해야한다면 업그레이드 프로세스에 문제가있을 수 있습니다. MVC 4 프로젝트를 MVC 5로 업그레이드하기 위해 어떤 프로세스를 수행 했습니까? 이 과정을 따랐습니까 ? 어떤 버전의 WebMatrix 어셈블리를 사용하고 있습니까? 어떤 버전의 Visual Studio를 사용하고 있습니까? WebMatrix 및 Visual Studio 2013 RC 버전 2.0.0.0을 사용하고 있습니다.


업데이트 (2013 년 10 월 25 일)

나는 MVC 5 프로젝트에 SimpleMembership을 추가하는 실험을 계속했고 어딘가에 그것이 깨졌고 @Sixten Otto와 같은 결과를 얻었습니다. 추가로 점진적으로 테스트하지는 않았지만 Web API 어셈블리를 설치할 때 발생했을 수 있습니다. 새 MVC 5 프로젝트를 만들 때 기본적으로 설치되지 않습니다.

오류에 대해 좀 더 조사한 결과 " Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start ()' " 라는 제목의이 QA를 발견했습니다 . 이것은 오래된 QA이며 원래 누군가 MVC 3 앱을 MVC 4로 업그레이드 할 때 이와 동일한 오류가 발생했습니다. 그러나 최근 사람들은 MVC 5로 업그레이드하는 것과 관련하여 답변을 추가하고 있으며 그 중 하나가 저에게 도움이되었습니다. 나를위한 해결책은 NuGet 패키지 Microsoft.AspNet.WebHelpers를 설치하는 것이 었습니다 . 이 패키지를 설치 한 후 모든 것이 잘 작동했습니다.

새 ASP.NET ID 로의 마이그레이션에 대한 내 연구에 대한 참고 사항은 동일한 암호 해시를 사용하지 않기 때문에 이전 멤버를 ASP.NET ID에서 사용하는 데이터베이스로 이동할 수 없다는 것입니다. ASP.NET Identity는 현재 실제 유동적 인 것처럼 보이므로 아마도 이에 대한 해결책을 제시 할 것입니다.


업데이트 (2014 년 2 월 16 일)

I erroneously reported that the hash algorithm for passwords was different in SimpleMembership and ASP.NET Identity. I assumed this based on a visual inspection of the hashed passwords, assuming that it was just the hashed password that was in the fields. After further research I found that SimpleMembership uses the System.Web.Helpers.Crypto class for hashing the password and what is stored in the password field is actually a 256 bit subkey and the salt. With that information I ran some tests to validate that ASP.NET Identity can verify passwords that are generated by SimpleMembership, and it passed. I was trying to find out what hash algorithm SimpleMembership used so I could plug in a password hasher in ASP.NET Identity that would allow me to migrate data from a SimpleMembership webiste to one that used ASP.NET Identity. Turns out it is not necessary. 이 기사에서는 암호 해시와 SimpleMembership에서 ASP.NET Identity로 데이터를 마이그레이션하는 방법에 대해 자세히 설명 합니다.


오류가 발생하는 경우

보안 투명 메서드 'WebMatrix.WebData.PreApplicationStartCode.Start ()'로 보안 중요 메서드 'System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport (System.String)'에 액세스하지 못했습니다.

이 문제를 해결하려면 NuGet 패키지 관리자를 사용하여이 패키지를 설치하세요.

Install-Package Microsoft.AspNet.WebHelpers

그 후에 아마도 다른 오류가 발생할 것입니다.

WebMatrix.Data 버전 3.0.0.0 어셈블리를로드 할 수 없습니다.

이 패키지를 수정하려면 NuGet 패키지 관리자를 사용하십시오.

Install-Package Microsoft.AspNet.WebPages.Data

현재 Simple Membership에서 ASP.NET Identity로 마이그레이션하기위한 마이그레이션 문서를 작성 중입니다. 이 마이그레이션 문서를 푸시 할 때까지 몇 주 동안 계속 지켜봐 주시기 바랍니다. 지금은 Simple Membership 스키마를 Identity에 매핑하고 SignIN / SIgnOut에 OWIN을 사용하도록 응용 프로그램 코드를 변경해야합니다.


위의 답변은 최근 웹 페이지까지 작동하지 않았습니다. 3.2.3. 새로운 문제가 나타났습니다. 나를위한 현재 수정 사항은 .Net 4.5.3으로 업그레이드하는 것입니다. 나는 이것을 좌절감에서 알아 냈다. 이 문제는 MVC 5뿐만 아니라 웹 페이지 3.2.3으로 업그레이드 한 후에도 핵심 Webmatrix 프로젝트에 영향을 미칩니다. 새로운 Microsoft Identity로 수정 될 프레임 워크 문제라고 생각합니다. 나를위한 현재 수정 사항은 다음과 같습니다. 참고 : Visual Studio의 속성 페이지 마법사를 사용하여 대상 프레임 워크를 .Net Framework 4.5.3으로 변경하십시오. web.config를 업데이트합니다.

<compilation debug="true" targetFramework="4.5.3">
  <assemblies>
    <add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  </assemblies>
</compilation>

1 단계 : Microsoft.AspNet.WebHelpers 설치-패키지

2 단계 : Microsoft.AspNet.WebPages.Data 패키지 설치

3 단계 : [선택 사항] 설치 패키지 Owin

4 단계 : 속성 페이지 대화 상자를 통해 targetFramework를 .Net 4.5.3으로 변경

여기에 이미지 설명 입력

[선택 사항] Web.Config는 다음과 같아야합니다.

    <?xml version="1.0"?>

<configuration>
  <appSettings/>
  <connectionStrings>
    <add connectionString="Server=XTREMEGOSPEL;Database=portfolioDB;Trusted_Connection=True" name="portDB" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <!--
    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5" />
      </system.Web>
  -->
  <system.web>
    <compilation debug="true" targetFramework="4.5.3">
      <assemblies>
        <add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5" maxRequestLength="2097151"/>
    <authentication mode="Forms">
      <forms timeout="1440"/>
    </authentication>
    <sessionState timeout="1440"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="4294967295"/>
      </requestFiltering>
    </security>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

내 로컬 컴퓨터가 아니라 라이브 사이트에서 같은 문제가 발생했습니다.

웹 구성에서 아래 줄을 제거했으며 현재 작동 중입니다.

<dependentAssembly>
   <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
   <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>

참고 URL : https://stackoverflow.com/questions/19169846/is-asp-net-mvc-5-incompatible-with-the-webmatrix-simplemembershipprovider

반응형