Swagger UI를 Nuget에서 받아보시면, App_Start 에 SwaggerConfig.cs가 생깁니다.

그 cs 파일에 Register 함수 안에 기본(Basic) 인증,  Api key , oAuth2 세 가지 인증(Authoirze) 구성이 있습니다.

저는 Swagger 페이지만 안들어가게 하고 싶을 뿐이였고, 사이트는 기본 인증을 베이스로 관리 페이지를 만들었습니다. Swagger Ui는 아래와 같은 URL로 만들어집니다.

http://{host}/swagger/ui/index

만약에 이 페이지를 못 들어가게 하고 싶다면 web.config에 아래와 같이 구성해주시면 됩니다.

<allow roles="{허용할 Role}"> // 기본인증 된 Role 중에 허용할 Role을 넣으시면 됩니다.

<deny users="*"> //모든 유저를 금지한다는 의미

<configuration>
  <location path="swagger">
    <system.web>
      <authorization>
        <allow roles="api"/> 

        <deny users="*"/> 
      </authorization>
    </system.web>
  </location>
</configuration>



Posted by Hoya0415
,


1. 내 문서 경로\IISExpress\config\applicationhost.config 을 편집으로 파일을 연다.


2. 단어 검색으로 <sites>부분을 검색하고


  <site name="프로젝트이름" id="3">

                <application path="/" applicationPool="Clr4IntegratedAppPool">

                    <virtualDirectory path="/" physicalPath="H:\프로젝트이름" />

                </application>

                <bindings>

                    <!--<binding protocol="http" bindingInformation="*:58665:localhost" />-->

                     <binding protocol="http" bindingInformation="*:58665:" /> 

                </bindings>

  </site>


Visual Studio  생성한 웹 사이트 주소를가 Site 태그에 있을 것이다.


물리적주소 physicalPath도 보인다


그리고 <binding 태그를 보면 원래는 bindingInformation 이 부분이 아래와 같은데 


 <!--<binding protocol="http" bindingInformation="*:58665:localhost" />-->


바꿔주면 된다.


<binding protocol="http" bindingInformation="*:58665:" /> 


바꾼 후 관리자 모드로 Visual Studio를 켜고 프로젝트를 불러와서 실행해보면 


외부 IP로도 접근이 가능하다.


※추가※

만약 위에 사항해도 안된다면 

방화벽은 해제와 고급 보안이 포함된 윈도우 방화벽에서 인바운드 포트를 열어주면 된다.


Posted by Hoya0415
,

IIS에서 PUT DELETE가 안될 때 Method Not Allowed 405

WEB API 에서 DELETE Method 만들고, 로컬에서 테스트 할 때는 정상적으로 작동하지만,

IIS 서버에 호스팅하게 되면, 안될 수 가 있다. HTTP Method에 제한이 걸려있을 텐데

Handler Mapping에서 WebDav 쪽에 Method가 제한되



IIS Handler Mapping -> WebDAV를 찾는다..



요청 제한 버튼을 클릭한다.


동사 탭을 선택 후 모든 동사들 체크해서 확인 누른다.





<handlers>
  <remove name="WebDAV" />
  <add name="WebDAV" path="*" verb="*" modules="WebDAVModule" resourceType="Unspecified" requireAccess="None" />
</handlers>

그리고 위에 구문을 Web.config에 써주면 된다. 
IIS를 재실행하자


Posted by Hoya0415
,

나는 Empty Web Project를 만들어서, MVC를 시도하고 있다. 

index 페이지로 이동 하던 중에 ViewBag가 작동하지 않는다.

이유는 Views라는 폴더 밑에 Web.config 라는 파일을 내가 생성해주지 않았기 때문이다.


저 파일을 생성하주면 된다.


내용 Web.config 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?xml version="1.0"?>
 
<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>
 
  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <!--<add namespace="System.Web.Optimization"/>-->
        <add namespace="System.Web.Routing" />
        <add namespace="MoccozyProject" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
 
  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>
 
  <system.webServer>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
 
  <system.web>
    <compilation>
      <assemblies>
        <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
  </system.web>
</configuration>
 
 
cs


Posted by Hoya0415
,

overall 

http://www.asp.net/media/4071077/aspnet-web-api-poster.pdf


formats of model Binding

http://www.asp.net/web-api/overview/formats-and-model-binding


Self Hosting

http://www.asp.net/web-api/overview/older-versions/self-host-a-web-api


