왜안됨왜안됨왜안됨왜안됨왜안됨왜안됨왜안됨왜안됨

업로드 기능 문제있음 원인 : 모름 진짜 모르겠음
발생과정 : 업로드버튼을 누를시 400에러 발생 업로드 버튼을 누르면 호출되야할 메서드가 호출이 안됨 페이지 링크가 안됬나 확인했더니 해당 문제 페이지에 있는 다른 메서드인 onGet은 잘만 호출됨 클라이언트 html보니 보여서는 안될 asp-for가 보여서 razor엔진이 동작안되는거 같아 program.cs확인 문제없음 근데 여전히 똑같음 => ???
This commit is contained in:
2025-05-18 00:01:18 +09:00
parent 471a1b1cf0
commit 45fea23a20
8 changed files with 77 additions and 4 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35931.197 d17.13
VisualStudioVersion = 17.13.35931.197
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "a4PaperHolder", "a4PaperHolder\a4PaperHolder.csproj", "{95F1076B-0572-4793-88E2-40D16276519D}"
EndProject

View File

@@ -33,4 +33,6 @@
</div>
</li>
}
</ul>
</ul>
<a href="/Upload">파일 업로드</a>

View File

@@ -0,0 +1,17 @@
@page
@model a4PaperHolder.Pages.UploadModel
@{
ViewData["Title"] = "파일 업로드";
}
<h2>파일 업로드</h2>
<form method="post" enctype="multipart/form-data">
<input type="file" asp-for="UploadFile" />
<button type="submit">업로드</button>
</form>
@if (Model.Message != null)
{
<p style="color:green;">@Model.Message</p>
}

View File

@@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace a4PaperHolder.Pages;
public class UploadModel : PageModel
{
[BindProperty]
public IFormFile? UploadFile { get; set; }
public string? Message { get; set; }
public void OnGet() { }
public async Task<IActionResult> OnPostAsync()
{
Console.WriteLine("onpostcalled");
if (UploadFile == null || UploadFile.Length == 0)
{
Message = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ּ<EFBFBD><D6BC><EFBFBD>.";
return Page();
}
var basePath = Path.Combine(AppContext.BaseDirectory, "NASFiles");
if (!Directory.Exists(basePath))
Directory.CreateDirectory(basePath);
var filePath = Path.Combine(basePath, Path.GetFileName(UploadFile.FileName));
await using var stream = System.IO.File.Create(filePath);
await UploadFile.CopyToAsync(stream);
Message = "<22><><EFBFBD>ε<EFBFBD> <20>Ϸ<EFBFBD>!";
return Page();
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using System.Text;
var builder = WebApplication.CreateBuilder(args);
@@ -9,6 +10,12 @@ var app = builder.Build();
//razor가 브라우저에서 돌아가면? brazor 작명센스 조졌네
app.UseStaticFiles();
//MvcOptions mvcOption = new();
//mvcOption.EnableEndpointRouting = false;
app.UseRouting();
app.UseAuthorization();
//app.UseMvc();
app.MapRazorPages();
var basePath = Path.Combine(AppContext.BaseDirectory, "NASFiles");
@@ -30,7 +37,17 @@ app.MapGet("/view", (HttpRequest request) =>
provider.TryGetContentType(filePath, out var contentType);
contentType ??= "application/octet-stream";
return Results.File(System.IO.File.OpenRead(filePath), contentType);
var stream = System.IO.File.OpenRead(filePath);
//플레인텍스트같은 확장자는 그냥 다운로드되버리는 문제 있음 일단 영상유형 확장자의 앞으로감기,뒤로감기 처리는 됨
//return Results.Stream(
// stream,
// contentType,
// fileDownloadName: fileName,
// enableRangeProcessing: true
// );
return Results.File(System.IO.File.OpenRead(filePath), contentType);
});
app.Run();