About WebApiConfig Class

http://www.asp.net/web-api/overview/advanced/configuring-aspnet-web-api


Routing 

http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api


Message handler

http://www.asp.net/web-api/overview/advanced/http-message-handlers


Model Validation

http://www.asp.net/web-api/overview/formats-and-model-binding/model-validation-in-aspnet-web-api


.NET CLIENT CALLING

http://www.asp.net/web-api/overview/advanced/calling-a-web-api-from-a-net-client


WEB API NINJECTION

http://www.asp.net/web-api/overview/advanced/dependency-injection

unit testing 

http://www.asp.net/web-api/overview/testing-and-debugging/unit-testing-with-aspnet-web-api


'.NET 개발 > ASP.NET Web API' 카테고리의 다른 글

Method Not Allowed 405 on IIS  (0) 2015.12.18
@ViewBag is Not Working  (0) 2015.12.07
Asp.Net Configuration Tool In Visual Studio 2013  (0) 2015.07.15
aspnetdb 생성  (0) 2015.07.14
IPrincipal 와 Identity  (0) 2015.07.14
Posted by Hoya0415
,

안녕하세요 . 오늘 포스팅은 Visual Studio 2010에서 지구 아이콘 혹은 메뉴에 Project에 Asp.net configuration Tool을 이용하였던 것인데 Visual Studio 2013 에서는 위에 말씀드린 것들이 없어 졌습니다. 그래서 IIS Express를 이용하여 해당 프로젝트가 있는 WEB 프로젝트의 절대 경로 를 설정해주어야 접속이 가능합니다.

1. 우선 명령 프롬프트를 실행합니다.

2. IIS Express가 있는 폴더 지정 위치로 이동합니다.

C:\Program Files (x86)\IIS Express

3. 명령 프롬프트에 IIS Express를 실행하면서 Port 설정을 하는데 이 {PORT}는 여러분이 안쓰시는 (Free) 한 Port를 써주시면 됩니다.

iisexpress.exe /path:C:\Windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles /vpath:"/ASP.NETWebAdminFiles" /port:{PORT} /clr:4.0 /ntlm /trace:error


4. 위에서 지정한 포트로 IIS Express가 실행되면서 호스팅 되는 것을 볼 수 있습니다. 그리고 나서 아래의 주소를 쳐주면 됩니다.

 http://localhost:{PORT}/asp.netwebadminfiles/default.aspx?applicationPhysicalPath={Absolutely Route}&applicationUrl=/


{PORT}는 위에서 지정한 포트로 IIS Express가 실행

{Absolutely Route} 절대 경로는 예를 들어 해당 프로젝트의 웹쪽 경로를 주면 됩니다. 특정 파일이 아닌 경로입니다.

"C:\Users\HP\Source\Company\Sample\Sample.Web"


5. 아래와 같은 Asp.net configuration Tool가 나타날 것이다.


6.이제 WebConfig 파일에 연결한 DB가 정상적으로 연결되었는지 확인을 해주면 된다.

여기까지!^^

'.NET 개발 > ASP.NET Web API' 카테고리의 다른 글

@ViewBag is Not Working  (0) 2015.12.07
ASP.NET API 부수적으로 알아야할 기능들.  (0) 2015.12.06
aspnetdb 생성  (0) 2015.07.14
IPrincipal 와 Identity  (0) 2015.07.14
인증 및 권한 부여  (0) 2015.07.14
Posted by Hoya0415
,

Aspnet_regsql.exe 라는 프로그램을 실행하면 아래의 설치 마법사가 나온다.

1. 다음을 눌러준다.

2. Configure SQL Server for application services 를 클릭해준다.


3. DB Server에 연결해준다.


위와같이 해주면 해당 데이터베이스 서버에 ASPNETDB가 생성된다.


아래는 sql 구문이다.

sql 구문을 실행해주면 자동으로 데이터베이스가 생성된다.

aspnetdbModel.edmx.sql


Posted by Hoya0415
,

역활 기반 보안은 .Net Framework 1.0 부터 사용해왔다. Identity 와 Iprincipal 은 역할 기반 보안을 구현하기 위해 .Net Framwork 에서 제공하는 두 가지 추상적인 개념이다.

(그림: IPrincipal 그리고 IIdentity 구현된 클래스)

사용자 정의 시나리오를 위한 GenericIdentity와 GenericPrincipal 클래스.

윈도우 인증 기반의 시나리오를 위한 WindowIdentity와 WindowPrincipal 클래스 

IPrincipal 인터페이스 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    // Summary:
    //     Defines the basic functionality of a principal object.
    [ComVisible(true)]
    public interface IPrincipal
    {
        // Summary:
        //     Gets the identity of the current principal.
        //
        // Returns:
        //     The System.Security.Principal.IIdentity object associated with the current
        //     principal.
        IIdentity Identity { get; }
 
        // Summary:
        //     Determines whether the current principal belongs to the specified role.
        //
        // Parameters:
        //   role:
        //     The name of the role for which to check membership.
        //
        // Returns:
        //     true if the current principal is a member of the specified role; otherwise,
        //     false.
        bool IsInRole(string role);
    }
cs

Identity 인터페이스 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 // Summary:
    //     Defines the basic functionality of an identity object.
    [ComVisible(true)]
    public interface IIdentity
    {
        // Summary:
        //     Gets the type of authentication used.
        //
        // Returns:
        //     The type of authentication used to identify the user.
        string AuthenticationType { get; }
        //
        // Summary:
        //     Gets a value that indicates whether the user has been authenticated.
        //
        // Returns:
        //     true if the user was authenticated; otherwise, false.
        bool IsAuthenticated { get; }
        //
        // Summary:
        //     Gets the name of the current user.
        //
        // Returns:
        //     The name of the user on whose behalf the code is running.
        string Name { get; }
    }
cs



Posted by Hoya0415
,

인증은 엔티티의 신원을 검색한다.

자격증명은 유효성 검사를 통해 신원을 확인하는 프로세스다.

권한 부여는 현재 신원 정보로 요청된 작업을 수행할 수 있는지 여부를 결정하는 프로세스다.

역활 기반 보안은 접근 제어를 위한 비즈니스 또는 엔터프라이즈 응용프로그램에서 사장 일반적으로 사용되는 보안 모델.

Identity 및 principal 개체는 역할 기반의 보안을 구현하기 위하여 .Net Framework에서 제공하는 추상적인 개념.

사용자 정의 시나리오를 위하여, Net. Framework 4.5의 GenericIdentity와 GenericPrincipal 클래스를 사용할 수 있다. 또 WINDOW 인증을 위해서 WindowsIdentity와 WindowsPrincipal 클래스를 사용할 수 있다.

클레임 기반 보안 모델에서 사용자는 응용프로그램에 자격증명을 제공하지 않고 단지 클레임만 제공한다.

역활 기반의 접근 제어와 클레임 기반의 접근 제어의 근본적인 차이점은 역할 기반의 접근 제어를 위해서는 반드시 사용자를 작업을 수행할 수 있는 권한이 있는 역할에 할당해야 한다는 것이고, 반면에 클레임 기반의 접근 제어를 위해서는 사용자가 권한을 부여 받을 수 있도록 응용프로그램이 확인할 수 있는 올바른 값으로 클레임을 제공해야 한다는 것이다. 클레임 기반의 접근 제어가 좀 더 제어하기가 쉽고 유지 관리 또한 쉽다.

클레임은 보안 토큰의 형태로 발급 기관에 의해 응용프로그램에 발급된다. 보안 토큰은 기본적으로 서명디어 있고 보안 전송을 위해 암호화 처리된 클레임의 집합이다.  보안 토큰은 Security Assertion Markup Language(SAML), Simple Web Token(SWT),  JSON Web Token(JWT) 세 가지 유형이 있다.


출처: 프로 ASP.NET 웹 API 보안 책.

Posted by Hoya0415
,

1. WebApiConfig에서 Route 설정하기 

App_Start 에서 WebApiConfig 파일에서 아래의 소스와 같이 만들어주면 된다.

students라는 ApiController가 있는데 routeTemplate을 바꿀 수 있다.

1
2
3
4
5
   config.Routes.MapHttpRoute(
                name: "students",
                routeTemplate: "api/students/{userName}",
                defaults: new { controller = "students", userName = RouteParameter.Optional }
            );
cs


2. Method Route 설정하기

1
2
3
4
5
6
7
public class UserIdCheckController : ApiController
    {
 
        [Route("User/{id}")]
        public int GetIdCheck(string id)
        {
        }
cs

메서드 마다 강제로 주소를 바꿀 수 있다.

Posted by Hoya0415
,